Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearby API: Add sort parameter #1464

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bboure
Copy link
Member

@bboure bboure commented Jul 10, 2020

Hi,

This is a follow up of pelias/pelias#857.

In order to move step by step, I thought that the first one could be to add a sort parameter to the nearby API.

Possible values:

  • distance (default): records are sorted by distance, from the center point.
  • popularity: records are sorted by popularity (desc). Popular venues within the area (given the focus point and radius) are placed on top.

Motivation:
I want to be able to get popular venues within a given area.

Works well when used with the category filter: e.g: best bars around me.

Example:

/v1/nearby?point.lat=41.40140682071436&point.lon=2.191686630249024&debug=1&categories=nightlife&sort=popularity

Result:

0) Razzmatazz, Barcelona, Spain
1) L'Aliança del Poblenou, Barcelona, Spain
2) BeGood Club, Barcelona, Spain
3) Bodega Carol, Barcelona, Spain
4) El Cafè Blau, Barcelona, Spain
5) El Maderal, Barcelona, Spain
6) Atrium, Barcelona, Spain
7) Isami, Barcelona, Spain
8) Nicasso, Barcelona, Spain
9) La Tagliatella, Barcelona, Spain

Debug Query:

{
    "query": {
    "bool": {
        "filter": [
        {
            "geo_distance": {
            "distance": "1km",
            "distance_type": "plane",
            "center_point": {
                "lat": 41.40140682071436,
                "lon": 2.191686630249024
            }
            }
        },
        {
            "terms": {
            "layer": [
                "venue",
                "address",
                "street"
            ]
            }
        },
        {
            "terms": {
            "category": [
                "nightlife"
            ]
            }
        }
        ]
    }
    },
    "size": 20,
    "track_scores": true,
    "sort": [
    "_score",
    {
        "popularity": {
        "order": "desc"
        }
    }
    ]
}

I will appreciate your feedback.

Related PR: pelias/query#123

TODO:

  • Add unit tests

@orangejulius
Copy link
Member

orangejulius commented Jul 17, 2020

Hi @bboure,
To be honest, the nearby endpoint isn't currently something we spend a lot of time thinking about, so I doubt either @missinglink or I have strong feelings here.

Fortunately, this is open source, where the project maintainers don't have to have strong feelings about every single feature :)

So I'm happy to essentially make you the project manager of the nearby endpoint. I do think it makes sense to have a sort parameter that looks at popularity, so feel free to go forward with this feature. We'll merge improvements that you think are useful if they don't break other endpoints 🤣

I've just invited you to the Pelias Contributors team which means you can create branches and open pull requests directly from the Pelias org, to make things easier on you. It also means our CI will generate docker images for any PRs you open.

🚀

@bboure
Copy link
Member Author

bboure commented Jul 17, 2020

Thank you for the invite @orangejulius
I'll keep working on this then and let you known when I think this is mergeable.

@bboure bboure force-pushed the feat/popularity-sort branch from d0b7a3d to 12886fe Compare September 22, 2020 05:37
@bboure
Copy link
Member Author

bboure commented Jan 17, 2021

Hi,

Some feedback on this. I have been testing this over the past few months. It hasn't made it to production (We haven't launched the product yet) but seems to be working pretty well, especially if the radius is limited to s small area and the layers are limited to venues only, which should be the recommended way of using this.

Example of usage:
Top touristic venues in a given area:

image

Logs:

info: [api] ::ffff:10.0.0.97 - - [17/Jan/2021:16:45:13 +0000] "GET /v1/nearby?point.lon=2.2056249941050794&size=40&layers=venue&categories=tourism&sort=popularity&boundary.circle.radius=7.065170809924477&point.lat=41.37980261117921 HTTP/1.1" 200 51246
info: [api] elasticsearch controller=search, queryType=reverse, es_hits=721, result_count=80, es_took=101, response_time=113, layers=[venue], size=40, private=false, point.lat=41.393325741087345, point.lon=2.1767000523781235, boundary.circle.radius=7.063700682170273, boundary.circle.lat=41.393325741087345, boundary.circle.lon=2.1767000523781235, categories=[tourism], sort=popularity, name=English, iso6391=en, iso6393=eng, via=header, defaulted=false, querySize=80, retries=0, text_length=0

Any additional feedback or suggestions are welcome.

@Joxit
Copy link
Member

Joxit commented Oct 25, 2021

Hi @bboure, did you launch your project now ? I would like to try this feature in a real use case 😄

@bboure
Copy link
Member Author

bboure commented Oct 26, 2021

@Joxit Not yet 😞
Some other things with higher priorities got in the way.

It's not dead though!
I hope I can came back to it soon!

Will keep you posted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants