Reading multi-valued fields in a Function Query

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Reading multi-valued fields in a Function Query

Ugo Matrangolo-2
Hi,

I'm trying to write a function query that needs to stick a score [0..1] to
each doc in the search results based on some logic applied to a
multi-valued field in the document.

This is an excerpt of the schema:

    <field name="sku_store" type="string" indexed="true" stored="true"
multiValued="true"/>

And this is how it looks in a generic document on the index:

"sku_store": [ "women",
"women-apparel" ]

I need to access this multi-valued field at query time in a function query
that then I use to boost the search results.

I'm using the following code that is the best I have found to access a
multi-valued field inside a *ValueSource*:

  override def getValues(context: JMap[_, _], readerContext:
LeafReaderContext): FunctionValues =
    new DoubleDocValues(this) {
      val userGuidValue: FunctionValues = userGuidSource.getValues(context,
readerContext)
      *val skuStores: FunctionValues = new
SortedSetFieldSource("sku_store").getValues(context, readerContext)*

      override def doubleVal(docId: Int): Double = {
        // Fail fast and loud if the client is sending invalid GUIDs
        val userGuid: UUID = UUID.fromString(userGuidValue.strVal(docId))
        *val store: String = skuStores.strVal(docId) // How to get an
Iterable[String] ???*

        // Logic to compute the score based on userGuid and store
      }
    }

I have searched the documentation but using a *SortedSetFieldSource* and
invoking the *strVal(docId)* on it is the best I have found to access the
content of a multi-valued field.

The problem with this approach is that I can read only the *first *value
(in the above case would be 'women') skipping on the other one (that, of
course, is the one I'm mostly interested in).

What I'm looking for is something that will give me a way to *iterate *on
the values in the multi-valued `sku-store` field.

Any suggestion ?

Best
Ugo