Hello Team, I have trouble while searching for dat...
# community-help
s
Hello Team, I have trouble while searching for data which contains the speical character like &. below is my snap shot dummy json data: {"company_id":"11609817","parent_id":"365","track_id":"1","security_id":"12", "symbol":"Ram&Madhu","company_nm":"Mahindra & Mahindra","short_name":"M&M" Whenever I search this data it gives me bad request error, intially when I created json file special character are encoded into UTF-8 still that was not coming into search. Can anybody please suggest a way here.
j
Could you share a set of curl commands like this that replicates the issue: https://gist.github.com/jasonbosco/7c3432713216c378472f13e72246f46b
I suspect it might be because of URL encoding
s
So while creating batch document I should use text/plain, is that right?
k
Hi Suraj, if you can just post a snippet that i can run to see the actual error, it would be easy for me to figure out what's going wrong.
s
Hi Kishor.. class SearchParameters { q: m&m queryBy: security_nm,symbol,brand.brandName queryByWeights: 3,2,1 prefix: true,true,true infix: null maxExtraPrefix: null maxExtraSuffix: null filterBy: null sortBy: null facetBy: null maxFacetValues: null facetQuery: null numTypos: null page: null perPage: 100 groupBy: null groupLimit: null includeFields: null excludeFields: null highlightFullFields: null highlightAffixNumTokens: null highlightStartTag: null highlightEndTag: null snippetThreshold: null dropTokensThreshold: null typoTokensThreshold: null pinnedHits: null hiddenHits: null highlightFields: null splitJoinTokens: null preSegmentedQuery: true enableOverrides: null prioritizeExactMatch: false maxCandidates: null prioritizeTokenPosition: null exhaustiveSearch: null searchCutoffMs: null useCache: null cacheTtl: null minLen1typo: null minLen2typo: null }
curl --location --request GET 'http://localhost:8080/search/M & M' <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {colorwhite;background color#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height1px;background color#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html> @Kishore Nallan FYR
@Jason Bosco @Kishore Nallan Can you please suggest a way here
k
The HTML response above is from your web server? I need to see the actual response from the Typesense API.
If you are using the GET search method, you might also want to try the using POST
/multi_search
end-point.
s
Now I am not getting any error as of now but with & it is not giving me result. it is sending me empty result
for query=m&m
for this json data:{"company_id":"11609817","parent_id":"365","track_id":"1","security_id":"12", "symbol":"Ram&Madhu","company_nm":"Mahindra & Mahindra","short_name":"M&M"
@Kishore Nallan
I have used tokenSeparators and symbolsToIndex as well, providing special character but still it sdoes not search with keyword like M&M
k
When I tried locally on a small sample set, querying with
m&m
does fetch that record for me. Please share a sample dataset so I can try it, for e.g. like this (as Jason shared earlier): https://gist.github.com/jasonbosco/7c3432713216c378472f13e72246f46b
s
This is my jsol file , below is data
Untitled
This is how I am creating collection in java
Untitled
So, when I search data for M&M, it return me blank data
@Kishore Nallan
k
Please post the search Java snippet also. Again, you need to post a fully reproduceable example so I run and check. Otherwise it's hard for me to help. Please post a full program in Java client that creates collection, indexes document and queries that show cases the issue.
s
Code
Have added code for collection create, document insert and search, please check the same @Kishore Nallan, let lme know in case anything else is required
k
Will check and get back to you in an hour or so.
s
Thanks @Kishore Nallan for your quick response, appreciate🙏
k
@suraj bhandari That M&M document is not even getting indexed. If you check the response of the import call, you will see this error:
Copy code
Field `security` has been declared in the schema, but is not found in the document.
The import function always returns true because only some of the documents could fail (like in this case), so you have to check the response.
s
@Kishore Nallan below is the right jsonl file, on which collection is created
Copy code
{"company_id":"3005","parent_id":"16795","exchange_id":"2","security":"","symbol":"M&MFIN","company_nm":"Mahindra & Mahindra Financial Services Ltd","short_company_nm":"M & M Fin. Serv.","code":"INE774D0102","series":"","brand":[{"heading":"Financial Services","brandName":"MAHINDRA FINANCE FINSMART"}]}
{"company_id":"3004","parent_id":"27242","exchange_id":"2","security":"","symbol":"BLKASHYAP","company_nm":"B.L.Kashyap & Sons Ltd","short_company_nm":"B.L.Kashyap","code":"INE350H1032","series":"","brand":[{"heading":"Construction & Civil Engineering","brandName":"BLK"}]}
{"company_id":"4354","parent_id":"28","exchange_id":"2","security":"","symbol":"ARUNAHTEL","company_nm":"Aruna Hotels Ltd","short_company_nm":"Aruna Hotels","code":"INE95701019","series":"","brand":[{"heading":"HotelBusiness","brandName":"ARUNA"}]}
I am able to search with other symbol like BLKASHYAP
When I search keyword like Mahindra , I am getting record of M&MFIN as well, hence it is stored in collection properly, only when i search M&M, id do not work @Kishore Nallan
k
I'm yet to look. Since I juggle supporting multiple customers it's always useful if you can share a fully reproduceable example that I can just run in one go. When you share snippets like above I still need to put it together into a Java program and run it and test it. That takes a lot of my time.
s
I Understand, let me put the entire code base here then
k
Just share a single Java program in static void main that we both can run and get the exact results.
It will prevent issues like earlier where the documents didn't even get indexed properly .
s
Okay got it..
java code and jsonl file
create collection code
have added this line query =URLEncoder.encode(query, StandardCharsets.UTF_8.toString()); in code just to check if with this special character is working or not
k
Again you are adding several snippets instead of a single program which creates, collection, indexes the docs, queries and prints the result. 🙂
s
Whole code.. jsonl file already sent to you
@Kishore Nallan Have sent you consolidated code.. Please have a look.. jsonl file is already sent
k
Thanks will get back to you
🙏 1
Remove
preSegmentedQuery
param and it should work.
Also you probably don't need
tokenSeparators
during collection creation as well.
s
@Kishore Nallan After removing
tokenSeparators and preSegmentedQuery *it is wokring fine now.*
Thank you for for help.:pray:
k
Welcome!