I've been trying to use ExternalFileField in ApacheSolr for external scoring.
I'm using the example config. Basically I want to set scores for items using their ids.
I set the fieldType idRankFile and field idRank in schema.xml:
<fieldType name="idRankFile" keyField="id" defVal="0" stored="true" indexed="true" class="solr.ExternalFileField" valType="pfloat" />
<field name="idRank" type="idRankFile" indexed="true" stored="true" />
And made a file called external_idRank in /solr/example/solr/data with the following content:
F8V7067-APL-KIT = 1.0
IW-02 = 10.0
9885A004 = 100.0
SOLR1000 = 1000.0
(This assigns idRank values for various ids)
Now I run the following query :
http://localhost:8983/solr/select/?indent=on&q=car%20power%20adapter%20_val_:%22product(idRank,1)%22&fl=name,id
This should basically return the results in order of their idRanks. However, it does not.
Any ideas?
Alright, so I had the same problem. This is what I did:
Create a file:
solr_home/PROJECT/multicore/core1/data/external_popularProducts.txt
The file should contain values like this:
uniqueID_in_core=count
Example:
873728721=19
842728342=20
Update schema.xml, add this under <types> </types>
<fieldType name="popularProductsFile" keyField="key" defVal="0" stored="true" indexed="true" class="solr.ExternalFileField" valType="float" />
Here, key
is the column name for the primaryID of solr core.
Add this under <fields></fields>
<field name="popularProducts" type="popularProductsFile" indexed="true" stored="true" />
Reload the core. I am using solr4.3 which has a bug. When I try to reload any core,the solrcloud node goes down. SOLR-4805: SolrCloud - RELOAD on collections or cores leaves collection offline and unusable till restart . So, I had to restart my solrcloud nodes.
Query:
http://SOLR_NODE:8983/solr/core1/select?q=ipad&sort=popularProducts desc
Note:
Most of the blogs written about ExternalFileField are not completely accurate. So just refer to the original documentation:
- http://lucene.apache.org/solr/4_3_1/solr-core/org/apache/solr/schema/ExternalFileField.html .
- http://docs.lucidworks.com/display/solr/Working+with+External+Files+and+Processes
Please improve this answer if you find any issues with it.