Closed (fixed)
Project:
Drupal core
Version:
9.1.x-dev
Component:
search.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Aug 2019 at 04:03 UTC
Updated:
4 Aug 2020 at 21:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
kim.pepperComment #3
kim.pepperI thought I'd bump this one along a bit. It is still blocked on #3075695: Move search_index() and related functions to a service but wanted to see if I can get tests to pass.
Comment #4
jhodgdonThanks for getting this going!
A few comments on the current patch:
a) In search.module... Why is there still a function body on search_invoke_preprocess()?
b) In the new interface:
This is not correct coding standards, and I don't think the API module will make it into a link... It needs to at least be self:: .
c) Bikeshed coming... In the new interface/class, I don't really like the name of the filterCharacters() method. That name to me sounds like it is filtering out characters. But it can be doing a lot more than that:
- It invokes hook_search_preprocess(), which is what stemming modules do to reduce words to their stems (like walked/walking/walks all become walk). That to me is not a "character filter" but more of a "word-level preprocessing".
- CJK processing takes CJK characters and separates them into "words". Again this is kind of word-level processing
So maybe a better name would be preprocessText()?
Actually, we had an issue a while back to convert all of these preprocessing steps to a filter chain... let me find it.
#257007: Convert hook_search_preprocess() into a plugin
d) Actually this whole issue seems like a duplicate of #2719961: Create SearchText service to deprecate procedural code in search.module so one of them needs to be closed I think? I'll wait to continue review until then...
Comment #5
andypostPatch in #2719961: Create SearchText service to deprecate procedural code in search.module slightly outdated but also converts "defines" (not sure why they are not constants)
Comment #7
kim.pepper#3075695: Move search_index() and related functions to a service is in so this is unblocked.
Comment #8
kim.pepperRe-roll of #3 to get us back on track.
Comment #9
kim.pepperOK, so addressing the feedback in #4.
\Drupal\search\SearchTextProcessor::invokePreprocess()as aprotectedmethod. I don't think we want to make it public and call it fromsearch_invoke_preprocess()do we?Funny that our tokenizer implementation is just
explode(' ', $text)🤔I also moved the constants to the interface, and reference them from search.module rather than duplicating them.
Wondering if we also tackle:
search_excerpt()_search_find_match_with_simplify()In this issue?
Comment #10
kim.pepperOoops. Forgot to replace usages of
filterCharacters()withanalyse()Comment #14
andypostLooks promising and have a change to get in before Alpha
Comment #15
kim.pepperRe-roll of #10.
Comment #17
kim.pepperReplaced deprecated use of
search_index_split()and added deprecation tests.Re: #4.3 I renamed it to
process(). I assume that works better?Comment #19
jhodgdonI took a fresh look at the patch... A few thoughts/questions:
a) Are we still deprecating things in drupal 8 for removal in 9? I don't think so... At least it would need to be 8.9:
b)
analyse should be spelled the American way: analyze
But really... Looking at what the function does, I don't think analyze makes much sense as the function name anyway. It is being processed, not analyzed.
c) I don't understand this deprecation/error message:
It says to use a custom implementation of SearchTextProcessorInterface, but then it calls a method on the core service?!? I guess because that function is marked as internal, but since it's an option on the Search module UI to do CJK processing, I think that we need it not to be internal?
d) nitpick -- on the interface:
Shouldn't have an @see to a deprecated function?
e) Similarly, the tests still talk about testing the search_simplify() function.
Comment #20
andypostThe deprecation possible starting from 9.1 for 10.0 removal iirc
Comment #21
kim.pepperPostponing since 9.1.x branch isn't open yet.
Comment #22
kim.pepperComment #23
andypostChange record version fixed
Comment #24
jungleOnly addressed #19 a) and d)
Re #19 b), there is a relevant issue FYI, #2972224: Add .cspell.json to automate spellchecking in Drupal core,
Re #23, reroll is unnecessary unless we want a patch for 8.x.
Comment #25
andypostThe re-roll is for version
Comment #26
kim.pepperI don't think we can reference the interface from the deprecated constants in search.module.
Comment #27
daffie commentedCan we not define those values with the constants from Drupal\search\SearchTextProcessorInterface?
Please use the Drupal\search\SearchTextProcessorInterface instead of Drupal\search\SearchTextProcessor
Here also needs deprecation stuff to happen.
This is out of scope for this issue. Create a followup for this.
There is no deprecation message testing for this
@trigger_error().This is wrong. Please change it to Drupal\search\SearchTextProcessor::expandCjk().
Comment #28
andypost@daffie about #27.1 - I also stuck to make it work with interface, looks define() is where autoload can't resolve
Comment #29
daffie commented@andypost: When you cannot fix it, then skip it. Fix the other stuff and when it looks good I shall give it a RTBC. Then it is up to the committer to see what he or she thinks about it. I was only asking.
Comment #30
andypostFixes #27 (except 1, 4, 6)
Comment #31
andypostout of scope - fixed
Comment #32
andypostFix #27.6 so the only test conversion follow-up or blocker left?
Comment #33
kim.pepperThis should be the American spelling of analyze as per standards.
Comment #34
ravi.shankar commentedHere I have changed all occurrences of "analyse" to "analyze".
Comment #35
daffie commented@ravi.shankar: The change from analyse to analyze look good. Could you also undo the following change (#27.4):
I will create a followup for it.
Comment #36
daffie commentedCreated the followup: #3134333: Change Drupal\Tests\search\Functional\SearchSimplifyTest and Drupal\Tests\search\Functional\SearchTokenizerTest to kerneltests.
Comment #37
daffie commentedBack to needs work for #27.4.
Comment #38
ravi.shankar commentedHere I have addressed comment #35.
Comment #39
kim.pepperI think this is ready.
Comment #40
kim.pepperNeeds a re-roll after #3134333: Change Drupal\Tests\search\Functional\SearchSimplifyTest and Drupal\Tests\search\Functional\SearchTokenizerTest to kerneltests
Comment #41
ravi.shankar commentedI am working on this.
Comment #42
ravi.shankar commentedAdded re-roll of patch #38.
Comment #43
andypostBack to rtbc
Comment #44
alexpottWe can change these to
define('PREG_CLASS_NUMBERS', SearchTextProcessorInterface::PREG_CLASS_NUMBERS);etc... that way these big constants are only defined in a single location.
This does work...
How about making this protected and deprecating the original code but with no replacement? And not emptying out the old code? There are no contrib usages of this method.
Let's assert it equals ['two', 'words'] - that way we test at least a little that we've not broken the implementation.
Again let's test the output value but the input should also be something that would change - maybe something like
Vögelas that would be changed to vogel.We should be testing the output here too... at the very least it should we could assert the output is the input wrapped in spaces.
Comment #45
kim.pepperThanks @alexpott.
Comment #47
kim.pepperPretty sure the test fails are due to this change
Comment #48
pavnish commentedOn it
Comment #49
pavnish commented@kim.pepper Hi yes you are correct.Please find the new patch without #41.1
RE#41.1 :#45 failed due to the #41.1 change so i am revert this point only.
regards
Pavnish
Comment #50
daffie commentedLet's see if this change fixes the testbot.
Comment #51
kim.pepperThanks @daffie. Although we should probably postpone on #3144354: ModuleInstaller loads .module and .install before allowing classes to autoloaded
Comment #52
andypostBlocker commited
Comment #53
andypostRemove the fix from #50
Comment #54
daffie commentedAll points of @alexpott are addressed.
Back to RTBC.
Comment #55
alexpottI think expandCjk should be protected. Marking it @internal seems only half the job. How about leaving this code here and only deprecating it. Then we wouldn't need to call into the method and it'd no longer need to be public but not on the interface. This is what we did with search_invoke_preprocess() and imo that makes sense.
Let's add typehints for scalars ie string $text and also add return typehints. As this is new code this means we don't have to do it later.
This could be a class property and that way we'd have one less static and it'd be cleared on container rebuild - which makes sense to me.
But also I think we should rewrite this. Because calling Unicode::truncate with none of the options set it wasteful.
This method should look like this:
I severely doubt that that static cache is worth if we check the word length and return early. Also this approach will benefit memory because at the moment the static $truncated is going to be full of 'the' => 'the, 'of' => 'of' etc...
This used to relevant when we did not have mb support baked in. But now we use Symfony's mb_* fallback and everyone has this enabled anyway this sort of optimisation is wasteful.
Comment #56
kim.pepperAddresses feedback in #55
Comment #58
kim.pepperReverted the truncate() changes from #55.3 to see if that was causing the test fails.
Comment #59
kim.pepperI think it was just the order of the if statements. We need to check is_numeric() before checking if < 50 chars.
Comment #60
andypostGreat! all points addressed
Comment #61
alexpottCommitted 640ea36 and pushed to 9.1.x. Thanks!
Added the
// cSpell:disable-next-lineon commit because it seemed sensible and avoids cSpell errorring on this test.I was wondering whether doing the string length check first was worth it - and it looks as though it is - https://3v4l.org/MVdrk
Comment #63
andypost@alexpott Thanks!
Looks #257007: Convert hook_search_preprocess() into a plugin could be closed as outdated now
Comment #64
kim.pepperThanks @alexpott !
Comment #65
andypostThe remaining issue is #2552497: [PP-1] Convert search_excerpt() to a filter