1
votes

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.

3
I don't understand why you want to match only a certain position in the multiValued field...Mauricio Scheffer
@Mauricio - I don't want to match only a certain position, I want to know which position matched.harschware

3 Answers

3
votes

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

1
votes

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

0
votes

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.