smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.03k stars 273 forks source link

Algolia label builder #221

Closed yznts closed 4 years ago

yznts commented 4 years ago

Intro

Hello! First of all, I'd like to thank maintainer of this library for such big work! :) It's pleasure to see in this project TypeScript, Jest, Github Actions, etc.

Problem

The problem I'd like to describe is related to Algolia default sorting and label builder function. As an example, I'd like to provide search results for such query "33130 miami":

https://hastebin.com/jupabijoji.json (33130 output for json sample)

      'Miami, Florida, 33101, United States of America',
      'Miami Avenue, Miami, Florida, 33130, United States of America',
      'South Miami Avenue, Miami, Florida, 33131, United States of America',
      'Southwest Miami Avenue Road, Miami, Florida, 33130, United States of America',
      'Brickell, Miami, Florida, 33131, United States of America',
      'Third Street, Miami, Florida, 33130, United States of America',
      'Latin Quarter, Miami, Florida, 33130, United States of America',
      'I 95, Miami, Florida, 33136, United States of America',
      'Southwest 8th Street,Tamiami Trail,Southeast 8th Street, Miami, Florida, 33144, United States of America',
      'Southwest 10th Avenue, Miami, Florida, 33130, United States of America',
      'Southwest 10th Street, Miami, Florida, 33130, United States of America',
      'Southwest 11th Avenue, Miami, Florida, 33130, United States of America',
      'Southwest 11th Street, Miami, Florida, 33130, United States of America',
      'Southwest 12th Street, Miami, Florida, 33135, United States of America',
      'Southwest 13th Street, Miami, Florida, 33145, United States of America',
      'Southwest 14th Street, Miami, Florida, 33145, United States of America',
      'Southwest 14th Terrace, Miami, Florida, 33145, United States of America',
      'Southwest 17th Road, Miami, Florida, 33129, United States of America',
      'Southwest 1st Avenue, Miami, Florida, 33131, United States of America',
      'Southwest 1st Court, Miami, Florida, 33130, United States of America'

As you can see, some postcodes are mismatched. Reason of this behaviour that we are taking first result from postcodes list, but algolia does not guarantee that values would be sorted by match level.

Solution

I'd like to propose a solution. Highlight results sorted in the same way as used values lists. So we can find index of value with matchLevel === 'full' and gracefully fallback to matchLevel === 'partial'. If any matches found, use first from the values list (just like now). In my case only postcode fix is needed, but I'd like to provide such solution for all values, used in label build.

Summary

I don't think that it's a bug. Just an ability to improve search results :) As one of the users and creators of algolia provider, I'm interested in providing solution. I'll create a PR in a few days.

yznts commented 4 years ago

I think this issue can be closed. @smeijer Thank you for fast review 👍

smeijer commented 4 years ago

Fixed by #222