How to filter values returned on a multivalued field in Solr

大兔子大兔子 提交于 2019-12-06 05:19:07
beerbajay

This is not currently possible; see this bug and this previous question.

Use highlighting. @Jokin first mentioned it and I feel this is the best answer without hacking on Solr. Try either the PostingsHighlighter or the FastVectorHighlighter, not the default/standard highlighter. Unfortunately both of them internally execute a wildcard query against all UIDS in this field. FVH has the opportunity internally to be smarter about that but it's not implemented that way.

note: if it's within scope to write a little Java to add to Solr, the ideal answer would be to add term vectors (just the terms data in the term-vector, no offsets/positions) and then write a "DocTransformer" to grab the term vector terms; seek to the prefix, then iterate on those that have that prefix. Pretty darned fast.

I don't know how big it's your index, but having a document with 100k multivalued fields doesn't seem the right approach to me. In this cases instead of asking for a feature in solr, it's better to refactor your index and store the information in other way, maybe creating another core with documents that have each the uniqueid of your document and a field with the guid. You can use then field collapsing or other solr features to get the info that you need.

So, for example, a simple case in solr was to index books, and instead of indexing each book as a whole, it was better to index each separate page as a document. If you could tell us a bit more about your case we can think how the index can be improved.

Anyway, for cases that doesn't have so many values you can achive the same result with the highlighting component. for best performance you can exclude the field in the return field list, and use the highlighter to return the matched terms. You can tune the highlighter to get the maximum number of snippets and how big is each one etc. http://localhost:8893/solr/test1/select?q=uuids%3A5ff6115e*&rows=1&fl=id&wt=json&indent=true&hl=on&hl.fragsize=1&hl.fl=uuids

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!