#community-help

Trouble with 'q' Parameter in Typesense query

TLDR ryosuke_shiomi was having trouble with a Typesense query involving the 'q' parameter. Kishore Nallan suggested a temporary workaround and proposed using the latest builds to fix the issue. The solution was under trial at the end of the thread.

Powered by Struct AI
Mar 11, 2022 (22 months ago)
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:14 AM
I think param ‘q’ does not work in well.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:24 AM
Can you please post the schema of your collection? The query_by clause requires a list of fields, but I see that in your query you have -${userId1} -${userId2} -${userId3} … which is strange.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:29 AM
Kishore Nallan sorry, field “query_by” and “q” are reverse in content,
In exactly,
const searchParams = {
  q: "-${userId1} -${userId2} -${userId3} …",
  query_by: "userId",
  filter_by: "favoriteGame: APEX"
}
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:34 AM
Okay can you tell me what the type of the userId field? Is it an array of user IDs or just a single user ID?
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:38 AM
userId type is string, and it is single.
schema is it (it is not all params because the app is not mine, is my office’s.)
collection 'users'

userId: string
favGame: string
createdAt: Date(int)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:40 AM
The issue is that when you query this way, you actually see results with those excluded user IDs in the result is it?
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:42 AM
YES! but it does not work in this way.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:43 AM
I will look into this. As a temporary workaround, can you try this:

q: "*",
filter_by: "favoriteGame: APEX && userId:!= [${userId1}, ${userId2}, ${userId3}]"
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:44 AM
ok, thank you for answering it!
After I try it, i would report the result.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:59 AM
ryosuke_shiomi I think this issue is fixed on the latest 0.23 RC builds. Would you be able to try that? How are you using Typesense: Docker or Linux binary? I can make a recent RC build available to you for testing.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
08:13 AM
Kishore Nallan ok, I examinate it.
I tried the answer, but returned error.
what is the ‘facet field’?
results: [
    {
      code: 400,
      error: 'To perform exclude filtering, filter field `userId` must be a facet field.'
    }
  ]
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:16 AM
Oh right, the userId field need to have facet: true enabled in the schema for negation. You don't need this if the latest RC builds work.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
08:16 AM
oh, really?
so I will try to use it.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:26 AM
I mean, if you want to do negation in filter_by then that field needs to have facet enabled. To do negation in q field, if you use the 0.23 RC builds, the bug you faced earlier won't be there.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
08:30 AM
ok.
so, please give me the information about how to use 0.23.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:41 AM
Are you using Typesense Cloud or self hosting?
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
11:59 AM
Kishore Nallan cloud!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:14 PM
Ok let me know your cluster ID and we can upgrade. Are you already using it on production? If so you will have to test locally first.

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Fixing Multiple Document Retrieval in Typesense

Phil needed an efficient way to retrieve multiple documents by id. Kishore Nallan proposed a solution available in a pre-release build. After some bug fixing regarding id matching by Jason and Kishore Nallan, Phil successfully tested the solution.

4

26
26mo

Typesense Bug Fix with `canceled_at` Field and Upgrade Concerns

Mateo reported an issue regarding the treatment of an optional field by Typesense which was confirmed a bug by Jason. After trying an upgrade, an error arose. Jason explained the bug was due to a recent change and proceeded to downgrade their version. Future upgrade protocols were discussed.

3

74
10mo

Querying with Typesense-Js and Handling Null Values

michtio was querying using typesense-js and receiving fewer results than expected. Kishore Nallan suggested using different query parameters. Further discussion led to the handling of 'null' values and filtering syntax in the search queries. The thread ended with Jason offering migration support from Algolia to Typesense.

4

39
17mo

Querying with Not-in in Typesense

Masahiro inquired about using not-in queries in Typesense. Kishore Nallan explained how to conduct such queries by using the "-" operator in the query string, and assisted Masahiro with issues stemming from a high number of exclusion tokens. The problem was eventually resolved by switching to the `multi_search` endpoint.

4

49
34mo

Resolving Issues with Infix and Prefix in Query Searches

Daren struggled with searches missing values in production. Jason and Kishore Nallan offered insights and created new features to help solve the problem, which was then tested and deployed by Daren.

2

38
5mo