AnsweredAssumed Answered

Get all features from query

Question asked by vakhtang_zuba on Sep 23, 2020

Hi guys,

 

I have autocomplete search widget generated from JQUERY.

 

Autocomplete works for some features ( it is street names ), but some features didn't appears in autocomplete, while if  i write in text field name of a street manually ( it should be full name, including , . ! etc) it finds the street.

When i check it on server side it does the same, if GEOMETRY is TRUE some features is missing, if FALSE again some features is still missing, no full features is responsed.

 

Here is a code i use: 

//Autocomplete

$(function () {
          var array = []
          queryTask = new QueryTask(myURL);
          query = new Query();
          query.returnGeometry = false;
          query.outFields = ["street_names"];
          query.where = "1=1";
          queryTask.execute(query).then(showResults);

          function showResults(results) {
            // Collect the results
            var resultItems = [];
            var resultCount = results.features.length;
            for (var i = 0; i < resultCount; i++) {
              var featureAttributes = results.features[i].attributes;
              for (var attr in featureAttributes) {
                // Convert the attribute to a string. Null Values create an extra comma which stops the widget from functioning.
                tags = String(featureAttributes[attr]);
                // push the attributes tothe blank array
                resultItems.push(tags);
              }
            }

            // Sort the array
            sorted = resultItems.sort()

            // Remove Duplicates
            var uniqueNames = [];
            $.each(sorted, function (i, el) {
              if ($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
            });

            // Set the varrible array
            array = uniqueNames

            // This is your AutoComplete Widget
            var availableTags = array;

            // Reference the div id which you want the autocomplete list to appear (in this case tag)(appear only 30 records)
            $("#searchInput").autocomplete({
              source: function (request, response) {
                var results = $.ui.autocomplete.filter(availableTags, request.term);

                response(results.slice(0, 20)); // მიუთითე რამდენი ჩანაწერი გინდა რომ გამოჩნდეს autocomplete- ში ერთდროულად.
              }
            });
          }
        });

Outcomes