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 Pablo Ricco <pr...@gmail.com> on 2011/09/13 21:00:02 UTC

Get field value in custom searchcomponent (solr 3.3)

What is the best way to get a float field value from docID?
I tried the following code but when it runs throws an exception For input
string: "`??eI" at line float lat = Float.parseFloat(tlat);

schemal.xml:
...
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0"
omitNorms="true" positionIncrementGap="0"/>
...
    <field name="latitude" type="float" indexed="true" stored="true"
multiValued="false" />

component.java:

@Override
public void process(ResponseBuilder rb) throws IOException {
DocSet docs = rb.getResults().docSet;
SolrIndexSearcher searcher = req.getSearcher()
FieldCache.StringIndex slat =
FieldCache.DEFAULT.getStringIndex(searcher.getReader(), "latitude");
DocIterator iter = docs.iterator(); while (iter.hasNext()) {
 int docID = iter.nextDoc(); String tlat = slat.lookup[slat.order[docID]];
if (tlat != null) {
 float lat = Float.parseFloat(tlat); //Exception!
}
}
}

Thanks,
Pablo

Re: Get field value in custom searchcomponent (solr 3.3)

Posted by Chris Hostetter <ho...@fucit.org>.
: What is the best way to get a float field value from docID?
: I tried the following code but when it runs throws an exception For input
: string: "`??eI" at line float lat = Float.parseFloat(tlat);

the most most straight foward level of abstraction to use (if you want to 
leverage the field cache as you are trying to do here) is probably to get 
hte FieldType & SchemaField objects for your "latitude" field (from the 
IndexSchema) and then call FieldType.getValueSource.  You can then ask the 
ValueSource for the value for any given doc in your DocIterator.

that wa you don't have to worry about wether this is an IntField, or a 
TrieIntField, etc...


-Hoss