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 Robert Krüger <kr...@lesspain.de> on 2015/10/15 17:19:20 UTC

Problem with custom function on binary content

Hi,

I am trying to implement a custom function that evaluates fields stored as
type "binary" (BinaryField).

I have my ValueSourceParser set up and I can retrieve the arguments of my
function correctly and have a reference to the SchemaField. Now I am a bit
stuck, how I can retrieve the binary content from a ValueSource?

Let's make this easier with an example. Let's say I have a field named
"fingerprint" defined as binary and I want to implement a custom function
"norm" that computes an integer from that binary content that can be used
in sorting or whatever.

The field is declared like this:

<field name="fingerprint" type="binary" indexed="true" stored="true"
multiValued="false"/>

I use "norm(fingerprint)" as my sorting expression and it arrives fine in
my ValueSourceParser.

To obtain a value source to use for the field value I tried two things:
1) parse the value source using parseValueSource()
2) parse the field name using parseId() and then something like:

SchemaField schemaField = fp.getReq().getSchema().getField(arg1);
ValueSource fieldValueSource =
schemaField.getType().getValueSource(schemaField, fp);

I thought I would just use that value source in my custom
FingerprintNormValueSource to retrieve the byte array via the
method org.apache.lucene.queries.function.FunctionValues#objectVal,
however, that always returns null for my documents.

Now I noticed that the ValueSource I get for the field is an instance
of org.apache.solr.schema.StrFieldSource and there objectVal is implemented
as strVal, which obviously will never return my fingerprint byte array.

Do I have to encode my byte arrays as strings or is there a direct way to
retrieve the binary data for use in my custom ValueSource?

Thanks a lot,

Robert