Hi, is there a way to perform a LIKE request on a text field, or partial matches for autocomplete routes?

Something like:

$query->addCondition('name', $name, 'LIKE');

Thanks for your help!

CommentFileSizeAuthor
#7 search-api-db-add-like-operator.patch3.84 KBsgourebi

Comments

Jupiter created an issue. See original summary.

drunken monkey’s picture

Status: Active » Fixed

No, there isn't. Since Search API supports a wide range of backends, it's not possible to require all of them to support the LIKE operator.
This could be added as an optional feature for backends, though, maybe in a contrib module.

Otherwise, if you just need it for your own site, you'll have to use custom code to rewrite the database or Solr query of your search accordingly.

jmlavarenne’s picture

Thanks for the quick reply. If you have the time, can you describe in quick terms, a sentence or two, of how to do that? Like implement this or that hook, implement a subscriber or listener that replaces this or that class, implements this or that interface. Or even a word or two about what terms to look for in the handbook would be amazing :)

drunken monkey’s picture

If you have the time, can you describe in quick terms, a sentence or two, of how to do that?

How to do what? I provided two options in my reply.
For the custom solution, you can use hook_search_api_db_query_alter() or hook_search_api_solr_query_alter(), depending on the backend (DB or Solr – others might have their own alter hooks).

Status: Fixed » Closed (fixed)

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

dmezquia’s picture

Hi @drunken monkey @Jupiter, any update on this issue?, in the current version of the module is it possible to use LIKE easily.?

sgourebi’s picture

StatusFileSize
new3.84 KB

I made a patch for database server.
I hope it will help someone.

You just have to use like this:
$query->addCondition('property_name', 'value', 'LIKE');