Searching books in Apache Solr

大兔子大兔子 提交于 2019-12-23 05:19:50

问题


I'm very new to Solr and I'm evaluating it. My task is to look for words within a corpus of books and return them within a small context. So far, I'm storing the books in a database split by paragraphs (slicing the books by line breaks), I do a fulltext search and return the row.

In Solr, would I have to do the same, or can I add the whole book (in .txt format) and, whenever a match is found, return something like the match plus 100 words before and 100 words after or something like that? Thanks


回答1:


Highlighting will do your bidding. http://wiki.apache.org/solr/HighlightingParameters

Here are relevant options for you:

hl.snippets

The maximum number of highlighted snippets to generate per field.....

hl.fragsize

The size, in characters, of the snippets (aka fragments) created by the highlighter.....
The default value is "100". 

hl.mergeContiguous

Collapse contiguous fragments into a single fragment....

For what you describe, set it to return 5 (or whatever a human can sanely handle) snippets from text field with hl.fl; the length of each snippet 400 characters (my approximation of 100 words) around the word/phrase.

See also hl.regex.slop for building snippets around phrases and hl.simple.pre/hl.simple.post for markup.



来源:https://stackoverflow.com/questions/9156614/searching-books-in-apache-solr

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