Solr Spatial search with self-intersecting polygons - search

I’m using Solr 4.3.0 with an up to date version of JTS and spatial4j. As field type in my schema.xml i’m using “location_rpt” like the description in the documentation.
Documentation
<field name="standort" type="location_rpt" indexed="true" stored="true" />
Now when my Application create a FilterQuery like this
standort:"IsWithin (POLYGON((16.243972778320312 48.27016879304729, 16.411170959472656 48.268340583150504, 16.44275665283203 48.19058119922813, 16.32396697998047 48.15921534239267,16.243972778320312 48.27016879304729)))
everything works fine. My problem is when im trying to use a more complex polygon (self-intersecting) Solr only shows an Error like this:
org.apache.solr.common.SolrException: com.spatial4j.core.exception.InvalidShapeException: Self-intersection at or near point (16.315572194579204, 48.26688289499306, NaN)
the corresponding query looks like this:
standort:"IsWithin (POLYGON((16.253585815429688 48.27748097861045, 16.506271362304688 48.23427822033628, 16.418380737304688 48.18646123261718, 16.286544799804688 48.28958948415696,16.253585815429688 48.27748097861045)))"
Screen of the Polygon
Are there any workarounds to get self-intersecting polgyon querys to work?

No, not really. You can use JTS on the client to clean up your polygon so that when Solr gets it, it's valid. See http://tsusiatsoftware.net/jts/jts-faq/jts-faq.html#G

Related

Using geospatial commands in rethinkdb with changefeed

right now I have a little problem:
I want to use geospatial commands (like getIntersecting) together with the changefeed feature of rethinkdb but I always get:
RqlRuntimeError: Cannot call changes on an eager stream in: r.db("Test").table("Message").getIntersecting(r.circle([-117.220406,32.719464], 10, {unit: 'mi'}), {index: 'loc'})).changes()
the big question is: Can I use getIntersecting with the changes() (couldn't find anything related to that in the docs btw ...) or do I have to abandon the idea of using rethinkdb geospatial features and just use change() to get ALL added or changed documents and do the geospatial stuff outside of rethinkdb?
You can't use .getIntersecting with .changes, but you can write essentially the same query by adding a filter after .changes that checks if the loc is within the circle. While .changes limits what you can write before the .changes, you write basically any query after the .changes and it will work.
r.table('Message')
.changes()
.filter(
r.circle([-117.220406,32.719464], 10, {unit: 'mi'})
.intersects(r.row('new_val')('loc'))
)
Basically, every time there is a change in the table the update will get push to the changefeed, but it will get filtered out. Since there is not a lot of support for geospatial and changfeeds, this is more or less how you would need to integrate the two.
In the future, changefeeds will be much broader and you'll be able to write basically any query with .changes at the end.

Solr spatial search , polygon intersect error

I am trying spatial search in SOLR 5.0 , My system are up and running, but sometimes I am coming across this error, I have google it around but found no explanation as such, anyone please help me with this.
My Error
because: com.spatial4j.core.exception.InvalidShapeException: Self-intersection at or near point
(13.143009111281323, 80.07316589355469, NaN)","code":400}})
My Query :
Intersects(POLYGON((13.142340452070176 80.07522583007812,13.141003126359843 80.079345703125
,13.141003126359843 80.08621215820312,13.1383284530778 80.09445190429688,13.1383284530778 80.101318359375
,13.136991105507466 80.11367797851562,13.131641642380112 80.14114379882812,13.128966867118496 80.15350341796875
,13.126292062732247 80.16311645507812,13.124954649619115 80.17135620117188,13.111580118251648 80.17135620117188
,13.099542418228534 80.15899658203125,13.095529720741494 80.10543823242188,13.09820485966459 80.10543823242188
,13.099542418228534 80.10406494140625,13.102217513557752 80.10406494140625,13.103555050321653 80.10269165039062
,13.106230102044576 80.101318359375,13.114255082724767 80.101318359375,13.1155925540513 80.09994506835938
,13.118267474880913 80.09857177734375,13.119604924382593 80.09857177734375,13.124954649619115 80.0958251953125
,13.127629468565612 80.0958251953125,13.130304258390225 80.09445190429688,13.131641642380112 80.09445190429688
,13.134316388511614 80.09307861328125,13.136991105507466 80.09033203125,13.139665793362148 80.0848388671875
,13.141003126359843 80.08346557617188,13.141003126359843 80.08209228515625,13.142340452070176 80.08071899414062
,13.142340452070176 80.0738525390625,13.14367777049247 80.07247924804688,13.14367777049247 80.07110595703125
,13.142340452070176 80.07522583007812)))distErrPct=0
Well, let's take a look at the polygon:
Looks reasonable, but pretty busy in the lower right:
There you can see the self-intersection, and self-intersecting polygons aren't acceptable (see Solr Spatial search with self-intersecting polygons for some more information on that).
It looks to me like you're trying to be more precise than your application is capable of.

Solr spatial search with input point and query which polygon within

I have some polygons indexed in Solr. Is it possible to query with a point(lat,lon) and see which polygon has that point inside?
Yes it is possible and described here: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
Your Solr Version must be 4 or higher and you have to import the JTS jar-file which you can get from http://sourceforge.net/projects/jts-topo-suite/
You have to define a field with a fieldType of location_rpt
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
distErrPct="0.025"
maxDistErr="0.000009"
units="degrees"
/>
in the schema.xml. Then you have to index the polygons like:
<field name="geo">POLYGON((-10 30, -40 40, -10 -20, 40 20, 0 0, -10 30))</field>
But i think you already did it this way because you wrote that you already have them indexed.
For the query you simply have to use the filter query fq=geo:"Intersects(10.12 50.02)" where 10.12 and 50.02 represent the latitude and longitude of your point.
We need the external JTS jar file to index Polygon shapes in first place.

How to create XML in Google custom search Autocomplete?

I try to use the structure at https://developers.google.com/custom-search/docs/queries but it can't upload successfully.
<Autocompletions>
<Autocompletion term="cake" type="1" language=""/>
<Autocompletion term="strawberry.*" type="2" match="2" language=""/>
<Autocompletion term="vanilla" type="2" language=""/>
<Autocompletion term="apple" type="3" language="">
<Promotion id="1" queries="dessert" title="Apple pie for dessert!" url="http://www.example.com/applepieforsale"
start_date="" end_date="" image_url="" description="Apple pie is the best dessert ever!"/>
<Promotion id="2" queries="apple" title="Buy Apple pie" url="http://www.example.com/applepieforsale"
start_date="" end_date="" image_url="" description="We stock the best apple pie in the world, right here."/>
</Autocompletion>
</Autocompletions>
My website is using wordpress; I get the title of posts and want to use it as string query for google custom search.
Please help me figure out how to create XML for autocomplete.
It's not liking the description attributes. It you remove those, then it will work.
Leave all terms in XML like that:
<Autocompletion term="%term-title%" type="%type%" language=""/>
Be careful with the length of the terms, I found that if it is 3 or less words, Google will accept it fine. There is also no big restriction on ammount of entries you're adding (I added 9000 entries in one go). And I added them in Russian, so there are no problems with encoding either.
The final format should be like that:
<Autocompletions>
<Autocompletion term="%term-title%" type="%type%" language=""/>
...
<Autocompletion term="%term-title%" type="%type%" language=""/>
</Autocompletions>
Not terribly well documented by Google, so you have to waste time reading this. Hope it helps :)

How to use an analyzer in compass-lucene search

How do I add compass analyzer while indexing and searching data in compass.I am using schema based configuration for compass.I want to use StandardAnalyzer with no stopwords.Because I want to index data as it is,without ignoring search terms like AND , OR , IN . The default analyzer will ignore AND , OR , IN from the data I give for indexing.
How do I configure snowball analyzer either thru code or thru xml. If someone could post me an example.
Below is the example. You can also find more details here
<comp:searchEngine useCompoundFile="false" cacheInvalidationInterval="-1">
<comp:allProperty enable="false" />
<!--
By Default, compass uses StandardAnalyzer for indexing and searching. StandardAnalyzer
will use certain stop words (stop words are not indexed and hence not searcheable) which are
valid search terms in the DataSource World. For e.g. 'in' for Indiana state, 'or' for Oregon etc.
So we need to provide our own Analyzer.
-->
<comp:analyzer name="default" type="CustomAnalyzer"
analyzerClass="com.ICStandardAnalyzer" />
<comp:analyzer name="search" type="CustomAnalyzer"
analyzerClass="com.ICStandardAnalyzer" />
<!--
Disable the optimizer as we will optimize the index as a separate batch job
Also, the merge factor is set to 1000, so that merging doesnt happen during the commit time.
Merging is a time consuming process and will be done by the batched optimizer
-->
<comp:optimizer schedule="false" mergeFactor="1000"/>
</comp:searchEngine>

Resources