- Issue created by @acbramley
- last update
11 months ago Composer require-dev failure - Status changed to Needs review
11 months ago 2:35am 19 January 2024 - last update
11 months ago 545 pass - 🇦🇹Austria drunken monkey Vienna, Austria
Thanks for the suggestion!
Sure, if using those operators already works correctly when using custom code to override the filter plugins then it makes sense not to prevent this use case in the backend plugin’s code. Seems a very simple change for the moment.
See also ✨ Implement like operator for search_api_db Active , which discusses a more elaborate implementation that also offers the new operators in the UI.
However, this would still need some test coverage before it can be committed. Ideally, we’d already test this in combination with Views, when using Core’s built-instring
plugin as you describe. But just making sure it can be used internally would already be fine, too, I think.Also, as you already found out, testing issue forks still doesn’t work with this module, so please still use patches for now. Now that there’s finally been movement in the test bot issue queue we’ll hopefully have this resolved soon.
Attaching a patch with some small code style changes. - Status changed to Needs work
10 months ago 2:58pm 12 February 2024 I have tried this patch but I have got one question, how do I alter the operator for the Fulltext search ?
Tried something like this:function mymodule_search_api_query_alter(\Drupal\search_api\Query\QueryInterface &$query) { foreach ($conditionGroups as &$conditionGroup) { foreach ($conditionGroup->getConditions() as &$condition) { // no condition found for the fulltext filter. } } }
but the condition for the Fulltext search filter is not there, did I miss something or is it something unusual ?
- 🇦🇹Austria drunken monkey Vienna, Austria
The fulltext search is actually not a “condition” in the Search API, but a separate part of the search query, the “keys”.
You can retrieve them via$query->getKeys()
– they’ll usually be represented as an array structure, see the doc block of\Drupal\search_api\ParseMode\ParseModeInterface::parseInput()
for details.Fulltext search basically just has two operators,
AND
(“contains all of these words”) andOR
(“contains any of these words”). To switch toOR
, you can either do$query->getParseMode()->setConjunction('OR');
before the keywords are set on the query or
$keys = &$query->getKeys(); if (is_array($keys)) { $keys['#conjunction'] = 'OR'; }
afterwards.
If
$keys
is a string, not an array, than the way to express anOR
conjunction depends on the backend. (For the database backend, there is no way to do that with unparsed keywords, i.e., if$keys
is a string. Use the “Terms” parse mode instead.)