简体   繁体   中英

Suggestions by more than one term or Space in between in Azure Search (Suggester)

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:

Azure搜索控制台

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM