Hi, everyone! I have a newbe problem :sweat_smile...
# community-help
c
Hi, everyone! I have a newbe problem 😅 when using a wildcard * in the filter_by param. I want to build an autocomplete search for city names in typesense. When I search with:
Copy code
$searchParameters = [
            "q" => "leip*",
            "query_by" => "seo_query",
            "filter_by" => "main_entry:=true"
        ];
then 65 documents are found in my index, which is great. But I want to use the filter to find cities. When I search like this:
Copy code
$searchParameters = [
            "q" => "*",
            "query_by" => "seo_query",
            "filter_by" => "seo_query:=leip* && main_entry:=true"
        ];
then there are no documents found. Why?
k
Can you try with:
Copy code
seo_query:leip*
c
Yes. Same result. found=0.
Here is my index setting, btw:
['name' => 'seo_query', 'type' => 'string', 'facet' => true, 'sort' => true],
k
Cc @Harpreet Sangar
h
@Christian Fritzsche Can you share few values of the
seo_query
field that match with
query_by
?
c
This is my sampledata
and this is my schema
h
Okay. I'll try to reproduce the issue and let you know.
🙏 1
What Typesense version are you using?
I used these commands and I get
found: 15
c
I'm using v28.0.
please try:
Copy code
curl '<http://localhost:8108/multi_search>' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{
  "searches": [
    {
      "collection": "test",
      "q": "*",
      "filter_by": "seo_query: leip* &&  main_entry:=true" 
    }
  ]
}'
I would expect 65 results out of 66, but found 0.
my full test:
h
Can you try with these commands?
I receive this response on latest version. I'll checkout v28 now.
c
I got "found":13 with your commands. so there is something wrong with my schema or sample data?
h
Seems like it. I'll check.
👍 1
I tried with the whole dataset and got this result:
Can you check if the
"out_of": 164,
is the same in your response?
c
Copy code
{
  "results": [
    {
      "facet_counts": [],
      "found": 0,
      "hits": [],
      "out_of": 164,
      "page": 1,
      "request_params": {
        "collection_name": "geodb",
        "first_q": "*",
        "per_page": 10,
        "q": "*"
      },
      "search_cutoff": false,
      "search_time_ms": 17
    }
  ]
}
did you import the whole geodb_sampledata.jsonl?
h
I only indexed
seo_query
and
main_entry
fields since we're only using those two in the query. I'll try again with all of the fields.
I tested again with the whole dataset and indexed all the fields. I get
"found": 64
Seems like somehow
Copy code
"default_sorting_field":"label"
is causing the issue. When this is removed,
"found": 64
is returned otherwise I get
"found": 0
c
Ah I see. I can reproduce that.
That seems to be the Reason. But why?
h
No clue. Can you check if you get
"found": 0
without
"default_sorting_field":"label"
but mention that field in
sort_by
c
Copy code
curl '<http://localhost:8108/multi_search>' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{
  "searches": [
    {
      "collection": "geodb",
      "q": "*",
      "filter_by": "seo_query: leip* &&  main_entry:=true",
      "sort_by": "label:asc"
    }
  ]
}'
that worked. "found":64.
could be a valid workaround for now...
h
Somehow this exact combination of the filter and the default sorting field is causing trouble 😄
c
I understand. I will use the workaround until it's fixed. Thank you so much for your support!
🙌🏼 1
Sorry @Harpreet Sangar, I have to ask another question related to the same query and same sampledataset. 🫤 When I search with q parameter and wildcard, I get 65 documents found (as expected, 64:'leipzig*' and 1:'leipheim'):
Copy code
curl '<http://localhost:8108/multi_search?query_by=seo_query>' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{
  "searches": [
    {
      "collection": "geodb",
      "q": "leip*",
      "filter_by": "main_entry:=true",
      "sort_by": "label:asc"
    }
  ]
}'
But when I use the wildcard in the filter, I only get 64 results ('leipheim' is missing):
Copy code
curl '<http://localhost:8108/multi_search>' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{
  "searches": [
    {
      "collection": "geodb",
      "q": "*",
      "filter_by": "seo_query: leip* &&  main_entry:=true",
      "sort_by": "label:asc"
    }
  ]
}'
Can you help me to understand the difference?
h
I would suggest you to add
-
as
token_separators
in the schema. Also, increasing the number of
max_filter_by_candidates
will return more results.
c
Both hints were helpful. Thank you so much!