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

useRefinementList not working as expected on a geopoint field #188

Open
iamarora opened this issue Oct 26, 2023 · 6 comments
Open

useRefinementList not working as expected on a geopoint field #188

iamarora opened this issue Oct 26, 2023 · 6 comments

Comments

@iamarora
Copy link

Description

The refine method on a geopoint field is giving an error.

Steps to reproduce

const { refine } = useRefinementList({ attribute: 'location_geo' });
// Tried the below
refine('(-44.50, 170.29, 20 mi)')

Expected Behavior

It should be able to refine results with lat, long and radius.

Actual Behavior

The error is
Error: 400 - Value of filter field location_geo: must be in the ([-44.50, 170.29], radius: 0.75 km, exact_filter_radius: 5 km) or ([56.33, -65.97, 23.82, -127.82], exact_filter_radius: 7 km) format.

Metadata

Typesense Version: 0.26.0.rc25

OS: Ubuntu

Ref: https://typesense-community.slack.com/archives/C01P749MET0/p1698234116317759

@jasonbosco
Copy link
Member

jasonbosco commented Oct 26, 2023

Generated query:

curl 'http://0.0.0.0:8108/multi_search?use_cache=true&x-typesense-api-key\
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Language: en-US,en-IN;q=0.9,en;q=0.8' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: text/plain' \
  -H 'Origin: http://localhost:3010/' \
  -H 'Referer: http://localhost:3010/' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' \
  --data-raw '{"searches":[{"query_by":"full_name","min_len_2typo":8,"split_join_tokens":"fallback","sort_by":"update_time:asc","per_page":40,"highlight_full_fields":"full_name","collection":"people_index","q":"*","facet_by":"location_city_geo_map,location_geo,org_funding_types_all,org_funding_types_current,org_industries_current,org_industry_groups_current,org_sizes_current","filter_by":"location_geo:=[`(56.33, -65.97, 20 mi)`]","max_facet_values":40,"page":1},{"query_by":"full_name","min_len_2typo":8,"split_join_tokens":"fallback","sort_by":"update_time:asc","per_page":40,"highlight_full_fields":"full_name","collection":"people_index","q":"*","facet_by":"location_geo","max_facet_values":40,"page":1}]}' \
  --compressed \
  --insecure

This is the problematic part:

"filter_by": "location_geo:=[`(56.33, -65.97, 20 mi)`]"

It should have been:

"filter_by": "location_geo:=(56.33, -65.97, 20 mi)"

@hdw1219
Copy link

hdw1219 commented Nov 30, 2023

Hi! any eta on this issue?

@iamarora
Copy link
Author

Hi! any eta on this issue?

Hey, I ended up using this to get my use case working. Doesn't look like refinement lists work with geopoint fields.

@hdw1219
Copy link

hdw1219 commented Nov 30, 2023

Hi! any eta on this issue?

Hey, I ended up using this to get my use case working. Doesn't look like refinement lists work with geopoint fields.

Thank you very much.

I use this temporary solution for now:

const finalLocation = location ? location : undefined;

const finalRadius = finalLocation ? radius * 1000 : undefined;

<InstantSearch searchClient={searchClient} indexName={'candidats'}>
  <Configure
    aroundLatLng={finalLocation}
    aroundRadius={finalRadius}
  />

finalLocation: 45.5764258, -73.5466107
finalRadius: 75000

@iamarora
Copy link
Author

Hi! any eta on this issue?

Hey, I ended up using this to get my use case working. Doesn't look like refinement lists work with geopoint fields.

Thank you very much.

I use this temporary solution for now:

const finalLocation = location ? location : undefined;

const finalRadius = finalLocation ? radius * 1000 : undefined;

<InstantSearch searchClient={searchClient} indexName={'candidats'}>
  <Configure
    aroundLatLng={finalLocation}
    aroundRadius={finalRadius}
  />

finalLocation: 45.5764258, -73.5466107 finalRadius: 75000

Yeah, I had tried the configure widget as well. That's good to apply the initial filter, but when the values change dynamically from the FE it wasn't filtering then, but the initial filter was working well with the Configure widget.

@hdw1219
Copy link

hdw1219 commented Nov 30, 2023

location and radius are states so it's working when i change values dynamically. But it's rendering everytime!

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

No branches or pull requests

3 participants