Solr 4.0 => Spatial Search - How to

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Solr 4.0 => Spatial Search - How to

caman
Ok, this could be very easy to do but was not able to do this.
Need to enable location search i.e. if someone searches for location 'New York' => show results for New York and results within 50 miles of New York. We do have latitude/longitude stored in database for each record but not sure how to index these values to enable spatial search.
Any help would be much appreciated.

thanks
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Adam Estrada-2
I believe this is what you are looking for. I renamed the field called
"store" to "coords" in the schema.xml file. The tricky part is building out
the query. I am using SolrNet to do this though and have not yet cracked the
problem.

http://localhost:8983/solr/select?q=*:*+AND+eventdate:[2006-01-21T00:00:000Z+TO+2007-01-21T00:00:000Z]&fq={!bbox}&sfield=coords&pt=32.15,-93.85&d=500

Adam

On Wed, Jan 12, 2011 at 8:01 PM, caman <[hidden email]>wrote:

>
> Ok, this could be very easy to do but was not able to do this.
> Need to enable location search i.e. if someone searches for location 'New
> York' => show results for New York and results within 50 miles of New York.
> We do have latitude/longitude stored in database for each record but not
> sure how to index these values to enable spatial search.
> Any help would be much appreciated.
>
> thanks
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2245592.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

caman
Adam,

thanks. Yes that helps
but how does coords fields get populated? All I have is

<field name="lat" type="tdouble" indexed="true" stored="true" />
<field name="lng" type="tdouble" indexed="true" stored="true" />

<field name="coord" type="location" indexed="true" stored="true" />

fields 'lat' and  'lng' get populated by dataimporthandler but coord, am not sure?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Adam Estrada-2
In reply to this post by Adam Estrada-2
Actually, I by looking at the results from the "geofilt" filter it would
appear that it's not giving me the results I'm looking for. Or maybe it
is...I need to convert my results to KML to see if it is actually performing
a proper radius query.

http://localhost:8983/solr/select?q=*:*&fq={!geofilt%20pt=39.0914154052734,-84.517822265625%20sfield=coords%20d=5000}<http://localhost:8983/solr/select?q=*:*+AND+eventdate:[2006-01-21T00:00:000Z+TO+2007-01-21T00:00:000Z]&fq={!geofilt%20pt=32.15,-93.85%20sfield=coords%20d=5000}>

<http://localhost:8983/solr/select?q=*:*+AND+eventdate:[2006-01-21T00:00:000Z+TO+2007-01-21T00:00:000Z]&fq={!geofilt%20pt=32.15,-93.85%20sfield=coords%20d=5000}>Please
let me know what you find.

Adam

On Wed, Jan 12, 2011 at 8:24 PM, Adam Estrada <[hidden email]
> wrote:

> I believe this is what you are looking for. I renamed the field called
> "store" to "coords" in the schema.xml file. The tricky part is building out
> the query. I am using SolrNet to do this though and have not yet cracked the
> problem.
>
>
> http://localhost:8983/solr/select?q=*:*+AND+eventdate:[2006-01-21T00:00:000Z+TO+2007-01-21T00:00:000Z]&fq={!bbox}&sfield=coords&pt=32.15,-93.85&d=500<http://localhost:8983/solr/select?q=*:*+AND+eventdate:[2006-01-21T00:00:000Z+TO+2007-01-21T00:00:000Z]&fq=%7B!bbox%7D&sfield=coords&pt=32.15,-93.85&d=500>
>
> Adam
>
> On Wed, Jan 12, 2011 at 8:01 PM, caman <[hidden email]>wrote:
>
>>
>> Ok, this could be very easy to do but was not able to do this.
>> Need to enable location search i.e. if someone searches for location 'New
>> York' => show results for New York and results within 50 miles of New
>> York.
>> We do have latitude/longitude stored in database for each record but not
>> sure how to index these values to enable spatial search.
>> Any help would be much appreciated.
>>
>> thanks
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2245592.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Adam Estrada-2
In reply to this post by caman
In my case, I am getting data from a database and am able to concatenate the
lat/long as a coordinate pair to store in my coords field. To test this, I
randomized the lat/long values and generated about 6000 documents.

Adam

On Wed, Jan 12, 2011 at 8:29 PM, caman <[hidden email]>wrote:

>
> Adam,
>
> thanks. Yes that helps
> but how does coords fields get populated? All I have is
>
> <field name="lat" type="tdouble" indexed="true" stored="true" />
> <field name="lng" type="tdouble" indexed="true" stored="true" />
>
> <field name="coord" type="location" indexed="true" stored="true" />
>
> fields 'lat' and  'lng' get populated by dataimporthandler but coord, am
> not
> sure?
>
> Thanks
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2245709.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Lance Norskog-2
Spatial does not support separate separate fields: you don't need
lat/long, only 'coord'.

To get latitude/longitude in the coord field from the DIH, you need to
use a transformer in the DIH script.
It would populate a field 'coord' with a text string made from the lat
and lon fields:

http://wiki.apache.org/solr/DataImportHandler?#TemplateTransformer



On Wed, Jan 12, 2011 at 5:47 PM, Adam Estrada
<[hidden email]> wrote:

> In my case, I am getting data from a database and am able to concatenate the
> lat/long as a coordinate pair to store in my coords field. To test this, I
> randomized the lat/long values and generated about 6000 documents.
>
> Adam
>
> On Wed, Jan 12, 2011 at 8:29 PM, caman <[hidden email]>wrote:
>
>>
>> Adam,
>>
>> thanks. Yes that helps
>> but how does coords fields get populated? All I have is
>>
>> <field name="lat" type="tdouble" indexed="true" stored="true" />
>> <field name="lng" type="tdouble" indexed="true" stored="true" />
>>
>> <field name="coord" type="location" indexed="true" stored="true" />
>>
>> fields 'lat' and  'lng' get populated by dataimporthandler but coord, am
>> not
>> sure?
>>
>> Thanks
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2245709.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>



--
Lance Norskog
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Grijesh
In reply to this post by caman
I have used that type of location searching. But I have not used spatial search. I wrote my logic at application end.
I have cached the location ids and their lat/lang. When queries are comming for any location say "New Delhi" then my location searche logic at application end calculate the distance from "New Delhi" to other locations from my cache and short lists the only location which are in my radious. and then I have goto solr for search on all locations i have got from my logic.

It works faster because it worked on only some data near about 500 locations. But in spatial search that calculation is done for all document counts which we have .

So this workaround does not impact on performance when my index size will grow up but spatial search do.
Thanx:
Grijesh
www.gettinhahead.co.in
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

caman
In reply to this post by Lance Norskog-2
Thanks
Here was the issues. Concatenating 2 floats(lat,lng) at mysql end converted it to a BLOB. Indexing would fail in storing BLOB in 'location' type field.
After BLOB issue was resolved, all worked ok.

Thank you all for your help


Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Stefan Matheis
caman,

how did you try to concat them? perhaps some typecasting would do the trick?

Stefan

On Fri, Jan 14, 2011 at 7:20 AM, caman <[hidden email]>wrote:

>
> Thanks
> Here was the issues. Concatenating 2 floats(lat,lng) at mysql end converted
> it to a BLOB. Indexing would fail in storing BLOB in 'location' type field.
> After BLOB issue was resolved, all worked ok.
>
> Thank you all for your help
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2253691.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

caman

CONCAT(CAST(lat as CHAR),',',CAST(lng as CHAR))
Reply | Threaded
Open this post in threaded view
|

Re: Solr 4.0 => Spatial Search - How to

Stefan Matheis
absolutely no idea why it is a blob .. but the following one works as
expected:

CAST( CONCAT( lat, ',', lng ) AS CHAR )

HTH
Stefan

On Fri, Jan 14, 2011 at 9:31 AM, caman <[hidden email]>wrote:

>
>
> CONCAT(CAST(lat as CHAR),',',CAST(lng as CHAR))
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2254151.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>