pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / highlighter / src / java / org / apache / lucene / search / vectorhighlight / package.html
1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2 <!--
3  Licensed to the Apache Software Foundation (ASF) under one or more
4  contributor license agreements.  See the NOTICE file distributed with
5  this work for additional information regarding copyright ownership.
6  The ASF licenses this file to You under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with
8  the License.  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 -->
18 <html>
19 <body>
20 This is an another highlighter implementation.
21
22 <h2>Features</h2>
23 <ul>
24 <li>fast for large docs</li>
25 <li>support N-gram fields</li>
26 <li>support phrase-unit highlighting with slops</li>
27 <li>support multi-term (includes wildcard, range, regexp, etc) queries</li>
28 <li>need Java 1.5</li>
29 <li>highlight fields need to be TermVector.WITH_POSITIONS_OFFSETS</li>
30 <li>take into account query boost to score fragments</li>
31 <li>support colored highlight tags</li>
32 <li>pluggable FragListBuilder</li>
33 <li>pluggable FragmentsBuilder</li>
34 </ul>
35
36 <h2>Algorithm</h2>
37 <p>To explain the algorithm, let's use the following sample text
38  (to be highlighted) and user query:</p>
39
40 <table border=1>
41 <tr>
42 <td><b>Sample Text</b></td>
43 <td>Lucene is a search engine library.</td>
44 </tr>
45 <tr>
46 <td><b>User Query</b></td>
47 <td>Lucene^2 OR "search library"~1</td>
48 </tr>
49 </table>
50
51 <p>The user query is a BooleanQuery that consists of TermQuery("Lucene") 
52 with boost of 2 and PhraseQuery("search library") with slop of 1.</p>
53 <p>For your convenience, here is the offsets and positions info of the 
54 sample text.</p>
55
56 <pre>
57 +--------+-----------------------------------+
58 |        |          1111111111222222222233333|
59 |  offset|01234567890123456789012345678901234|
60 +--------+-----------------------------------+
61 |document|Lucene is a search engine library. |
62 +--------*-----------------------------------+
63 |position|0      1  2 3      4      5        |
64 +--------*-----------------------------------+
65 </pre>
66
67 <h3>Step 1.</h3>
68 <p>In Step 1, Fast Vector Highlighter generates {@link org.apache.lucene.search.vectorhighlight.FieldQuery.QueryPhraseMap} from the user query.
69 <code>QueryPhraseMap</code> consists of the following members:</p>
70 <pre class="prettyprint">
71 public class QueryPhraseMap {
72   boolean terminal;
73   int slop;   // valid if terminal == true and phraseHighlight == true
74   float boost;  // valid if terminal == true
75   Map&lt;String, QueryPhraseMap&gt; subMap;
76
77 </pre>
78 <p><code>QueryPhraseMap</code> has subMap. The key of the subMap is a term 
79 text in the user query and the value is a subsequent <code>QueryPhraseMap</code>.
80 If the query is a term (not phrase), then the subsequent <code>QueryPhraseMap</code>
81 is marked as terminal. If the query is a phrase, then the subsequent <code>QueryPhraseMap</code>
82 is not a terminal and it has the next term text in the phrase.</p>
83
84 <p>From the sample user query, the following <code>QueryPhraseMap</code> 
85 will be generated:</p>
86 <pre>
87    QueryPhraseMap
88 +--------+-+  +-------+-+
89 |"Lucene"|o+->|boost=2|*|  * : terminal
90 +--------+-+  +-------+-+
91
92 +--------+-+  +---------+-+  +-------+------+-+
93 |"search"|o+->|"library"|o+->|boost=1|slop=1|*|
94 +--------+-+  +---------+-+  +-------+------+-+
95 </pre>
96
97 <h3>Step 2.</h3>
98 <p>In Step 2, Fast Vector Highlighter generates {@link org.apache.lucene.search.vectorhighlight.FieldTermStack}. Fast Vector Highlighter uses {@link org.apache.lucene.index.TermFreqVector} data
99 (must be stored {@link org.apache.lucene.document.Field.TermVector#WITH_POSITIONS_OFFSETS})
100 to generate it. <code>FieldTermStack</code> keeps the terms in the user query.
101 Therefore, in this sample case, Fast Vector Highlighter generates the following <code>FieldTermStack</code>:</p>
102 <pre>
103    FieldTermStack
104 +------------------+
105 |"Lucene"(0,6,0)   |
106 +------------------+
107 |"search"(12,18,3) |
108 +------------------+
109 |"library"(26,33,5)|
110 +------------------+
111 where : "termText"(startOffset,endOffset,position)
112 </pre>
113 <h3>Step 3.</h3>
114 <p>In Step 3, Fast Vector Highlighter generates {@link org.apache.lucene.search.vectorhighlight.FieldPhraseList}
115 by reference to <code>QueryPhraseMap</code> and <code>FieldTermStack</code>.</p>
116 <pre>
117    FieldPhraseList
118 +----------------+-----------------+---+
119 |"Lucene"        |[(0,6)]          |w=2|
120 +----------------+-----------------+---+
121 |"search library"|[(12,18),(26,33)]|w=1|
122 +----------------+-----------------+---+
123 </pre>
124 <p>The type of each entry is <code>WeightedPhraseInfo</code> that consists of
125 an array of terms offsets and weight. The weight (Fast Vector Highlighter uses query boost to
126 calculate the weight) will be taken into account when Fast Vector Highlighter creates
127 {@link org.apache.lucene.search.vectorhighlight.FieldFragList} in the next step.</p>
128 <h3>Step 4.</h3>
129 <p>In Step 4, Fast Vector Highlighter creates <code>FieldFragList</code> by reference to
130 <code>FieldPhraseList</code>. In this sample case, the following
131 <code>FieldFragList</code> will be generated:</p>
132 <pre>
133    FieldFragList
134 +---------------------------------+
135 |"Lucene"[(0,6)]                  |
136 |"search library"[(12,18),(26,33)]|
137 |totalBoost=3                     |
138 +---------------------------------+
139 </pre>
140 <h3>Step 5.</h3>
141 <p>In Step 5, by using <code>FieldFragList</code> and the field stored data,
142 Fast Vector Highlighter creates highlighted snippets!</p>
143 </body>
144 </html>