Skip to content

Instantly share code, notes, and snippets.

@b0g3r
Created April 17, 2023 20:02
Show Gist options
  • Save b0g3r/69a2268cc0965ce706a06b8d7ae108e1 to your computer and use it in GitHub Desktop.
Save b0g3r/69a2268cc0965ce706a06b8d7ae108e1 to your computer and use it in GitHub Desktop.
example of split token ranking
export TYPESENSE_API_KEY=secret
curl "http://localhost:8108/collections/test" \
-X DELETE \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"
curl "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "test",
"fields": [
{"name": "content", "type": "string" }
]
}'
curl "http://localhost:8108/collections/test/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"id": "1", "content": "basketball"}
{"id": "2", "content": "basket ball"}'
curl "http://localhost:8108/multi_search" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"searches": [
{
"collection": "test",
"query_by": "content",
"q": "basketball",
"split_join_tokens": "always"
}
]
}' | jq '.results[0].hits[] | .highlight.content, .text_match_info'
# {
# "matched_tokens": [
# "basket",
# "ball"
# ],
# "snippet": "<mark>basket</mark> <mark>ball</mark>"
# }
# {
# "best_field_score": "2211897868544",
# "best_field_weight": 15,
# "fields_matched": 1,
# "score": "1157451471441625209",
# "tokens_matched": 2
# }
# {
# "matched_tokens": [
# "basketball"
# ],
# "snippet": "<mark>basketball</mark>"
# }
# {
# "best_field_score": "1108091339008",
# "best_field_weight": 15,
# "fields_matched": 1,
# "score": "578730123365711993",
# "tokens_matched": 1
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment