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.

Reply via email to