You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Gurmit Teotia <gu...@gmail.com> on 2022/10/24 17:01:13 UTC

How to return location name in search result?

I've defined following field in my schema to store latitude and longitude-

<field name="loc_coords" type="location" uninvertible="true" indexed="true"
stored="true" sortMissingLast="true" multiValued="true"/>

and "location" is of following field type
<fieldType name="location" class="solr.LatLonPointSpatialField"
docValues="true"/>

I'm storing multiple latitude and longitude pairs in loc_coords field and
using a "geofilt" filter successfully able to retrieve the documents close
to a given point. I'm looking for your advice on how I can store the
location names, corresponding to latitude/longitude pairs and return them
in search result e.g. if "loc_coords" has following lat/long coordinates
for "London" and "New York"

["51.5072,0.1276", "40.7128,74.0060"]

In my search query when I'm looking for documents *near *to "New York" then
the above document will be returned  and in the search result I also want
to return the location name "New York".

I'm considering following two approaches to store location names and return
them in search result-

1. Store location names in a string array field ( call it location_names)
in the same order as lng/lat pair in location_coords field and somehow find
the index of matching lng/lat pair and use the index on location_names
field to retrieve the location name. This is just logical thinking. I'm not
sure how I can achieve it in Solr.

2. Store the data as GeoJson in solr because GeoJson allows to store extra
information along with coordinates as mentioned here- https://geojson.org/.
But I'm not sure how I'm going to get the location name of matching
coording in the search result.

Thank you for the help.

GS

Re: How to return location name in search result?

Posted by Gurmit Teotia <gu...@gmail.com>.
Thank you for your response. I don't like the denormalization approach for
3 reasons-
- More memory
- Increased efforts to keep the document in sync
- Filter out copies of documents from search if different copies of the
same document are returned in the search result because their locations are
quite close and within the search circle.

Not sure how I will solve it but I will look at next if I can write
custom functions to sort this out.


On Tue, 25 Oct 2022 at 16:29, Houston Putman <ho...@gmail.com>
wrote:

> This is a good question, but I'm not sure you are going to be able to do
> this easily.
>
> For any "which part of my document matched the query" questions we
> generally suggest the highlighting component:
> https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
> However, you want to return another field that relates to the part of the
> document that matches your query, so I don't think highlighting will do
> that for you.
>
> If you do not have a lot of data, I would recommend denormalizing your data
> if this feature is necessary.
> This means breaking up your current documents and duplicating them such
> that each document only holds one location (the field would be
> single-valued).
> That way whenever you get a document that matches, you can easily just
> return the string value of that location.
> The downside of this method is that your index will get bigger (but
> depending on the size right now this might not actually matter), and you
> need to update multiple documents anytime you want to change shared
> metadata.
>
> - Houston
>
> On Mon, Oct 24, 2022 at 1:01 PM Gurmit Teotia <gu...@gmail.com>
> wrote:
>
> > I've defined following field in my schema to store latitude and
> longitude-
> >
> > <field name="loc_coords" type="location" uninvertible="true"
> indexed="true"
> > stored="true" sortMissingLast="true" multiValued="true"/>
> >
> > and "location" is of following field type
> > <fieldType name="location" class="solr.LatLonPointSpatialField"
> > docValues="true"/>
> >
> > I'm storing multiple latitude and longitude pairs in loc_coords field and
> > using a "geofilt" filter successfully able to retrieve the documents
> close
> > to a given point. I'm looking for your advice on how I can store the
> > location names, corresponding to latitude/longitude pairs and return them
> > in search result e.g. if "loc_coords" has following lat/long coordinates
> > for "London" and "New York"
> >
> > ["51.5072,0.1276", "40.7128,74.0060"]
> >
> > In my search query when I'm looking for documents *near *to "New York"
> then
> > the above document will be returned  and in the search result I also want
> > to return the location name "New York".
> >
> > I'm considering following two approaches to store location names and
> return
> > them in search result-
> >
> > 1. Store location names in a string array field ( call it location_names)
> > in the same order as lng/lat pair in location_coords field and somehow
> find
> > the index of matching lng/lat pair and use the index on location_names
> > field to retrieve the location name. This is just logical thinking. I'm
> not
> > sure how I can achieve it in Solr.
> >
> > 2. Store the data as GeoJson in solr because GeoJson allows to store
> extra
> > information along with coordinates as mentioned here-
> https://geojson.org/
> > .
> > But I'm not sure how I'm going to get the location name of matching
> > coording in the search result.
> >
> > Thank you for the help.
> >
> > GS
> >
>

Re: How to return location name in search result?

Posted by Houston Putman <ho...@gmail.com>.
This is a good question, but I'm not sure you are going to be able to do
this easily.

For any "which part of my document matched the query" questions we
generally suggest the highlighting component:
https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
However, you want to return another field that relates to the part of the
document that matches your query, so I don't think highlighting will do
that for you.

If you do not have a lot of data, I would recommend denormalizing your data
if this feature is necessary.
This means breaking up your current documents and duplicating them such
that each document only holds one location (the field would be
single-valued).
That way whenever you get a document that matches, you can easily just
return the string value of that location.
The downside of this method is that your index will get bigger (but
depending on the size right now this might not actually matter), and you
need to update multiple documents anytime you want to change shared
metadata.

- Houston

On Mon, Oct 24, 2022 at 1:01 PM Gurmit Teotia <gu...@gmail.com> wrote:

> I've defined following field in my schema to store latitude and longitude-
>
> <field name="loc_coords" type="location" uninvertible="true" indexed="true"
> stored="true" sortMissingLast="true" multiValued="true"/>
>
> and "location" is of following field type
> <fieldType name="location" class="solr.LatLonPointSpatialField"
> docValues="true"/>
>
> I'm storing multiple latitude and longitude pairs in loc_coords field and
> using a "geofilt" filter successfully able to retrieve the documents close
> to a given point. I'm looking for your advice on how I can store the
> location names, corresponding to latitude/longitude pairs and return them
> in search result e.g. if "loc_coords" has following lat/long coordinates
> for "London" and "New York"
>
> ["51.5072,0.1276", "40.7128,74.0060"]
>
> In my search query when I'm looking for documents *near *to "New York" then
> the above document will be returned  and in the search result I also want
> to return the location name "New York".
>
> I'm considering following two approaches to store location names and return
> them in search result-
>
> 1. Store location names in a string array field ( call it location_names)
> in the same order as lng/lat pair in location_coords field and somehow find
> the index of matching lng/lat pair and use the index on location_names
> field to retrieve the location name. This is just logical thinking. I'm not
> sure how I can achieve it in Solr.
>
> 2. Store the data as GeoJson in solr because GeoJson allows to store extra
> information along with coordinates as mentioned here- https://geojson.org/
> .
> But I'm not sure how I'm going to get the location name of matching
> coording in the search result.
>
> Thank you for the help.
>
> GS
>