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

_geoPoint and _geoRadius not working #4628

Closed
skalra90 opened this issue May 10, 2024 · 3 comments
Closed

_geoPoint and _geoRadius not working #4628

skalra90 opened this issue May 10, 2024 · 3 comments
Labels
needs more info This issue needs a minimal complete and verifiable example
Milestone

Comments

@skalra90
Copy link

Here is my code:

const results = await global.meiliClient.index("airports").search("", {
                sort: [`_geoPoint(${topLatitude}, ${topLongitude}):asc`],
                showRankingScore: true,
                showRankingScoreDetails: true
            });

results contains all airports not sorted by distance.

Index details:
{
    "displayedAttributes": [
        "airport_id",
        "name",
        "alias",
        "city_name",
        "city_alias",
        "country_name",
        "iata",
        "country_code",
        "type",
        "capital",
        "_geo"
    ],
    "searchableAttributes": [
        "name",
        "alias",
        "city_name",
        "city_alias",
        "country_name",
        "iata",
        "country_code",
        "capital"
    ],
    "filterableAttributes": [
        "_geo",
        "country_code",
        "type"
    ],
    "sortableAttributes": [
        "_geo",
        "type"
    ],
    "rankingRules": [
        "sort",
        "words",
        "typo",
        "proximity",
        "attribute",
        "exactness"
    ],
    "stopWords": [],
    "nonSeparatorTokens": [],
    "separatorTokens": [],
    "dictionary": [],
    "synonyms": {},
    "distinctAttribute": "airport_id",
    "proximityPrecision": "byWord",
    "typoTolerance": {
        "enabled": true,
        "minWordSizeForTypos": {
            "oneTypo": 5,
            "twoTypos": 9
        },
        "disableOnWords": [],
        "disableOnAttributes": []
    },
    "faceting": {
        "maxValuesPerFacet": 100,
        "sortFacetValuesBy": {
            "*": "alpha"
        }
    },
    "pagination": {
        "maxTotalHits": 1000
    },
    "searchCutoffMs": null
}

Checked all documents and found no invalid entry:

function checkGeoData(documents) {
    const invalidEntries = [];

    documents.forEach((doc, index) => {
        // Check if _geo exists and has both lat and lng
        if (!doc._geo || typeof doc._geo.lat !== "number" || typeof doc._geo.lng !== "number") {
            invalidEntries.push({ index, doc });
        }
    });
    return invalidEntries;
}

First document always with airport_id 1:

{
  name: "Goroka Airport",
  alias: null,
  city_name: "Goroka",
  city_alias: "Goronka",
  country_name: "Papua New Guinea",
  iata: "GKA",
  country_code: "PG",
  capital: "Port Moresby",
  airport_id: 1,
  _geo: {
    lat: -6.08169,
    lng: 145.391998,
  },
  type: "medium_airport",
  _geoDistance: 8294109,
  _rankingScore: 1,
  _rankingScoreDetails: {
    "_geoPoint(29.61611, 76.98056):asc": {
      order: 0,
      value: null,
      distance: null,
    },
  },
}

topLatitude = 29.61611
topLongitude = 76.98056

Same is for _geoRadius, no matter how big radius I make it returns no results.

Originally posted by @skalra90 in #4334 (reply in thread)

@irevoire
Copy link
Member

irevoire commented May 13, 2024

Hey @skalra90, could you run your search request again but with the ranking score details enabled and share the output here so I can see what’s going on?
Could you also share the meilisearch version you're using please?

Also, if your data are public, it would be nice if you could share a dump with me

@curquiza curquiza added the needs more info This issue needs a minimal complete and verifiable example label May 13, 2024
@skalra90
Copy link
Author

skalra90 commented May 13, 2024

Hey @irevoire

Indexes: airports and cities
URL: https://meili.rhombee.com
Key for accessing: 405b238c3616249d58e57d48a34fcb9aa9b86b148337567d72ee8117ab20afe6

Earlier _geoPoint and _geoRadius was working for airports only.
But _geoPoint and _geoRadius now works for cities as well. I deleted and built index again and somehow it started working. I changed nothing at all but it worked. WEIRD. But definitely worth looking into.

Now the problem I am facing is that the population sort doesn't seem to work and also takes a lot of time, may be it contains 0 as population for many cities but I didn't read anywhere that it doesn't work for 0 values.

@irevoire irevoire added this to the v1.8.1 milestone May 20, 2024
meili-bors bot added a commit that referenced this issue May 21, 2024
4642: Index the _geo fields when changing the setting while there is already documents in the DB r=ManyTheFish a=irevoire

# Pull Request

## Related issue
Fixes #4640
Fixes #4628

## What does this PR do?
- Add an integration test that first indexes the document and then changes the settings
- Fix `extract_geo_point` by detecting if the `_geo` field has been faceted in this setting change and index all documents

Co-authored-by: Tamo <[email protected]>
Co-authored-by: ManyTheFish <[email protected]>
@curquiza
Copy link
Member

Closed by #4642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs a minimal complete and verifiable example
Projects
None yet
Development

No branches or pull requests

3 participants