How to avoid retrieve entire stored field from solr

半世苍凉 提交于 2019-12-10 10:57:01

问题


I'm using sunspot and solr for a rails app to search ebook contens, for highlight feature I have to set the ebook_content as a stored filed, every time I queried solr for result, it sends back the entire document content about the book, which makes the query very slow.

How could I only get the result without the stored field?


回答1:


The fl parameter of Solr allows you to specify which fields you want returned in the result. If you had fields id, title, ebook_content, then you could use fl=id,title to omit the ebook_content field. I don't think there's support in Solr for getting all fields except one (e.g. -ebook_content).

Update

If you don't want to return the field in the normal results, but still want highlighting on that field, exclude the field as I described above, then turn on the highlighter:

hl=true

set the field(s) which should be highlighted:

hl.fl=ebook_content

and set the size of the highlighting fragment (in characters):

hl.fragsize=50

your finished query looks something like this:

?q=search term&fl=id,title&hl=true&hl.fl=ebook_content&hl.fragsize=50


来源:https://stackoverflow.com/questions/10301785/how-to-avoid-retrieve-entire-stored-field-from-solr

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