Hi, How to perform the multiple field infix text ...
# community-help
v
Hi, How to perform the multiple field infix text search on the same collection (among all field it should be and operation) Kindly Help me to find the solution in single API call. For Example FirstName having '*abc*' anywhere within string (and) EmailAddress having '*xyz*' anywhere within string Thanks!
f
👋🏻 there. For infix search, you first need to enable infix in your field schema inside of your collection by setting
infix: true
, along with its type and name (FirstName and EmailAddress for your use-case). Afterwards, when querying that collection you can use the
infix
parameter to specify the behavior of infix search. To quote our documentation:
If infix index is enabled for this field, infix searching can be done on a per-field basis by sending a comma separated string parameter called infix to the search query. This parameter can have 3 values:
off: infix search is disabled, which is default
always: infix search is performed along with regular search
fallback: infix search is performed if regular search does not produce results
For example, if you are querying two fields via ?query_by=title,part_number, you can enable infix searching only for the part_number field, by sending
?infix=off,always
(in the same order of the fields in query_by).
v
Thank you Fanis for your input, If I wanted to search FirstName contains "*ri*" and Email Address Contains "*com*", I am try to send the parameter as follows, but it does not working. query = { 'q': '*ri*,*com*', 'query_by': 'firstname, emailaddress', 'infix': 'always' } client.collections['playerimport'].documents.search(query)
f
You're trying to search for something that contains that
q
value. You'd need to make a multi search request with the two different values of ri and com
v
Multi search is returning two different result set, but I need it like common result applied both the Infix condition as and operation, is anyway I can achieve?
h
@venkadesh The syntax of your query is incorrect. It should be:
Copy code
query = {
  'q': 'ri com',
  'query_by': 'firstname, emailaddress',
  'infix': 'always, always'
}
v
Hi @Harpreet Sangar, Thank you for your response. I am using following as search query : query = { 'q': 'ri optxtest', 'query_by': 'firstname, emailaddress', 'infix': 'always, always' } But It seems to be not working, it is always search for any one field. In the response I am getting following document as well, In this firstname infix search seems to be working but emailaddress I wanted to have the optxtest but in this document optxtest is missing in emailaddress field, Kindly help me. { "document": { "city": "xxxx", "clubtier": "Topaz", "emailaddress": "admin@optx.com", "firstname": "CATHERINE", "homephone": "9865298", "id": "2512841", "lastname": "2512841LName", "market": "Outer Rochester Competitive", "marketid": 11, "playerid": 2512841, "state": "New York" }, "highlight": { "firstname": { "matched_tokens": [ "Ri" ], "snippet": "<mark>Ri</mark>" } }, "highlights": [ { "field": "firstname", "matched_tokens": [ "Ri" ], "snippet": "<mark>Ri</mark>" } ], "text_match": 578730123365711993, "text_match_info": { "best_field_score": "1108091339008", "best_field_weight": 15, "fields_matched": 1, "num_tokens_dropped": 1, "score": "578730123365711993", "tokens_matched": 1, "typo_prefix_score": 0 } } Thanks!
h
@Kishore Nallan
v
Hi @Kishore Nallan , Your insights on this request would be greatly appreciated. Kindly help me on my use case. Thanks!
k
It's not possible to do what you have described.
👍 1
v
Thank you