#community-help

Handling Special Characters in Search Queries

TLDR Sidharth asks how to handle special characters in search queries. Kishore Nallan suggests using symbols_to_index configuration and provides an example to help.

Powered by Struct AI

1

6
4mo
Solved
Join the chat
May 25, 2023 (4 months ago)
Sidharth
Photo of md5-051f535431ff484f44f165e9a0b696a5
Sidharth
10:59 AM
Hello Team,
Is there a way to not pre-process the special characters during search?
Got miss-match while searching a query (a&b) in the documents where one document actually contained the queried string
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:06 AM
You can urlencode the special chars.
11:07
Kishore Nallan
11:07 AM
If you want to actually index them, use the symbols_to_indexconfiguration while creating collection.
Sidharth
Photo of md5-051f535431ff484f44f165e9a0b696a5
Sidharth
12:41 PM
Any reference example for this utility would be very helpful.
https://typesense.org/docs/0.23.1/api/collections.html#schema-parameters
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:43 PM
Sample usage:

curl -k "" -X POST -H "Content-Type: application/json" \ -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
        "name": "docs",
        "fields": [     
          {"name": "title", "type": "string" },
          {"name": "points", "type": "int32" }
        ], "symbols_to_index": ["&"]
      }'
Sidharth
Photo of md5-051f535431ff484f44f165e9a0b696a5
Sidharth
12:44 PM
Thanks Kishore Nallan
We'll try this, thanks

1