locked
Search returns only if query is less than two characters RRS feed

  • Question

  • I am using the search contract in my Windows 8 app. I haven't meddled around much with the search contract which is present by default when we add it from Visual Studio, since all the parameters like Title, Subtitle etc were the same. Whenever I perform a search, it only returns results, if the query is less than 2 characters. Also the search is case sensitive.
    How can i make it non case sensitive?
    And why does it return results only for two characters... 
    Am attaching the code that I am using for search :

    // This function executes each step required to perform a search.
            _handleQuery: function (element, args) {
                var originalResults;
                this._lastSearch = args.queryText;
                WinJS.Namespace.define("searchResults", { markText: WinJS.Binding.converter(this._markText.bind(this)) });
                this._initializeLayout(element.querySelector(".resultslist").winControl, Windows.UI.ViewManagement.ApplicationView.value);
                this._generateFilters();
                originalResults = this._searchData(args.queryText);
                if (originalResults.length === 0) {
                    document.querySelector('.filterarea').style.display = "none";
                } else {
                    document.querySelector('.resultsmessage').style.display = "none";
                }
                this._populateFilterBar(element, originalResults);
                this._applyFilter(this._filters[0], originalResults);
            },

     _searchData: function (queryText) {
                var originalResults;
                // TODO: Perform the appropriate search on your data.
                if (window.Data) {
                    originalResults = Data.items.createFiltered(function (item) {
                        return (item.title.indexOf(queryText) >= 0);
                    });
                } else {
                    originalResults = new WinJS.Binding.List();
                }
                return originalResults;
            }

    These are the two functions responsible for the search. 
    Thanks a lot in advance! :)

    Saturday, March 2, 2013 2:33 PM

Answers

  • Hi Shashav,

    For case-sensitive searching issue, I suggest you try debugging the windows store app in Visual Studio IDE and set breakpoint into the "_searchData" function (in the generated searchContract code) to see what is the query text passed in and whether the query text or the title (on the items be searched) is incorrectly capitalized.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 5, 2013 3:37 AM
    Moderator

All replies

  • I solved the search query thing. It returns answers for more than two characters too. But i still can't figure how to make the search in Search Contract non case sensitive
    Saturday, March 2, 2013 7:59 PM
  • Hi Shashav,

    For case-sensitive searching issue, I suggest you try debugging the windows store app in Visual Studio IDE and set breakpoint into the "_searchData" function (in the generated searchContract code) to see what is the query text passed in and whether the query text or the title (on the items be searched) is incorrectly capitalized.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 5, 2013 3:37 AM
    Moderator