You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by caman <ab...@gmail.com> on 2011/01/13 02:01:24 UTC

Solr 4.0 => Spatial Search - How to

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.

Re: Solr 4.0 => Spatial Search - How to

Posted by Adam Estrada <es...@gmail.com>.
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 <estrada.adam.groups@gmail.com
> 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 <ab...@gmail.com>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.
>>
>
>

Re: Solr 4.0 => Spatial Search - How to

Posted by Stefan Matheis <ma...@googlemail.com>.
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 <ab...@gmail.com>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.
>

Re: Solr 4.0 => Spatial Search - How to

Posted by caman <ab...@gmail.com>.

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.

Re: Solr 4.0 => Spatial Search - How to

Posted by Stefan Matheis <ma...@googlemail.com>.
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 <ab...@gmail.com>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.
>

Re: Solr 4.0 => Spatial Search - How to

Posted by caman <ab...@gmail.com>.
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.

Re: Solr 4.0 => Spatial Search - How to

Posted by Lance Norskog <go...@gmail.com>.
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
<es...@gmail.com> 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 <ab...@gmail.com>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
goksron@gmail.com

Re: Solr 4.0 => Spatial Search - How to

Posted by Adam Estrada <es...@gmail.com>.
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 <ab...@gmail.com>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.
>

Re: Solr 4.0 => Spatial Search - How to

Posted by caman <ab...@gmail.com>.
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.

Re: Solr 4.0 => Spatial Search - How to

Posted by Adam Estrada <es...@gmail.com>.
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 <ab...@gmail.com>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.
>

Re: Solr 4.0 => Spatial Search - How to

Posted by "Grijesh.singh" <pi...@gmail.com>.
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. 

-----
Grijesh
-- 
View this message in context: http://lucene.472066.n3.nabble.com/Solr-4-0-Spatial-Search-How-to-tp2245592p2253682.html
Sent from the Solr - User mailing list archive at Nabble.com.