Hi below is data xml which I have inserted in solr.
<add>
<doc>
<field name="id">3007</field>
<field name="name">Autauga</field>
<field name="coord">POLYGON((-10 30,-40 40,-10 -20,40 20,0 0,-10 30))</field>
</doc>
</add>
There will be many documents of such type denoting separate regions
Now please let me know How can I search that document having a given point which lies in the range of polygon.
Your Solr Version must be 4 or higher and you have to import the JTS jar-file. You also have to define a field with a fieldType of "solr.SpatialRecursivePrefixTreeFieldType". Then you can query using a filter query like fq=geo:"Intersects(10.12 50.02)".
But please see my previous post or http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 for more detailed information.
Related
I have a dynamic numeric multivalued field in my solr schema -
<dynamicField name="*_nm" type="float" indexed="true" stored="true" multiValued="true" omitNorms="false"/>
I'd like to run a function score on said field -
_val_:"if(exists(features.width_nm),mul(exp(div(pow(max(0,sub(abs(sub(features.width_nm,12.00000)),0.00000)),2),-51.93702)),10.00000),0.000000)"
but function queries on multivalued fields aren't properly supported in my version of Solr (5.2.1). Trying the above gives the error -
"can not use FieldCache on multivalued field"
My current work-around for this is during indexing to create another field, numeric single-valued, which contains a "reduced" form of the multivalues.
Currently I do this in Java code.
Is there any way for me to do this directly in Solr? for example using a "copy-field"?
Just for completeness - In solr 6.3 I am able to calculate a function-score on a multivalued field by using the field function with a min/max parameter described here.
Thank you very much!
I am new to solr. Currently we are using solr 4.8.0. We have already done indexing, created fields, field types. Now I want to boost some of the fields using index time boosting. Does this have to be done in solrconfig.xml? What are the tags and syntax?
Index time boosts are applied for each field when the document is submitted to the index. You can either apply the boost to hits in a specific field or for the document as the whole (which would apply the same boost to all fields).
Example from the wiki:
<add>
<doc boost="2.5">
<field name="employeeId">05991</field>
<field name="office" boost="2.0">Bridgewater</field>
</doc>
</add>
after searching and searching over the net, i've found a possible open-source solution for the click-count-popularity in solr (=does not require a payd version of lucid work search).
In my next two answers i will try to solve the problem in a easy way and in a way a little bit complex...
But first some pre-requisites.
We suppose to google-like scenario:
1. the user will introduce some terms in a textfield and push the search button
2. the system (a custom web-app coupled with solr) will produce a web page with results that are clickable
3. the user will select one of the results (e.g. to access to the details) and will inform the system to change the 'popularity' of the selected result
The very easy way.
We define a field called 'popularity' in solr schema.xml
<field name="popularity" type="long" indexed="true" stored="true"/>
We suppose the user will click on the document with id 1234, so we (=the webapp) have to call solr to update the popularity field of the document with id 1234 using the url
http://mysolrappserver/solr/update?commit=true
and posting in the body
<add>
<doc>
<field name="id">**1234**</field>
<field name="popularity" update="inc">1</field>
</doc>
</add>
So, each time the webapp will query something to solr (combining/ordering the solr 'boost' field with our custom 'popularity' field) we will obtain a list ordered also by popularity
The more complex idea is to update the solr index tracing not only the user selection but also the search terms used to obtain the list.
First of all we have to define a history field where to store the search terms used:
<field name="searchHistory" type="text_general" stored="true" indexed="true" multiValued="true"/>
Then we suppose the user searched 'something' and selected from the result list the document with id 1234. The webapp will call the solr instance at the url
http://mysolrappserver/solr/update?commit=true
adding a new value to the field searchHistory
<add>
<doc>
<field name="id">**1234**</field>
<field name="searchHistory" update="add">**something**</field>
</doc>
</add>
finally, using the solr termfreq function in every following query we will obtain a 'score' that combined with 'boost' field can produce a sorted list based of click-count-popularity (and the history of search terms).
This is interesting approach however I see some disadvantages in it:
Overall items storage will grow dramatically with each and every search.
You're assuming that choosing specific item is 100% correct and it wasn't done by mistake or for brief only. In this way you might get wrong search results along the way.
I suggest only to increment the counter or even to maintain relative counter based on the other results that the user didn't click it.
I am importing data using the DIH and have a need to parse a string, capture two numbers, then populate a field of type=location (which accepts a "lat,long" coordinate pair). The logical thing to do is:
<field column="latLong"
regex="Latitude is ([-\d.]+)\s+ Longitude is ([-\d.]+)\s+"
replaceWith="$1,$2" />
It seems the DIH only knows about a single capture group. So $2 is never used.
Has anyone ever used more than one capture with the regexTransformer? Searching the documentation didn't provide any examples of $2 or $3. What gives, O ye priests of Solr?
It is not true that Solr DIH does not understand $2, $3, etc.,
I just tried this. Added this in DIH data-config.xml:
<entity name="foo"
transformer="RegexTransformer"
query="SELECT list_id FROM lists WHERE list_id = ${Lists.id}">
<field column="firstLastNum"
regex="^(\d).*?(\d)$"
replaceWith="$1:$2"
sourceColName="list_id"/>
</entity>
and then added the field in my schema.xml
<field name="firstLastNum" type="string" indexed="true" stored="true"/>
When I indexed a document with list_id = 390, firstLastNum was 3:0 which is indeed correct.
I suspect that the issue may be because of an incorrect regex which matches only the first part and not the second. Maybe try this regex:
regex="Latitude is ([-\d.]+)\s*Longitude is ([-\d.]+)"
Another reason could be that latLong is of location type and $1,$2 is of string type, but I am not sure about that.
Is there a way to increment a numeric field in solr that is indexed but not stored?
I.e. I have
<add>
<doc>
<field name="n">10</field>
</doc>
</add>
And the schema is something like:
<field name="n" indexed="true" stored="false" type="tint" />
And I want to do an update on n where for example i increment the current value by some value m.
The only thing I can think of is to make the value both stored and indexed, and then when I want to update the value I have to query solr to get the existing value then call the update endpoint to write out the new value. Or is there an easier way?
SOLR-139 was recently committed that will allow adding etc, but:
fields must be stored
Fix Version is not set but I guess is only on trunk