[Search Contract] How to display search results that are not into an object (listview), for example, a text that is the HTML content of a page. RRS feed

  • Question

  • Hello guys.

    It's clear to me how add search contract. But all examples that I saw, use a ListView Object that already have all information that are been searched:

    (See SearchData function, on search.js)

    searchData: function (queryText) {
                var originalResults;
                // TODO: Perform the appropriate search on your data.
                if (typeof (window.data) !== "undefined") {
                    originalResults = data.items.createFiltered(function (item) {
                      var regex = new RegExp(queryText, "gi");
                      return (item.title.match(regex) || item.subtitle.match(regex) || item.description.match(regex));
                } else {
                    originalResults = new WinJS.Binding.List();
                return originalResults;

    But if want to make a HTML page in the project, I mean, the HTML content of a static page be searchable?

    And if I have 250 HTML pages added on the project, and I want to make all this static content be searchable?

    Is there a way to do that? Or I will have to add all these content in a ListView?


    Thursday, May 17, 2012 12:25 PM


All replies

  • If you wish to 'Find' information in a document it is recommended you implemant that functionality from a tool bar item in your app.

    If you wish to truly do a search, it would be up to you to have the logic to search your HTML for the terms.  You could for instance loop over all your HTML that is in your application installed directory and parse through it.  Then provide it back as search terms.


    Jeff Sanders (MSFT)

    Thursday, May 17, 2012 6:44 PM
  • Hi jpsanders, thanks for your answer.

    Yes, I wish to do a search. But will I have to open each file on the directory with a filePicker, and read this information? I could not figure out a better way of doing this.


    • Edited by geovanneb Thursday, May 17, 2012 7:35 PM
    Thursday, May 17, 2012 7:25 PM
  • Hi Geo,

    You can open files in your application install directory (since this is Static HTML shipped with your app).


    You would get a StorageFolder object and then search for html files (actually hard code this since you know what they are), open them and then search each.


    Jeff Sanders (MSFT)

    Thursday, May 17, 2012 7:51 PM
  • Hi Jeff,


    It's a good solution. I'll develop this logic.


    Friday, May 18, 2012 12:47 PM