views:

697

answers:

3

If I have a multiValued field type of text, and I put values [cat,dog,green,blue] in it. Is there a way to tell when I execute a query against that field for dog, that it was in the 1st element position for that multiValued field?

Assumption: client does not have any pre-knowledge of what the field type of the field being queried is. (i.e. Solr must provide the answer and the client can't post process the return doc to figure it out because it would not know how SOLR matched the query to the result).

Disclosure: I posted to solr-user list and am getting no traction so I post here now.

+1  A: 

Currently, there's no out-of-the-box functionality provided in Solr which tells you the position of a value in a multiValue field.

Brian Mansell
(+1) This may be the true answer? Is it possible to run the field through the query and index analyzers, or extended versions of them as a client side post process? The key is that the client can produce the same hit that querying the server would.
harschware
oops I forgot to +1
harschware
A: 

The Lucene API allows for this, but I'm not sure if Solr does out of the box. In Lucene you can use the IndexReader.termPositions(Term term) method.

bajafresh4life
A: 

Hopefully I understand your question correctly.

If you want to get field index or value there is an ugly workaround:

You could add the index directly in the value e.g. store "1; car", "2; test" and so on. Then use highlighting. When reading the returned fields simply skip the text before the semicolon.

But if you want to query only one type:

You can avoid the multivalue approach and simply store it as item_i and query via item_1. To query against all items regardless the type you need to use the copyField directive in the schema.xml

Karussell