schema.xml里配置term位置信息
<field name="text" type="text_en_splitting_tight" indexed="true" stored="true" multiValued="false" [b] termVectors="true" termPositions="true" termOffsets="true"[/b] />
如果使用了比较智能的分词,则要在solrconfig.xml里配置breakIterator
<boundaryScanner name="breakIterator" default="true"
class="solr.highlight.BreakIteratorBoundaryScanner">
<lst name="defaults">
<!-- type should be one of CHARACTER, WORD(default), LINE and SENTENCE -->
<str name="hl.bs.type">SENTENCE</str>
<!-- language and country are used when constructing Locale object. -->
<!-- And the Locale object will be used when getting instance of BreakIterator -->
<str name="hl.bs.language">en</str>
<str name="hl.bs.country">US</str>
</lst>
</boundaryScanner>
最后必须在查询语句里设置useFastVectorHighlighter
query.setParam("hl.useFastVectorHighlighter", "true");