问题
I need to suggest a list of users in a dropdown by FirstName, LastName, and Email I have created an index marking the fields with the suggester in the azure console as follows:
This only works for a query by the FirstName but not for FirstName "space" LastName, when I run this query I just get 0 documents
Example:
Name John Doe
- John, I get suggestions for all Johns
- John , I get suggestions for all Johns
- John D, I get 0 documents
- John Doe, I get 1 document
This is my code:
term = Uri.EscapeDataString(term);
SuggestParameters sp = new SuggestParameters
{
Top = 20,
UseFuzzyMatching = true,
SearchFields = new List<string> { "FirstName", "LastName","Email" },
Select = new List<string> { "Id","FirstName", "LastName", "Email" },
OrderBy = new List<string> { "FirstName", "LastName", "Email" },
};
var docs = await _indexClient.Documents.SuggestAsync(term, "sg", sp);
- Can I split the query by terms like one to be the FirstName and the second one to be the LastName?
- Do I need to scape the term in a different way?
- Is there any wildcard I can use to have a similar behavior like a Like expresion in SQL?
Any help will be appreciated
回答1:
To Answer your question:
**Can I split the query by terms like one to be the FirstName and the second one to be the LastName?**
For Illustration, let't take below example:
POST /indexes/Flights/docs/search?api-version=2019-05-06
{
"search": "First Class, Spacious Seats* +\"Emirates\"",
"searchFields": "description, title",
"searchMode": "any",
"filter": "price ge 60 and price lt 300",
"orderby": "geo.distance(location, geography'POINT(-449.476235 11.212349)')",
"queryType": "full"
}
For this request, the search engine does the following:
- Filters out documents where the price is at least $60 and less than $300.
Executes the query. In this example, the search query consists of phrases and terms: "First Class, Spacious Seats* +\"Emirates\"" (users typically don't enter punctuation, but including it in the example allows us to explain how analyzers handle it). For this query, the search engine scans the description and title fields specified in searchFields for documents that contain "Emirates", and additionally on the term "First Class", or on terms that start with the prefix "Spacious Seats". The searchMode parameter is used to match on any term (default) or all of them, for cases where a term is not explicitly required (+).
Orders the resulting set of flights by proximity to a given geography location, and then returned to the calling application.
I believe , by this way you will be able to do **OR**
based search.
Do I need to scape the term in a different way?
Same as above
Is there any wildcard I can use to have a similar behavior like a Like expresion in SQL?
You can refer this link for wildcard search.
Reference:
https://littlekendra.com/2016/10/25/wildcard-vs-regular-expressions-lucene-query-in-azure-search/
Hope it helps.
来源:https://stackoverflow.com/questions/57684546/suggestions-by-more-than-one-term-or-space-in-between-in-azure-search-suggester