I have a search view where users can search in multiple fields via exposed filter criteria.
I have set the filter criteria to fulltext search and selected different fields indexed in solr.
When I use full words in the search fields the search works ok.
When I try to use wildcards in the search fields like "foo*" it works only in the first search field. Wildcards in any other search fields lead to no results.
I tried to change the "Operator" and "Parse mode" but no setting seemed to work.
I looked into the queries sent to Solr and it seemed to help to remove the quotation marks in the fq-part of the query when I tried it in the Solr web frontend but I don't know how to influence this.
I tried search_api_solr 1.0, 1.2 (search_api 1.5, 1.7) and 2.0 (search_api 1.7, 1.9) on Drupal 8.3.9 and 8.5.5.
Any ideas?
I can provide more details if necessary.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2990453.patch | 5.36 KB | mkalkbrenner |
| #7 | views.view_.ismi_search_entities.yml | 61.33 KB | robcast |
Comments
Comment #2
dsquaredb commentedComment #3
mkalkbrennerTurn on search_api_solr_devel included in search_api_solr 8.x-2.x and post the query parameters here.
Comment #4
robcast commentedWhen I search for title=mulahhas and author=jajmini (without wildcard) I get two results.
When I replace the last character of the author with a wildcard (title=mulahhas, author=jajmin*) I get no results.
This is the output from search_api_solr_devel on the page:
Comment #5
robcast commentedI see that
createFilterQuery()escapes the second field query as a phrase.When I remove the
escapePhrase()in line 2094 I get a result but I don't think this is a real fix...Comment #6
mkalkbrennerHaving Search API and Views on top, we can't leverage all Solr features in search_api_solr.
The problem is, that second term is handled by a filter query (fq). All this parse mode stuff is applied to the search keys we get as 'q'.
Can you export and upload your View? Based on that YAML file we can start solving the issue.
Comment #7
robcast commentedI've uploaded the view config from the profile as views.view_.ismi_search_entities.yml
The view has multiple displays for slightly different lists and searches.
The example I gave above is from the "search_texts" display (starting at line 1204).
Does that help?
Comment #8
mkalkbrennerYou are exposing multiple search boxes at once, right?
Comment #9
robcast commentedYes, in the seach_texts display I have two exposed filters using the "full text search" filter with different solr fields.
When I leave the first exposed filter empty then the search expression goes into the q-part instead of the fq-part and the wildcard works.
Comment #10
mkalkbrennerThat's the problem. Search API (not Search API Solr) sets the first search box as "query" and the second as "filter". Is that what you really want to do? And doesn't it confuse the user?
If you just want to search different fields using a single exposed filter at once you have two possibilities:
1. Select multiple fields in the config of the exposed filter
2. Index mutiple fields as one aggregated field and use this one with your exposed filter.
Anyway, if somone really wants that "filter", we might have a bug here. Removing the escapePhrase is not an option because it will open a security issue (injection).
But we might need to "copy" the full text query builder logic to the filter query.
Comment #11
robcast commentedWhat the users want is to search in separate fields with separate search terms including wildcards. I can not see how that can be achieved with only one input field.
The user wants to search for a word in the title field and another word in the author field and find all books that match both conditions. I think this is a very common pattern.
That the first field gets to be the "query" and the others to be a "filter" is a detail that the user is not interested in.
Would it be possible to change the logic so that the exposed fields create additional conditions in the q-part of the query instead of a filter query?
Otherwise it may be necessary to apply the query builder logic also to the filter query part to be able to have wildcards.
Comment #12
mkalkbrennerI died some tests just recognized that Search API applies some magic here if you have multiple search boxes depending on the configuration of them.
Some combinations leed to Solr exceptions!
Comment #13
robcast commentedSo search_api is involved as well?
I was wondering where the logic is that puts multiple search fields into one query...
Comment #14
robcast commentedoops, reset priority...
Comment #15
mkalkbrennerI just opened #2991134: Support setting parse mode and conjunction for fulltext conditions
The first problem is that the configured parse modes get lost. In other words the Solr backend has no idea about parse modes of conditions/filters.
Without that information I can't fix anything here.
Comment #16
mkalkbrennerOk, here's a patch that should work if you configure all exposed fulltext filters to use the same operator and parse mode.
Comment #17
mkalkbrennerComment #18
robcast commentedThe patch works in my first tests! Thanks a lot!
Comment #19
mkalkbrennerComment #21
mkalkbrenner