Clean up tag regepx and if/else logic in \Drupal\search\SearchIndex::index()

Created on 19 August 2019, almost 6 years ago
Updated 11 January 2024, over 1 year ago

Follow up to #3075695: Move search_index() and related functions to a service โ†’ :

+++ b/core/modules/search/src/SearchIndex.php
@@ -0,0 +1,309 @@
+      if ($tag) {
+        // Increase or decrease score per word based on tag.
+        list($tagname) = explode(' ', $value, 2);
+        $tagname = mb_strtolower($tagname);
+        // Closing or opening tag?
+        if ($tagname[0] == '/') {
+          $tagname = substr($tagname, 1);
+          // If we encounter unexpected tags, reset score to avoid incorrect
+          // boosting.
+          if (!count($tagstack) || $tagstack[0] != $tagname) {
+            $tagstack = [];
+            $score = 1;
+          }
+          else {
+            // Remove from tag stack and decrement score.
+            $score = max(1, $score - $tags[array_shift($tagstack)]);
+          }
+        }
+        else {

a subsequent follow-up could be to put this in a method that returned early instead of the if/else/if/else/if
๐Ÿ“Œ Task
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component
Searchย  โ†’

Last updated 3 days ago

  • Maintained by
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States @pwolanin
Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia kim.pepper ๐Ÿ„โ€โ™‚๏ธ๐Ÿ‡ฆ๐Ÿ‡บSydney, Australia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024