locked
onresultsuggestionchosen event RRS feed

  • Question

  • Hello guys.

    According to the docs, this event only  fireS "when the user selects one of the suggested results that was provided by your app and displayed in the search pane."

    Now, I'm handling the suggestions requested event and I'm only adding custom suggestions to the list. Unfirtunately, the resultsuggestionchosen event insists on not firing. Any clues on what's going on? My code is really simple, so I'm not sure on what's going on:

    var searchPane = appModel.Search.SearchPane.getForCurrentView();
        searchPane.onquerysubmitted = function (eventObject) {
            nav.navigate(searchPageURI, eventObject);
        };
        
        searchPane.searchHistoryEnabled = false;
        var localContentSettings = new Windows.ApplicationModel.Search.LocalContentSuggestionSettings();
        localContentSettings.enabled = false;
        searchPane.setLocalContentSuggestionSettings(localContentSettings);
        searchPane.onsuggestionsrequested = function (e) {
            var pedido = e.request;       
            var texto = e.queryText.toLowerCase();
            var dadosFiltrados = dados.filter(function (item) {
                return item.nome.toLowerCase().indexOf(texto) >= 0;
            })
            .map(function (item) {
                return item.nome;
            });
            dadosFiltrados.forEach(function (nome) {
                if (pedido.searchSuggestionCollection.size < 5) {
                    pedido.searchSuggestionCollection.appendQuerySuggestion(nome);
                }
            });
          
        }
        searchPane.onresultsuggestionchosen = function (e) {
            var r = "";
        };


    Luis Abreu

    Saturday, May 5, 2012 11:24 AM

Answers

  • OK, I figured it out (sheesh)

    The suggestions with an image, title, and description are referred to as result suggestions.  These suggestions should be used to represent actual results and when the user clicks on one your application should take the user to the result itself instead of a search results page.

    So... If you modify the Search sample XML for scenario 6 to have this in it:

     <Item>
          <Text>Xbox 360 Shopping</Text>
          <Title> The title </Title>
          <Description>Game console systems and packages at a great deal.</Description>
          <Image source="http://www.example.com/xboxconsole.jpg" alt="Xbox 360 Consoles" width="75" height="75"/>
          <Url>http://www.example.com/games.aspx?q="Xbox 360"</Url>
        </Item>

    You will get the event fired.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, May 14, 2012 6:18 PM
    Moderator
  • Here is the complete documentation on the fields:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh700542.aspx


    Jeff Sanders (MSFT)

    Tuesday, May 15, 2012 5:39 PM
    Moderator

All replies

  • Try addEventListener like this:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.search.searchpane.resultsuggestionchosen.aspx

    also the sample shows how to respond to this event (including a defer for async).

    http://code.msdn.microsoft.com/windowsapps/Search-app-extension-sample-6baa6270

    -Jeff


    Jeff Sanders (MSFT)

    Monday, May 7, 2012 3:36 PM
    Moderator
  • Hello again Jeff.

    Unfortunately, I can't confirm it right away (the 2 days period for renewing the lic haven't passed by), but I'm almost positive that I tried it at the time (and it didn't work). Btw, stupid question: why do we have this event? At first sight, it looks like the only thing it gives is confirmation that the current search is being executed because the user picked a suggestion. am i wrong?


    Luis Abreu

    Tuesday, May 8, 2012 7:44 AM
  • Hi Luis,

    It should work, the sample works great and uses this code.  This is the only way you can provide a way to show something in your app once the user clicks on the suggestion... the source of where the suggesting came from for example.

    Try the sample and the suggesting once you are up and running again.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, May 8, 2012 2:03 PM
    Moderator
  • Hello again.

    ok. i understand.

    going back to the code, it's still not working:

    searchPane.addEventListener("resultsuggestionchosen", function (e) {
            document.getElementById("info").innerHTML = "JJ";
        });

    do you know if there's anything else I need to check to make it work?


    Luis Abreu

    Tuesday, May 8, 2012 3:58 PM
  • Did you get the sample to work?  What is different with your code or actions?  Are you providing suggestions?

    Jeff Sanders (MSFT)

    Wednesday, May 9, 2012 3:10 PM
    Moderator
  • Hello again.

    Well, not really.

    I've run the sample, picked one of the options which generate custom suggestions, and then clicked over one of the suggestions shown on the search pane (below the textbox). The breakpoint on the onResultSuggestiontChosen isn't hit (nor do I see the status being presented in the page).

    Does the sample run in your machine?


    Luis Abreu

    Wednesday, May 9, 2012 9:25 PM
  • Wow,

    I have to appologize.  I could have sworn I got this to work in the sample but double checked today and it is not hitting this event.

    I will see if I can track down what is going wrong here.  Thanks for reporting this Luis!!!

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, May 10, 2012 2:04 PM
    Moderator
  • No problem Jeff.

    Thanks again for taking the time to help me.


    Luis Abreu

    Thursday, May 10, 2012 9:45 PM
  • OK, I figured it out (sheesh)

    The suggestions with an image, title, and description are referred to as result suggestions.  These suggestions should be used to represent actual results and when the user clicks on one your application should take the user to the result itself instead of a search results page.

    So... If you modify the Search sample XML for scenario 6 to have this in it:

     <Item>
          <Text>Xbox 360 Shopping</Text>
          <Title> The title </Title>
          <Description>Game console systems and packages at a great deal.</Description>
          <Image source="http://www.example.com/xboxconsole.jpg" alt="Xbox 360 Consoles" width="75" height="75"/>
          <Url>http://www.example.com/games.aspx?q="Xbox 360"</Url>
        </Item>

    You will get the event fired.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, May 14, 2012 6:18 PM
    Moderator
  • ah...you're saying that it has to have an image for it to be considered a suggestion result??

    Luis Abreu

    Monday, May 14, 2012 8:34 PM
  • Title, Description, Text and Image!

    Documentation is slow but will catch up.  Also the sample will be updated.


    Jeff Sanders (MSFT)

    Tuesday, May 15, 2012 12:15 PM
    Moderator
  • Here is the complete documentation on the fields:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh700542.aspx


    Jeff Sanders (MSFT)

    Tuesday, May 15, 2012 5:39 PM
    Moderator
  • once again, thanks :)

    Luis Abreu

    Tuesday, May 15, 2012 8:48 PM