Abhishek Choudhary
12/06/2024, 4:27 AMI’m a developer integrating Typesense into our project, and I have a few questions regarding advanced search functionalities and user experience.
1 - Search Query Behavior and Operators:
Is there a configuration or functionality in Typesense that allows users to specify how search queries are processed? For instance, can users explicitly indicate:
All words must be included (e.g., using operators like AND or +).
Any words can match (e.g., similar to using OR).
Exact phrases (e.g., with "quoted text").
I’m particularly interested in whether Typesense supports query customization or operators similar to Google Search, which uses tools like +, -, AND, OR, and quotation marks to refine search behavior.
2 - Query Adjustments and User Feedback:
When a user performs a search, if Typesense modifies the query (e.g., due to typo tolerance or synonyms), is there a built-in mechanism to notify the user about these adjustments? For example, showing a message like “Showing results for [adjusted query]” while also providing an option to search using the exact query they entered.
Additionally, if we want to implement this behavior ourselves, is there an API or configuration setting that allows us to Identify when a query has been adjusted.
Re-run the search with the original input (disabling typo tolerance or synonyms) to display precise results.
These features are crucial for delivering a transparent and user-friendly search experience in our application. If such functionalities exist, could you guide us on how to configure them?
Fanis Tharropoulos
12/06/2024, 9:08 AM+
(and the +
is not part of the symbols_to_index
parameter in your collection schema), then change drop_tokens_threshold=0
. Some documentation on drop_tokens_threshold
:
IfThe OR one just sounds like the default behavior of how Typesense handles search queries. For exact queries, you could try to apply a an exact match by filtering by that field with the exact match operatoris set to a numberdrop_tokens_threshold
and a search query contains multiple words (eg:N
), if at leastwordA wordB
results with bothN
andwordA
in the same document are not found, then Typesense will dropwordB
and search for documents with justwordB
. Typesense will keep dropping keywords like this left to right and/or right to left, until at leastwordA
documents are found. Words that have the least individual results are dropped first. SetN
todrop_tokens_threshold
to disable dropping of words (tokens).0
:=
e.g. name:=<query_term>
Fanis Tharropoulos
12/06/2024, 9:09 AM-
operator wouldn't be possibleFanis Tharropoulos
12/06/2024, 9:28 AMtypo_prefix_score
parameter in the hits
of your search response will be 0 if typo-tolerance didn't kick in for that result. So you can know if your search had to use typo-tolerance for that result if the typo_prefix_score
is not 0. Essentially, you can use the /multi_search
endpoint, search by that term with no typo tolerance and with typo tolerance at the same time (two searches in the same multisearch request). Then you'd either recommend that the user searches by a document that matches a result from the typo-tolerated search (let's say that the user searched the best bur
and there's a document with the best burger in town
. You'd recommend that the user searched the best burger
, matching the first_q
parameter (the best burger
) that the typo-tolerant search would provide you.
❯ curl "<http://localhost:8108/collections/pg-essays/documents/search?q=the%20best%20burg&query_by=title>" \
-X GET \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": { "id": "1", "title": "the best burger in town" },
"highlight": {
"title": {
"matched_tokens": ["the", "best", "burg"],
"snippet": "<mark>the</mark> <mark>best</mark> <mark>burg</mark>er in town"
}
},
"highlights": [
{
"field": "title",
"matched_tokens": ["the", "best", "burg"],
"snippet": "<mark>the</mark> <mark>best</mark> <mark>burg</mark>er in town"
}
],
"text_match": 1736172785157275769,
"text_match_info": {
"best_field_score": "3315687620608",
"best_field_weight": 15,
"fields_matched": 1,
"num_tokens_dropped": 0,
"score": "1736172785157275769",
"tokens_matched": 3,
"typo_prefix_score": 1
}
}
],
"out_of": 2,
"page": 1,
"request_params": {
"collection_name": "pg-essays",
** "first_q": "the best burger", // Notice this**
"per_page": 10,
"q": "the best burg"
},
"search_cutoff": false,
"search_time_ms": 0
}
Abhishek Choudhary
12/06/2024, 9:31 AMAbhishek Choudhary
12/06/2024, 9:49 AMFanis Tharropoulos
12/06/2024, 9:54 AMAbhishek Choudhary
12/06/2024, 9:56 AM