简体   繁体   English

确定哪个值在SOLR多值字段类型中产生了命中

[英]determine which value produced a hit in SOLR multivalued field type

If I have a multiValued field type of text, and I put values [cat,dog,green,blue] in it. 如果我有一个multiValued字段类型的文本,我将值[cat,dog,green,blue]放入其中。 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? 有没有办法告诉我何时对狗的那个字段执行查询,它是否在该multiValued字段的第一个元素位置?

Assumption: client does not have any pre-knowledge of what the field type of the field being queried is. 假设:客户端对所查询的字段的字段类型没有任何预先知识。 (ie 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). (即Solr必须提供答案,客户端不能对返回文档进行后处理,因为它不知道SOLR如何将查询与结果相匹配)。

Disclosure: I posted to solr-user list and am getting no traction so I post here now. 披露:我发布到solr-user列表并且没有牵引力所以我现在在这里发布。

目前,Solr中没有提供开箱即用的功能,它告诉您multiValue字段中值的位置。

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 eg store "1; car", "2; test" and so on. 您可以直接在值中添加索引,例如存储“1; car”,“2; test”等。 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. 您可以避免使用多值方法,只需将其存储为item_i并通过item_1进行查询。 To query against all items regardless the type you need to use the copyField directive in the schema.xml 要查询所有项目,无论您需要在schema.xml中使用copyField指令

The Lucene API allows for this, but I'm not sure if Solr does out of the box. Lucene API允许这样做,但我不确定Solr是否可以开箱即用。 In Lucene you can use the IndexReader.termPositions(Term term) method. 在Lucene中,您可以使用IndexReader.termPositions(Term term)方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM