How to avoid retrieve entire stored field from sol

2019-05-24 14:52发布

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条回答
再贱就再见
2楼-- · 2019-05-24 15:27

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
查看更多
登录 后发表回答