It is explicitly documented to only remove it in the index, but somehow, that doesn't seem to make sense to me.

If you have a sentence like "We are talking", then the We is skipped on index. makes sense. But when searching and having the search view configured to search for all words, if you are are searching for "We are talking" then you get no results because We isn't actually found.

IMHO, it should also remove it there, as users don't know that they are not "allowed" to enter two-word keywords in the search field :)

Comments

Berdir created an issue. See original summary.

drunken monkey’s picture

Component: General code » Plugins
Status: Active » Needs review
StatusFileSize
new2.44 KB
new3.16 KB

IMHO, it should also remove it there, as users don't know that they are not "allowed" to enter two-word keywords in the search field :)

For that reason, it is recommended to use Views and set the same minimum word length in the fulltext search filter there. (Otherwise, if those are just removed by the processor and a visitor enters just a short word, all results will be displayed, without any comments, which is of course also very confusing behavior.)

Thus, I’m not actually sure which behavior, the current one or the one you’re proposing, has more potential for confusion. But probably, the more sensible thing here is really to mirror the behavior at indexing time, as you suggest.

Patch attached, please test/review!

berdir’s picture

Will try the patch.

We're using views and have that configured, but I think views just checks the whole search string and if you have multiple words then it doesn't filter them out.

If you combine that with matching all words, then you can for example search for an exact title that has a short word like "we" in it and it not find it because that word doesn't exist in the indexed data :)

mstrelan’s picture

I've found the same issue with users searching "ID cards".

Off topic for this issue, I think the solution for me will be to lower the minimum word length to 2, although it would be nice if it could remain at 3 with a whitelist of 2 letter words. I don't want results that just related to "cards" if they are not about "ID cards". That's obviously a separate feature request.

But adding my +1 to the approach in OP and #2, if words are stripped from the index they should be stripped from the query too.

drunken monkey’s picture

We're using views and have that configured, but I think views just checks the whole search string and if you have multiple words then it doesn't filter them out.

No, the length is checked for each word individually, and short words removed. See the bottom of \Drupal\search_api\Plugin\views\filter\SearchApiFulltext::validateExposed(). (The form field’s description also makes this quite clear, I think – but of course, that could have been wrong.)
Does the patch work for you?

  • drunken monkey committed 03eb8db on 8.x-1.x
    Issue #3011859 by drunken monkey: Fixed Tokenizer not removing short...
drunken monkey’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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