Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I do not enter a search term, all results appear. This is desired behaviour.
When I enter a search term greater than the minimum word length of my database server, I get my "no results text" that I set in views. This is desired behaviour.
When I enter a search term shorter than the minimum word length of my database server, I get all results. This is not what I want. I want it to show that there are no results for this search.
I'm using search_api_db with views.
For now I have fixed this by setting the minimum word length to 1, but I shouldn't have to.
Comment | File | Size | Author |
---|---|---|---|
#6 | 1961120-6--views_minimum_keyword_length.patch | 2.48 KB | drunken monkey |
Comments
Comment #1
tvn CreditAttribution: tvn commentedHappening to us on D7 Drupal.org as well. Search API 7.x-1.9. See issue #2118545: /project/issue/search returns results on two-character results.
Comment #2
drunken monkeyOK, I see that with Views this doesn't even show a warning that words were ignored, which is of course bad. So one thing is, we should definitely fix Views to resolve this, i.e., (provide a way to) show any keywords that were ignored. Either by always outputting them (like the errors) or by providing an area handler listing them. (Or is it possible to just supply it as a token for area handlers, so users could just use a custom text?)
For displaying no results if no keys were present, we have several options. One question is whether this should always be the case – if so, then just fixing the database backend to do that seems like the proper solution. If this should be optional, the question is whether we should include the option for the server or for the view. For the server, the implementation would be cleaner and easier, but in the view it would allow finer-grained control (since different views could be configured differently). So it depends how likely you think it is that someone would want to display all results, and whether there would likely be anyone who wants this for some but not all searches.
Comment #3
tvn CreditAttribution: tvn commentedThe way D6 D.o shows warnings now is good: error message saying that user didn't input enough characters and the search field highlighted.
I don't think it's very likely that someone would want to display all results when searching for word shorter than minimum word length. That's confusing as the results displayed won't have any relation to whatever the person was searching for.
Comment #4
drunken monkeyHm, for that to work (without larger hacks), I think we'd have to include that as an additional option for the "Search: Fulltext search" filter. Otherwise, there's no real/clean way to show a validation error for the field. Would that be OK? (I.e., that you'd have to set the same minimum word length on both the search server and the Views filter.)
Comment #5
tvn CreditAttribution: tvn commentedThat'd be ok I think. In fact I was looking for a setting exactly there, while trying to figure out how to fix that on git7site :)
Comment #6
drunken monkeyOK, that should be easy. Patch attached, please test/review!
Comment #7
tvn CreditAttribution: tvn commentedApplied the patch on my dev site, updated the view and it works just fine.
http://tvn7-drupal_7.redesign.devdrupal.org/project/issues/search?text=j...
(User/pass drupal/drupal to access)
Comment #8
drunken monkeyThanks for testing, good to hear it works!
Committed.
Comment #10
tvn CreditAttribution: tvn commentedSo we have Search API with this patch on D.o, but it seems validation still isn't working for words shorter than minimum word length. Please, see this comment: https://drupal.org/comment/8614065#comment-8614065
Comment #11
drunken monkeySorry for not answering earlier! I'm currently busy with the D8 port and therefore only process the D7 issues on a approximately monthly basis. Also, it seems this issue has slipped from my notice on top of that, for some reason.
Since I also don't log in to Twitter regularly, please just send a mail next time! D.o issues do have priority. ;)
Anyways, I answered in the other issue. A bit confusing.
Comment #12
tvn CreditAttribution: tvn commentedThanks, Thomas. Will do email next time :)
Closing this one again, see my follow up in the other issue.