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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tvn’s picture

Version: 7.x-1.4 » 7.x-1.9
Issue tags: +affects drupal.org

Happening 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.

drunken monkey’s picture

OK, 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.

tvn’s picture

The way D6 D.o shows warnings now is good: error message saying that user didn't input enough characters and the search field highlighted.

Only local images are allowed.

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.

drunken monkey’s picture

Version: 7.x-1.9 » 7.x-1.x-dev
Component: Framework » Views integration

Hm, 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.)

tvn’s picture

That'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 :)

drunken monkey’s picture

Status: Active » Needs review
FileSize
2.48 KB

OK, that should be easy. Patch attached, please test/review!

tvn’s picture

Applied 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)

drunken monkey’s picture

Issue summary: View changes
Status: Needs review » Fixed

Thanks for testing, good to hear it works!
Committed.

Status: Fixed » Closed (fixed)

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

tvn’s picture

Status: Closed (fixed) » Active

So 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

drunken monkey’s picture

Sorry 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.

tvn’s picture

Status: Active » Closed (fixed)

Thanks, Thomas. Will do email next time :)
Closing this one again, see my follow up in the other issue.