Problem/Motivation

On #3075695: Move search_index() and related functions to a service, in the last couple of hours before it was committed, a change was rushed through that left Search module indexing in an inefficient state.

This should be fixed before the 8.8 release IMO.

Two problems:

a) The plugins that are calling ->index() are not passing the $needs_update in as FALSE, but they are still calling updateWordWeights(). For example, here is HelpSearch from that patch:

+            $words += $this->searchIndex->index($this->getType(), $item->sid, $langcode, $text);
+          }
         }
       }
     }
+    finally {
+      $this->searchIndex->updateWordWeights($words);
+    }

So HelpSearch is keeping track of $words and calling updateWordWeights, but because it didn't pass in FALSE as the last argument, the ->index() function is updating itself:

+  public function index($type, $sid, $langcode, $text, $update_weights = TRUE) {
...
+    finally {
+      if ($update_weights) {
+        $this->updateWordWeights($current_words);
+      }
+    }

So, updateWordWeights() is being called on every index() call, and then again at the end. Inefficient and redundant.

b) The docs in index() telling you what function to call when you do pass in FALSE were removed in one of the interdiffs above. So people looking at SearchIndexInterface() don't have an explicit message that if they do pass in FALSE saying how they should update the word weights later.

Proposed resolution

a) Fix HelpSearch and NodeSearch to do the right thing with calling index() so it is more efficient.
b) Update the docs on SearchIndexInterface

Remaining tasks

Make a patch.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None needed.

CommentFileSizeAuthor
#2 3087407.patch2.28 KBjhodgdon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon created an issue. See original summary.

jhodgdon’s picture

Status: Active » Needs review
FileSize
2.28 KB

Here's an untested patch -- let's see what the bot says.

andypost’s picture

Assigned: Unassigned » pwolanin
Issue tags: +Quick fix

I think RTBC but would be great to get another opinion

jhodgdon’s picture

Note: In Slack @jibran suggested this needs a test.

My thought is that if we pass in FALSE (as in this patch) and the existing tests pass, then we know that everything is working correctly. I don't know of a way to have a test that we aren't being redundant in our calls to ->index() and ->updateWordWeights in both NodeSearch and HelpSearch plugins.

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the quick fix.

andypost’s picture

Assigned: pwolanin » Unassigned
Status: Reviewed & tested by the community » Needs review
andypost’s picture

Status: Needs review » Reviewed & tested by the community

sure rtbc++

  • larowlan committed 1c4e7f7 on 9.0.x
    Issue #3087407 by jhodgdon: Search indexing calls are inefficient
    
larowlan’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/core/modules/node/src/Plugin/Search/NodeSearch.php
@@ -540,7 +540,7 @@ protected function indexNode(NodeInterface $node, array &$words) {
-      $words += $this->searchIndex->index($this->getPluginId(), $node->id(), $language->getId(), $text);
+      $words += $this->searchIndex->index($this->getPluginId(), $node->id(), $language->getId(), $text, FALSE);

thanks - we should open a followup to remove the pass by reference here too (out of scope here)

Committed 1c4e7f7 and pushed to 9.0.x. Thanks!

  • larowlan committed 184bb93 on 8.8.x
    Issue #3087407 by jhodgdon: Search indexing calls are inefficient
    
    (...
  • larowlan committed d9cf058 on 8.9.x
    Issue #3087407 by jhodgdon: Search indexing calls are inefficient
    
    (...
andypost’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.