none
Suggestion doesn't work RRS feed

  • Question

  • Hi,

    We had set a suggester while creating index

    and made confirmed on azure dashboard.


    But we got an error message "The index does not have any fields marked as enabled for suggestions"

    while running the sample search project.

    Is there any setting missing??

    Thank you 

    --------------------------------------------------------------------------------------------------

    try
                {
                    var definition = new Index()
                    {
                        Name = "advazuresearch",
                        Fields = new[] 
                        { 
                           ...
                        },
                        Suggesters = new[]
                        {
                            new Suggester("suggester01", SuggesterSearchMode.AnalyzingInfixMatching, new List<string>(){"name_01","name_02"})
                        }

                    };

                    _searchClient.Indexes.Create(definition);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error creating index: {0}\r\n", ex.Message.ToString());
                }

    Thursday, November 19, 2015 8:33 AM

Answers

  • Hi Sam,

    If you are using C#, why not just use the official Azure Search SDK for .Net?

    With it, you don't have to worry about URLs or casting, just use (very simple sample):

    var client = new SearchServiceClient("search_service_name", new SearchCredentials("apiKey"));
    var indexClient = client.Indexes.GetClient("my_index");
    
    var results = indexClient.Documents.Suggest("my search Text", "my_suggester_name");
    var suggestedTexts = suggestions.Results.Select(x=>x.Text).ToList();
    It has Async version of methods too.

    Monday, November 23, 2015 11:17 AM

All replies

  • That code looks correct to me. Can you also include the definitions of the fields "name_01" and "name_02", as well as the code that calls Suggest?

    Thursday, November 19, 2015 4:29 PM
    Moderator
  • Hi!

    Can you check the index structure on the Azure Portal and verify that, when browsing your Index and switching to the Suggester tab, you see a Suggester configured with the fields "name_01" and "name_02" marked?

    Thursday, November 19, 2015 4:47 PM
  • HI,

    We've checked the setting below.

    Is that correct??

    Friday, November 20, 2015 9:21 AM
  • That should work, it would provide Suggestions based on the values of those 2 fields (name_AAU and name_ENU).

    Friday, November 20, 2015 11:32 AM
  • Sam, can you show the code you're using to call Suggest?
    Friday, November 20, 2015 9:30 PM
    Moderator
  • Hi, Bruce,


    We called Suggest by the following code

    public dynamic Suggest(string searchText)
    {
                Uri uri = new Uri(_serviceUri, "/indexes/advazuresearch/docs/suggest?search=" + Uri.EscapeDataString(searchText));

    HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(_httpClient, HttpMethod.Get, uri);
                AzureSearchHelper.EnsureSuccessfulSearchResponse(response);

                return AzureSearchHelper.DeserializeJson<dynamic>(response.Content.ReadAsStringAsync().Result);

    }



    and the definition of the suggestable fields are

    new Field("name_AAU",   DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = false, IsRetrievable = true},

    Really appreciate your advise

    Monday, November 23, 2015 2:19 AM
  • Hi Ealsur,

    Thanks a lot for the prompt advice.

    I'll check if my c# code that calls suggest miss any setting.


    Monday, November 23, 2015 2:22 AM
  • Hi Sam,

    If you are using C#, why not just use the official Azure Search SDK for .Net?

    With it, you don't have to worry about URLs or casting, just use (very simple sample):

    var client = new SearchServiceClient("search_service_name", new SearchCredentials("apiKey"));
    var indexClient = client.Indexes.GetClient("my_index");
    
    var results = indexClient.Documents.Suggest("my search Text", "my_suggester_name");
    var suggestedTexts = suggestions.Results.Select(x=>x.Text).ToList();
    It has Async version of methods too.

    Monday, November 23, 2015 11:17 AM
  • It looks like you're not setting the suggester name in the request. However, the error message is not very clear. I'll fix it.

    Ealsur's advice is the best -- You should use the .NET SDK for this, it will be much easier.

    Monday, November 23, 2015 6:51 PM
    Moderator
  • It appears that sample code you're using is out of date. It's using the API version from our Public Preview over a year ago. That's why the error message was unclear -- because suggesters didn't exist as a concept in that API version. If you had used the latest version, the message would have been "Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.

    Where did you find that sample code? I'd like to update it so other customers don't run into this problem.

    Thanks,

    -Bruce

    Monday, November 23, 2015 7:48 PM
    Moderator
  • Hi Bruce,

    We found the sample code here https://azuresearchadventureworksdemo.codeplex.com/

    links from https://azure.microsoft.com/en-us/documentation/articles/search-create-first-solution/ 

    Thanks a lot for your help.

    Sam

    Tuesday, November 24, 2015 1:19 AM
  • Hi Ealsur,

    It looks like I was using the out-of-date code.

    Thanks so much for your clear sample  !!!

    Sam

    Tuesday, November 24, 2015 1:33 AM
  • Thanks. I'll make sure that sample gets updated.
    Tuesday, November 24, 2015 1:40 AM
    Moderator