Question

I have a problem querying multi value PointType field. Can this be done correctly in Solr.

Example document:

<doc>
    <field name="id">test1</field>
    <field name="xy">100,100</field>
    <field name="xy">0,100</field>
    <field name="xy">100,0</field>
    <field name="xy">0,-100</field>
    <field name="xy">-100,0</field>
    <field name="xy">-100,-100</field>
    <field name="xy">-100,100</field>
    <field name="xy">100,-100</field>
</doc>

Schema:

<fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
<field name="xy" type="point" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_d" type="double" indexed="true" stored="true" multiValued="true"/>

FQuery:

{!geofilt pt=0,0 sfield=xy d=15}

It should not match document but it does :(

My goal is to query that XY field to get documents sorted by distance (at some point it would like to have or in between geo queries and sum scores from each sub query to calculate final score for doc).

Any idea can this be done (simple query atm)?

Was it helpful?

Solution

{!geofilt} doesn't work with multivalue

http://wiki.apache.org/solr/SpatialSearch#LatLonType

But fortunately there is a new feature, which is SpatialRecursivePrefixTreeFieldType (abbreviated as RPT). This comes on SOLR 4.0 and later, so first check your solr version, and do an upgrade if you are still using 3.x version.

You will need to define the rpt field type

  <fieldType name="location_rpt"   class="solr.SpatialRecursivePrefixTreeFieldType"
       spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
       distErrPct="0.025" maxDistErr="0.000009" units="degrees" />

Then you can use it in a multivalue field

<field name="point" type="location_rpt" indexed="true" stored="true"  multiValued="true" />

And you need to write your query a bit differently now:

fq=geo:"Intersects(Circle(point d=1.5))"

And make sure that the distance is converted to degrees (not kilometers). This is a quick way to convert from kilometers to degrees

distantceInDegrees = distanceInKilometers / 111.2

More on queries here:

https://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top