aupac / ember-aupac-typeahead

ember-cli ajax typeahead search component
MIT License
25 stars 38 forks source link

Doesn't display all found suggestions #32

Closed tevch closed 7 years ago

tevch commented 7 years ago
dropzoneSource: Ember.computed(function () {
    const _this = this;
    return function (query, syncResults, asyncResults) {
      var dropzones = _this.get('activeRegisteredDropzones');

      var results = dropzones.filter(function(record){
        var dz_name = record.get('dz_name');
        return dz_name.toLowerCase().indexOf(query.toLowerCase()) >= 0;
      });

      console.log('from names: found '+results.length+' dropzones');

      if(results.length<=0) {
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode( { "address": query }, function(geoResults, status) {
          if (status == google.maps.GeocoderStatus.OK && geoResults.length > 0) {
            var geoResult = geoResults[0];
            var geoResultLatLng = {latitude: geoResult.geometry.location.lat(), longitude: geoResult.geometry.location.lng()};

            results = dropzones.filter(function(record){
              var dzLatLng = {latitude: record.get('lat'), longitude: record.get('lon')};
              var inside = geolib.isPointInCircle(geoResultLatLng, dzLatLng, 200000);
              return inside;
            });
            console.log('from radius: found '+results.length+' dropzones');
          }
          asyncResults(results);
        });
      } else {
        syncResults(results);
      }
    };
  })

What happens is this:

searching for phrase "Gardiner" produces 3 results, and displays 3 searching for phrase "new york" produces 13 results, but displays ONLY 2

both searches trigger async geo search

what could be the problem? how would i even start figuring out why some results are not displayed?

Thanks

jackmatt2 commented 7 years ago

Could it be to do with the case "new york" vs "New York"?

jackmatt2 commented 7 years ago

As a test, can I suggest hard coding the returned results instead of actually hitting the API. That might reveal something on interest.

jackmatt2 commented 7 years ago

Since you are using the async function your might need async=true on the component also. This is part of the typeahead API. I wouldn't mix syncResults and asyncResults either. Use one or the other.

panthony commented 7 years ago

Since you are using async results you may encounter the following bug:

https://github.com/twitter/typeahead.js/pull/1212

jackmatt2 commented 7 years ago

This sounds like it would be resolved by #46