Hi Uwe, Indeed if I use StrField I'm able to retrieve the whole value. However, I want to be able to look up for individual terms as well, which is not possible anymore if I use StrField. To give an example: Solr query: *field_s:term3* Matches all documents that contain term3 in field_t. Unable to do so with StrField.
I was thinking about copying the fields into the "text" field, which uses text_general as field type. However, I can't make the distinction anymore between "documents that contain term3 in field_t" and "documents that contain term3 in other_field_t", which is important for me. I can only make the query "documents that contain term3 in any field". <doc> <str name="id">1</str> <str name="field_s">term1 term2 term3</str> < str name="other_field_s">term3 term4 term5</str> <doc> So the solution would be to duplicate each field: field_s copied to field_t other_field_s copied to other_field_t ... and so forth Then use field_s in the custom function. And use field_t for lookups (eg.* field_t:term3*). Duplicating them in this way seems rather inefficient. Is it so? On Wed, Jun 11, 2014 at 6:57 PM, Uwe Schindler <[email protected]> wrote: > Hi, > > > > You need to index this field with a different analyzer under a different > name. In Solr, this should be a StrField or a field with KeywordTokenizer. > For your use-case (random access to values), the field should ideally be a > docvalues field. > > > > Uwe > > > > ----- > > Uwe Schindler > > H.-H.-Meier-Allee 63, D-28213 Bremen > > http://www.thetaphi.de > > eMail: [email protected] > > > > *From:* Costi Muraru [mailto:[email protected]] > *Sent:* Wednesday, June 11, 2014 5:31 PM > *To:* [email protected]; [email protected] > *Subject:* How to retrieve entire field value (text_general) in custom > function? > > > > I have a text_general field and want to use its value in a custom > function. I'm unable to do so. It seems that the tokenizer messes this up > and only a fraction of the entire value is being retrieved. See below for > more details. > > > > <doc> > > <str name="id">1</str> > > <str name="field_t">term1 term2 term3</str> > > <long name="_version_">1470628088879513600</long></doc> > > <doc> > > <str name="id">2</str> > > <str name="field_t">x1 x2 x3</str> > > <long name="_version_">1470628088907825152</long></doc> > > > > > > public class MyFunction extends ValueSource { > > > > @Override > > public FunctionValues getValues(Map context, AtomicReaderContext > readerContext) throws IOException { > > final FunctionValues values = valueSource.getValues(context, > readerContext); > > return new StrDocValues(this) { > > > > @Override > > public String strVal(int doc) { > > return values.strVal(doc); > > } > > }; > > } > > } > > > Tried with SOLR 4.8.1. > > > > Function returns: > > - term3 (for first document) > > - null (for the second document) > > > > I want the function to return: > > - term1 term2 term3 (for first document) > > - x1 x2 x3 (for the second document) > > > > How can I achieve this? I tried to google it but no luck. I also looked > through the SOLR code but could not find something similar. > > > > Thanks! > > Costi >
