Solr geographical search - solr

i am testing solr query for geographical search, this is my query:
SolrQuery query =new SolrQuery();
query.setParam("q","*:*");
query.setParam("fq","geofilt");
query.setParam("d","100000");
query.setParam("pt","51.53750834,-0.19329616");
query.setParam("sfield","location_s");
i am getting no results although there is very near points and also exact point to the pt.
any idea whats the reason??
hint: im using this field type for spatial search (the one comes in the schema.xml by default):
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" />
because when i try to use this one as mentioned in the solr website i get an error:
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType" spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
autoIndex="true"
distErrPct="0.025"
maxDistErr="0.000009"
units="degrees" />
and this is my field definition:
<field name="location_s" type="location_rpt" indexed="true" stored="true"/>
thanks in advance!

instead of this kind of field names please add only 1 field that served for both x/y :
<dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="true"/>
That will allow you to put directly datas in solr geo format :
"env": "DEV",
"latlgn_0_coordinate": -2.6263,
"latlgn_1_coordinate": -44.1978,
please take a look to both solr spatialsearch & solr wiki spatialsearch

As said above, please make sure to have in your runtime classpath.
You might download and install in your path the JTS library : JTS Library
Solr Manual solr install documentation
The JTS jar file must be on Solr's classpath as well. Due to a
combination of things, JTS can't simply be referenced by a ""
entry in solrconfig.xml; it needs to be in WEB-INF/lib in Solr's war
file, basically.
enjoy :)

Thanks jean, it worked with me without using JTS library, solr schema comes already with this field type that I used:
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" />
I defined a field of that type and it worked. This is my query:
SolrQuery query =new SolrQuery();
query.set("q","*:*");
query.set("fq","{!geofilt}");
query.set("pt","32.014708,35.873725");
query.set("sfield","location");
query.set("d","100");
Thanks.

Related

Adding fields to Solr using the API

I am very new to solr. I am trying to add a large number of fields to the schema. I am using version 8.1, and it is my understanding that it should be done through the API.
I am trying to upload all fields using curl, but keep getting errors. It works fine through the web interface.
1. Where can I find the correct field types? I checked
here, but I get error messages like "Field type 'StrField' not found".The values are also different from the ones that I get presented with in the webinterface.
2. Enum valuesI found documentation, which also results in an unknown field error. For enumns I don't see an option in the web interface.
<\p>
curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field":{"name":"TEST","type":"string","required":"true","stored":true,"indexed":"true"}}' http://localhost:8983/api/cores/tgec/schema
{
"responseHeader":{
"status":400,
"QTime":27},
"error":{
"metadata":[
"error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject",
"root-error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject"],
"details":[{
"add-field":{
"name":"TEST",
"type":"StrField",
"required":"true",
"stored":true,
"indexed":"true"},
"errorMessages":["Field 'TEST': Field type 'StrField' not found.\n"]}],
"msg":"error processing commands",
"code":400}}
There is field type named "string" and the class is of "solr.StrField".
Its defined in schema.xml as below.
<fieldType name="string" class="solr.StrField" sortMissingLast="true" docValues="true" />
Then when you define a field, you mention a type string to it as below.
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
You need to change the "type":"StrField" to "type":"string".

Solr Spatial - Indexing bean

I need to index on Solr a bean that contains a generic spatial field (generally, a polygon).
I configured my Solr core schema in this way (following the tutorial here):
<fieldType name="area" class="solr.RptWithGeometrySpatialField" spatialContextFactory="org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory"
autoIndex="true"
validationRule="repairBuffer0"
distErrPct="0.025"
maxDistErr="0.001"
distanceUnits="kilometers" />
....
<field name="location" type="area" indexed="true" stored="true" required="true" multiValued="false" />
My bean class is as follows:
public class MySolrBean {
#Field("id")
private String id;
#Field("location")
private Geometry location;
// getters and setters...
}
where Geometry refers to com.vividsolutions.jts.geom.Geometry (jts-1.13)
When I try to add a new bean to the index with SolrClient.addBean(Object) I get the following error:
Unable to parse shape given formats "lat,lon", "x y" or as WKT because java.text.ParseException: Unknown Shape definition [com.vividsolutions.jts.geom.Polygon:POLYGON ((1 0, 0.9980267284282716 0.0627905195293134, 0.9921147013144779 0.12533323356430...]
where WKT representation of my polygon is prefixed by the class fqn. I remember I saw a similar problem some time ago, this time when using ZonedDateTime: I changed my code to use java.util.Date and everything worked.
Though now I would not know which class to use instead of com.vividsolutions.jts.geom.Geometry and surfing the web I didn't find any documentation about that.
Anyone can help me out sorting this issue?
EDIT
Forgot to mention I'm using the latest Solr and Solrj distribution: 6.5.1

Solr facet tag exclude does not work with space

I am using exclude and tag for faceting. Strange this is it works where I don't have space in value.
http://192.168.2.114:8983/solr/customer/select?indent=on&q=*:*&fq=(%7B!tag%3DstateName%7DstateName:%22Gujarat%22)&fq=(%7B!tag%3DstateName%7DstateName:%22AndhraPradesh%22)&facet=true&facet.limit=100&facet.mincount=0&facet.field=%7B!ex%3DstateName%7DcountryName&facet.field=%7B!ex%3DstateName%7DstateName&facet.field=%7B!ex%3DstateName%7Dicity&facet=true - This works
but
http://192.168.2.114:8983/solr/customer/select?indent=on&q=*:*&fq=(%7B!tag%3DstateName%7DstateName:%22Gujarat%22)&fq=(%7B!tag%3DstateName%7DstateName:%22Andhra Pradesh%22)&facet=true&facet.limit=100&facet.mincount=0&facet.field=%7B!ex%3DstateName%7DcountryName&facet.field=%7B!ex%3DstateName%7DstateName&facet.field=%7B!ex%3DstateName%7Dicity&facet=true - This does not
The only difference between these two is a space in {!tag=stateName}stateName="Andhra Pradesh" ({!tag=stateName}stateName="AndhraPradesh" - this works).
I don't understand why. I have tried encoding the URL, i.e. put + or %20 for space, still no luck.
PFA images for the same
Working copy
EDIT
Here is the definition of stateName field.
<field name="stateName" type="string" multiValued="false" indexed="true" stored="true"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
Problem is that local parameters in query must be at the beginning of the string:
{!tag=stateName}(stateName:"Andhra Pradesh")
and not
({!tag=stateName}stateName:"Andhra Pradesh")
You can also avoid parenthesis:
{!tag=stateName}stateName:"Andhra Pradesh"

Is it possible to have a static index field for Liferay using solr-web plugin?

Can anyone tell me if I can associate a static index field for Liferay using the solr-web.plugin? Is there a way to define a static index in solr?
I need something similar to the following configuration in Nutch
<property>
<name>index.static</name>
<value>source:nutch</value>
</property>
This will add the field "source" as an index and its value as "nutch" to all documents in Nutch. Anything similar to this for Liferay + Solr?
Not sure for Liferay configuration, however you can add a default value in the schema.xml which will be applied to documents.
<field name="source" type="string" indexed="true" stored="true" default="Nutch" />

SOLR refuses to bring exact matches, How?

I have the following field type (notice no filters, no tokenizers)
<fieldType name="text_names" class="solr.StrField" />
I create a field in my schema using that type:
<field name="exact_type" type="text_names" indexed="true" stored="true" />
now, I search q=*:*&fq=exact_type:aa&fl=exact_type
I still get results which have other than 'aa' in the exact_type field.
What am I missing here?
Also this behaves the same:
q=exact_type:aa&fl=exact_type
I don't think that "q=*:*" works with DisMaxHandler and I believe that you are using it ,the correct syntax for both the queries should be:
q=&fq=exact_type:aa&fl=exact_type
fq=exact_type:aa&fl=exact_type

Resources