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.

Comments

robcast created an issue. See original summary.

dsquaredb’s picture

mkalkbrenner’s picture

Turn on search_api_solr_devel included in search_api_solr 8.x-2.x and post the query parameters here.

robcast’s picture

When 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:

    Try to send Solr request => select?omitHeader=true&wt=json&json.nl=flat&q=tm_text_full_title_translit%3A%28mulahhas%29%5E1&start=0&rows=30&fl=ss_search_api_id%2Css_search_api_language%2Cscore%2Chash&sort=score+desc&fq=ss_type%3A%22text%22&fq=tm_person_name_translit_1%3A%22jajmin%2A%22&fq=%2Bindex_id%3Aismi_default_index

    GET => Array
    (
        [omitHeader] => Array
            (
                [0] => true
            )

        [wt] => Array
            (
                [0] => json
            )

        [json.nl] => Array
            (
                [0] => flat
            )

        [q] => Array
            (
                [0] => tm_text_full_title_translit:(mulahhas)^1
            )

        [start] => Array
            (
                [0] => 0
            )

        [rows] => Array
            (
                [0] => 30
            )

        [fl] => Array
            (
                [0] => ss_search_api_id,ss_search_api_language,score,hash
            )

        [sort] => Array
            (
                [0] => score desc
            )

        [fq] => Array
            (
                [0] => ss_type:"text"
                [1] => tm_person_name_translit_1:"jajmin*"
                [2] => +index_id:ismi_default_index
            )

    )

    Received Solr response => 200 OK
robcast’s picture

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

mkalkbrenner’s picture

Status: Active » Postponed (maintainer needs more info)
        [q] => Array
            (
                [0] => tm_text_full_title_translit:(mulahhas)^1
            )
        [fq] => Array
            (
                [1] => tm_person_name_translit_1:"jajmin*"
            )

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

robcast’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new61.33 KB

I'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?

mkalkbrenner’s picture

You are exposing multiple search boxes at once, right?

robcast’s picture

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

mkalkbrenner’s picture

That'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.

robcast’s picture

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

mkalkbrenner’s picture

Priority: Normal » Major

I 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!

robcast’s picture

Priority: Major » Normal

So search_api is involved as well?

I was wondering where the logic is that puts multiple search fields into one query...

robcast’s picture

Priority: Normal » Major

oops, reset priority...

mkalkbrenner’s picture

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

mkalkbrenner’s picture

Status: Active » Needs review
StatusFileSize
new5.36 KB

Ok, here's a patch that should work if you configure all exposed fulltext filters to use the same operator and parse mode.

mkalkbrenner’s picture

Title: Problem with wildcard search in multiple fields » Problem with wildcard search in multiple exposed filters
robcast’s picture

Status: Needs review » Active

The patch works in my first tests! Thanks a lot!

mkalkbrenner’s picture

Status: Active » Reviewed & tested by the community

  • mkalkbrenner committed 1b9f563 on 8.x-2.x
    Issue #2990453 by mkalkbrenner, robcast: Problem with wildcard search in...
  • mkalkbrenner committed 1e04e00 on 8.x-2.x
    Issue #2990453 by mkalkbrenner, robcast: Problem with wildcard search in...
  • mkalkbrenner committed c6455b3 on 8.x-2.x
    Issue #2990453 by mkalkbrenner, robcast: Problem with wildcard search in...
mkalkbrenner’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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