|
1 /** |
|
2 * Copyright 2002-2004 The Apache Software Foundation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 #ifndef _lucene_search_highlight_querytermextractor_ |
|
17 #define _lucene_search_highlight_querytermextractor_ |
|
18 |
|
19 #if defined(_LUCENE_PRAGMA_ONCE) |
|
20 # pragma once |
|
21 #endif |
|
22 |
|
23 #include "CLucene/util/VoidList.h" |
|
24 #include "CLucene/search/SearchHeader.h" |
|
25 #include "CLucene/index/IndexReader.h" |
|
26 #include "CLucene/search/BooleanQuery.h" |
|
27 #include "CLucene/search/PhraseQuery.h" |
|
28 #include "CLucene/search/TermQuery.h" |
|
29 #include "CLucene/highlighter/WeightedTerm.h" |
|
30 |
|
31 CL_NS_DEF2(search,highlight) |
|
32 |
|
33 /** |
|
34 * Utility class used to extract the terms used in a query, plus any weights. |
|
35 * This class will not find terms for MultiTermQuery, RangeQuery and PrefixQuery classes |
|
36 * so the caller must pass a rewritten query (see Query.rewrite) to obtain a list of |
|
37 * expanded terms. |
|
38 * |
|
39 */ |
|
40 class QueryTermExtractor |
|
41 { |
|
42 QueryTermExtractor(){ |
|
43 } |
|
44 public: |
|
45 |
|
46 /** |
|
47 * Extracts all terms texts of a given Query into an array of WeightedTerms |
|
48 * |
|
49 * @param query Query to extract term texts from |
|
50 * @return an array of the terms used in a query, plus their weights. |
|
51 */ |
|
52 static WeightedTerm** getTerms(const Query *query); |
|
53 |
|
54 /** |
|
55 * Extracts all terms texts of a given Query into an array of WeightedTerms |
|
56 * |
|
57 * @param query Query to extract term texts from |
|
58 * @param reader used to compute IDF which can be used to a) score selected fragments better |
|
59 * b) use graded highlights eg chaning intensity of font color |
|
60 * @param fieldName the field on which Inverse Document Frequency (IDF) calculations are based |
|
61 * @return an array of the terms used in a query, plus their weights. |
|
62 */ |
|
63 static WeightedTerm** getIdfWeightedTerms(const Query* query, CL_NS(index)::IndexReader* reader, const TCHAR* fieldName); |
|
64 |
|
65 /** |
|
66 * Extracts all terms texts of a given Query into an array of WeightedTerms |
|
67 * |
|
68 * @param query Query to extract term texts from |
|
69 * @param prohibited <code>true</code> to extract "prohibited" terms, too |
|
70 * @return an array of the terms used in a query, plus their weights.Memory owned by the caller |
|
71 */ |
|
72 static WeightedTerm** getTerms(const Query * query, bool prohibited); |
|
73 |
|
74 |
|
75 static void getTerms(const Query * query, WeightedTermList* terms,bool prohibited); |
|
76 static void getTermsFromBooleanQuery(const BooleanQuery * query, WeightedTermList* terms, bool prohibited); |
|
77 static void getTermsFromPhraseQuery(const PhraseQuery * query, WeightedTermList* terms); |
|
78 static void getTermsFromTermQuery(const TermQuery * query, WeightedTermList* terms); |
|
79 // static void getTermsFromSpanNearQuery(SpanNearQuery* query, WeightedTermList* terms); |
|
80 }; |
|
81 |
|
82 CL_NS_END2 |
|
83 |
|
84 |
|
85 |
|
86 #endif |