1

Wondering if there is any way to force Craft to update the search index for an entry when it is saved.

Reason I ask is that on our site we have a Location entry type with lat/lon inputs that we use to maintain store locations and plot them on a map. However, when we update the lat/lon coordinates, it does not update the search index and continues to plot the old location on the map even though it is displaying the new address in the text.

We can force it to update by rebuilding the search indexes, the only downside is that it takes a few minutes and renders the site search functions useless until it is done. If there's some way for the entry to automatically update the index when lat/lon coordinates are changed, that would be awesome. Any ideas?

  • What type of field are you storing the lat/long values in? – Brad Bell Dec 11 '15 at 0:52
  • Each one has a number field with 6 decimal points. – Joel Dec 11 '15 at 16:14
1

You can do a task resave after elements are entered:

public function resaveElements()
{
    // Queue up a new ResaveElements task
    craft()->tasks->createTask('ResaveElements', null, array(
        'elementType' => ElementType::Entry,
        'criteria'    => array('section' => 'search', 'limit' => null, 'status' => null,'localeEnabled' => null)
    ));

    // Start running tasks
    craft()->tasks->runPendingTasks();
}
| improve this answer | |
1

Craft has always updated the search index automatically after an entry is saved.

The exact time it does that depends on what version of Craft you are using, and how the entry is being saved (web or CLI), but generally speaking there should never be a need to manually or programmatically update the search index yourself after saving an entry.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.