0

How do you configure md-autocomplete so that if you search for a word, it searches for strings within strings. At the moment it only finds the first word. As with the demo https://material.angularjs.org/latest/demo/autocomplete, if you type new, it finds New Jersey. But if you type jersey, it does not find anything.

This is my querySearch function

function querySearch(query) {
    var results = query ? vm.subjects.filter(createFilterFor(query)) : vm.subjects,
        deferred;
    return results;
}

This is my createFilterFor function

function createFilterFor(query) {
    var lowercaseQuery = angular.lowercase(query);
    return function filterFn(subject) {
        return (subject.Display.indexOf(lowercaseQuery) === 0);
    };
}
Michael Coxon
  • 5,311
  • 1
  • 24
  • 51
skunk
  • 83
  • 1
  • 8

2 Answers2

0

I solved it this way. Note there is an array with tags and and array without used for displaying.

            function querySearch(query) {

            var results = new Array();

            for (var i = 0, len = taggedSubjectArrray.length; i < len; i++) {
                var txtToCompare = taggedSubjectArrray[i].Display;

                if (txtToCompare.indexOf(query) != -1)
                {
                    // string was found
                    // Add to results
                    results.push(validationArrray[i]);
                }
            }

            return results;
        }
skunk
  • 83
  • 1
  • 8
0
//This worked for me

function createFilterFor(query) {
        debugger;
        //var lowercaseQuery = angular.lowercase(query);

        return function filterFn(product) {
            var results = new Array();

            var lowercaseQuery = angular.lowercase(query);

            index = 0,
            res = [];
            res.push(-1);

            //Get starting index of each word in string & push in array 
            while ((index = product.value.indexOf(' ', index + 1)) >= 0) {
                res.push(index);
            }

            for (var i = 0; i < res.length; i++) {
                var a = res[i] + 1;

                if (product.value.indexOf(lowercaseQuery) === a)
                {
                    return (product.value.indexOf(lowercaseQuery) === a);
                }
            }
        };
    }