I have enabled autocomplete via the search_api_autocomplete module. If I search for "area" then the suggestion "Areaal" is returned. If I search for "Area" then the suggestion "Areaal" is not returned.

In my index I do have "Ignore case" enabled, but it doesn't seem to do anything.

If I use strtolower to make the sting the user inputted lowercase then it does work. But I wonder if it's caused by the Collation of the table?

Comments

Johnny vd Laar’s picture

Attached is a patch that uses strtolower. I think the search function also does this.

drunken monkey’s picture

Status: Active » Needs work

Thanks for reporting this issue!
You're right, I hadn't really thought about it but currently the incomplete keys aren't processed by any processors, so things like case insensitivity won't be applied to them automatically. I don't really know what the proper way to fix this would be, but I guess applying such a workaround for this module would make sense for now. While some people might have their searches set up as case-sensitive, most people probably haven't.

However, your patch isn't completely correct as you'd need to have both keys and values in $keys in lower case, and also lowercase the incomplete key when adding that.

drunken monkey’s picture

Category: Support request » Bug report
valderama’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new557 bytes

Can't I assume that all indexed data is actually lowercase? The indexItem method from SearchApiDbService casts all textual fields to lowercase, as far as I can see.

That would make case-sensitive searches impossible with the DB server anyhow - and would allow to simply convert all user input for the autocompletion to lowercase as well.

I have a slightly different patch to #1 - but actually it simple converts input to lowercase.

drunken monkey’s picture

Can't I assume that all indexed data is actually lowercase? The indexItem method from SearchApiDbService casts all textual fields to lowercase, as far as I can see.

For the moment, yes, you're right. Since we now set the table collation, at least for fulltext fields, we should maybe fix that – but in this case it's of course practical. Otherwise, I don't know – we'd maybe have to check whether the "Ignore case" processor is enabled on the index, or use all the index's processors on the incomplete key in some way. Might still be good, as it's a cleaner and broader solution, but this quick fix should already cover most cases.

Leaving this open for comments for now, and will commit in a week or so. Thanks!

drunken monkey’s picture

Status: Needs review » Fixed

Committed.
Thanks again!

Status: Fixed » Closed (fixed)

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

drunken monkey’s picture

Project: Search API Database Search » Search API
Version: 7.x-1.x-dev » 8.x-1.x-dev
Component: Code » Database backend
Status: Closed (fixed) » Patch (to be ported)

Needs to be ported to D8. (Even though there is no Autocomplete module in D8 yet, the code in the DB backend is still there and we'll probably forget if we don't fix this now.)

drunken monkey’s picture

Issue tags: +Novice
dragos-dumi’s picture

Assigned: Unassigned » dragos-dumi
cristiroma’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new648 bytes

Uploading Drupal 8 port patch.

drunken monkey’s picture

Status: Needs review » Fixed

Thanks a lot, looks good!
Also really great that you wanted to add tests, a pity it doesn't really work for this issue. But generally, very admirable!
Committed. Thanks again!

Status: Fixed » Needs work

The last submitted patch, 12: autocomplete-case-insensitivity-2231453-12.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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