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 Abhishek tiwari <ab...@gmail.com> on 2013/05/09 09:05:53 UTC

Need solr query help

We are doing spatial search. with following logic.
a) There are shops in a city . Each provides the facility of home delivery
b) each shop has different  max_delivery_distance .

Now my query is suppose some one is searching from point P1 with radius R.

User wants the result of shops those can deliver him.(distance between P1
to shop s1 say d1 should be less than max_delivery distance say md1 )

how can i implement this by solr spatial query.

Re: Need solr query help

Posted by Amit Nithian <an...@gmail.com>.
Is it possible instead to store in your solr index a bounding box of store
location + delivery radius, do a bounding box intersection between your
user's point + radius (as a bounding box) and the shop's delivery bounding
box. If you want further precision, the frange may work assuming it's a
post-filter implementation so that you are doing heavy computation on a
presumably small set of data only to filter out the corner cases around the
radius circle that results.

I haven't looked at Solr's spatial querying in a while to know if this is
possible or not.

Cheers
Amit


On Sat, May 11, 2013 at 10:42 AM, smsolr <sm...@hotmail.com> wrote:

> Hi Abhishek,
>
> I forgot to explain why it works.  It uses the frange filter which is
> mentioned here:-
>
> http://wiki.apache.org/solr/CommonQueryParameters
>
> and it works because it filters in results where the geodist minus the
> shopMaxDeliveryDistance is less than zero (that's what the u=0 means, upper
> limit=0), i.e.:-
>
> geodist - shopMaxDeliveryDistance < 0
> ->
> geodist < shopMaxDeliveryDistance
>
> i.e. the geodist is less than the shopMaxDeliveryDistance and so the shop
> is
> within delivery range of the location specified.
>
> smsolr
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Need-solr-query-help-tp4061800p4062603.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Need solr query help

Posted by smsolr <sm...@hotmail.com>.
Hi Abhishek,

I forgot to explain why it works.  It uses the frange filter which is
mentioned here:-

http://wiki.apache.org/solr/CommonQueryParameters

and it works because it filters in results where the geodist minus the
shopMaxDeliveryDistance is less than zero (that's what the u=0 means, upper
limit=0), i.e.:-

geodist - shopMaxDeliveryDistance < 0
->
geodist < shopMaxDeliveryDistance

i.e. the geodist is less than the shopMaxDeliveryDistance and so the shop is
within delivery range of the location specified.

smsolr



--
View this message in context: http://lucene.472066.n3.nabble.com/Need-solr-query-help-tp4061800p4062603.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Need solr query help

Posted by smsolr <sm...@hotmail.com>.
Hi Abhishek,

I've had a look into this problem and have come up with a solution.

Following instructions assume you have downloaded the 4.3.0 release of Solr
from:-

http://www.apache.org/dyn/closer.cgi/lucene/solr/4.3.0

First add to:-

solr-4.3.0/solr/example/solr/collection1/conf/schema.xml

the following:-

   <field name="shopLocation" type="location" indexed="true" stored="true"/>
   <field name="shopMaxDeliveryDistance" type="float" indexed="true"
stored="true"/>

after the id field:-

   <field name="id" type="string" indexed="true" stored="true"
required="true" multiValued="false" /> 

Then start solr by going to:-

solr-4.3.0/solr/example

and running:-

java -jar start.jar

Then change into your solr-4.3.0/solr/example/exampledocs directory and
write the following text to a new file called shops.xml:-

<add>
	<doc>
		<field name="id">2468</field>
		<field name="name">Shop A</field>
 	       <field name="shopLocation">0.1,0.1</field>
	       <field name="shopMaxDeliveryDistance">10</field>
	</doc>
	<doc>
		<field name="id">2469</field>
		<field name="name">Shop B</field>
 	       <field name="shopLocation">0.2,0.2</field>
	       <field name="shopMaxDeliveryDistance">35</field>
	</doc>
	<doc>
		<field name="id">2470</field>
		<field name="name">Shop C</field>
 	       <field name="shopLocation">0.9,0.1</field>
	       <field name="shopMaxDeliveryDistance">25</field>
	</doc>
	<doc>
		<field name="id">2480</field>
		<field name="name">Shop D</field>
 	       <field name="shopLocation">0.3,0.2</field>
	       <field name="shopMaxDeliveryDistance">50</field>
	</doc>
</add>


Now run:-

./post.sh shops.xml 

You should get back something like:-


Posting file shops.xml to http://localhost:8983/solr/update
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int
name="QTime">120</int></lst>
</response>

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int
name="QTime">46</int></lst>
</response>


The doing the following queries in your browser:-

All 4 shops:-

http://localhost:8983/solr/select?q=name:shop&fl=name,shopLocation,shopMaxDeliveryDistance


All shops with distance from point 0.0,0.0 and ordered by distance from
point 0.0,0.0 (gives order A, B, D, C):-

http://localhost:8983/solr/select?q=name:shop&fl=name,shopLocation,shopMaxDeliveryDistance,geodist%28shopLocation,0.0,0.0%29&sort=geodist%28shopLocation,0.0,0.0%29%20asc


All shops with distance from point 0.0,0.0 and ordered by distance from
point 0.0,0.0 and filtered to eliminate all shops with distance from point
0.0,0.0 greater than shopMaxDeliveryDistance (gives shops  B and D):-

http://localhost:8983/solr/select?q=name:shop&fl=name,shopLocation,shopMaxDeliveryDistance,geodist%28shopLocation,0.0,0.0%29&sort=geodist%28shopLocation,0.0,0.0%29%20asc&fq={!frange%20u=0}sub%28geodist%28shopLocation,0.0,0.0%29,shopMaxDeliveryDistance%29


To delete all shops so you can edit the file to play with it and repost the
shops:-

http://localhost:8983/solr/update?stream.body=<delete><query>name:shop</query></delete>&commit=true



smsolr



--
View this message in context: http://lucene.472066.n3.nabble.com/Need-solr-query-help-tp4061800p4062591.html
Sent from the Solr - User mailing list archive at Nabble.com.