I have an application in python that accepts a list of text (strings) that we want to use as search terms in Azure Cognitive Search. The search parameter needs to be a string, so if I have a list of words I can do something like:
words_to_search_list = ["toy", "durable"]
words_to_search_str = ' '.join(words_to_search_list)
and then pass words_to_search_str as the "search" parameter in Azure Search, and it can search for text that has "durable" or "toy".
"toy durable"
However, I am not sure how to handle situations where there are bigrams or trigrams in the words_to_search_list like here:
words_to_search_list = ["more toys", "free treats"]
In order to get back text from Azure that contains either "more toys" or "free treats" we'd need to pass the parameter like this:
"\"more toys\" \"free treats\""
Meaning the bigrams need to be in double quotes, but escaped. I started this:
words_to_search_str=""
for words in words_to_search_list:
words_list=words.split()
if len(words_list)>1:
words_escaped='\\"'+ words + '\\"'
words_to_search_str+=words_escaped
else:
words_to_search_str+=words
But this makes words_to_search_str into the following:
'\\"more toys\\"\\"free treats\\"'
which is not what I want (the double backsplashes won't work).
Is there any way to take that list of strings and end up with one string, but where the bigrams are each in (escaped) double quotes?
Edit: I'd like to add that in the solution I have here, if you print it, you get what looks to be the right object (single backslashes, not double), but the actual object still seems to have the double backslashes and they don't give the same result when you pass into the search parameter...