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 kevenz <fr...@qq.com> on 2013/05/23 03:52:59 UTC

How to query docs with an indexed polygon field in java?

hi, I'm using solr 4.3, I have indexed docs with a polygon field, and I'd
like to search the polygon docs according to the given point.
I've put the jts-1.13.jar into the WEB-INF/lib directory, and I've added the
doc to solr successfully.  I'm new to lucene and solr, I'm not sure how to
query indexed docs in java, any help would be appreciated.
scheme.xml: 
<fieldType name="location_rpt"
class="solr.SpatialRecursivePrefixTreeFieldType"
spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
distErrPct="0.025"
maxDistErr="0.000009"
units="degrees"
/>
<field name="geo" type="location_rpt" indexed="true" stored="true"
multiValued="true" />

java code:
String sql = "indexType:219" " AND "
"geo:Contains(POINT(114.078327401257,22.5424866754136))";
SolrQuery query = new SolrQuery();
query.setQuery(sql);
QueryResponse rsp = server.query(query);
SolrDocumentList docsList = rsp.getResults();
Then I got an error at "java.lang.IllegalArgumentException: missing parens:
Contains". Is there any suggestion?



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-query-docs-with-an-indexed-polygon-field-in-java-tp4065512.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to query docs with an indexed polygon field in java?

Posted by "David Smiley (@MITRE.org)" <DS...@mitre.org>.
Hi Kevenz,


kevenz wrote
> ...
> String sql = "indexType:219" " AND "
> "geo:Contains(POINT(114.078327401257,22.5424866754136))";
> ...
> Then I got an error at "java.lang.IllegalArgumentException: missing
> parens: Contains". Is there any suggestion?

First of all, if your query shape is a point, then use Intersects, which
semantically equivalent but works much faster.  One error in your query is
that your quotes look messed up.  Another is that you used a comma to
separate the X and Y when you should use a space (because you are using WKT
syntax via POINT).  Try this:

   indexType:219 AND geo:"Contains(POINT(114.078327401257
22.5424866754136))"

This will also work using lat comma lon non-WKT syntax:

   indexType:219 AND geo:"Contains(22.5424866754136, 114.078327401257)"

Disclaimer: I didn't run these, I just typed them in the email.

~ David



-----
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-query-docs-with-an-indexed-polygon-field-in-java-tp4065512p4065550.html
Sent from the Solr - User mailing list archive at Nabble.com.