10 #include "clucene/document/document.h" |
10 #include "clucene/document/document.h" |
11 #include "clucene/index/indexreader.h" |
11 #include "clucene/index/indexreader.h" |
12 #include "filter.h" |
12 #include "filter.h" |
13 #include "clucene/search/searchheader.h" |
13 #include "clucene/search/searchheader.h" |
14 //#ifdef USE_HIGHLIGHTER |
14 //#ifdef USE_HIGHLIGHTER |
15 //#include "CLucene/highlighter/QueryTermExtractor.h" |
15 |
16 //#include "CLucene/highlighter/QueryScorer.h" |
16 #include "CLucene/highlighter/QueryTermExtractor.h" |
17 //#include "CLucene/highlighter/Highlighter.h" |
17 #include "CLucene/highlighter/QueryScorer.h" |
18 //#include "CLucene/highlighter/SimpleHTMLFormatter.h" |
18 #include "CLucene/highlighter/Highlighter.h" |
19 //#include "CLucene/analysis/standard/StandardAnalyzer.h" |
19 #include "CLucene/highlighter/SimpleHTMLFormatter.h" |
|
20 #include "CLucene/analysis/standard/StandardAnalyzer.h" |
|
21 #include "clucene/search/prefixquery.h" |
|
22 |
|
23 // internal libs |
|
24 #include "cpixparsetools.h" |
|
25 |
20 //#endif |
26 //#endif |
21 |
27 |
22 CL_NS_USE(document) |
28 CL_NS_USE(document) |
23 CL_NS_USE(util) |
29 CL_NS_USE(util) |
24 CL_NS_USE(index) |
30 CL_NS_USE(index) |
48 |
54 |
49 |
55 |
50 Hits::Hits(Searcher* s, Query* q, Filter* f, const Sort* _sort): |
56 Hits::Hits(Searcher* s, Query* q, Filter* f, const Sort* _sort): |
51 query(q), searcher(s), filter(f), sort(_sort) |
57 query(q), searcher(s), filter(f), sort(_sort) |
52 //#ifdef USE_HIGHLIGHTER |
58 //#ifdef USE_HIGHLIGHTER |
53 // , hl_frag(20) |
59 , hl_frag(20) |
54 //#endif |
60 //#endif |
55 { |
61 { |
56 //Func - Constructor |
62 //Func - Constructor |
57 //Pre - s contains a valid reference to a searcher s |
63 //Pre - s contains a valid reference to a searcher s |
58 // q contains a valid reference to a Query |
64 // q contains a valid reference to a Query |
92 |
98 |
93 if (hitDoc->doc == NULL){ |
99 if (hitDoc->doc == NULL){ |
94 hitDoc->doc = _CLNEW Document; |
100 hitDoc->doc = _CLNEW Document; |
95 searcher->doc(hitDoc->id, hitDoc->doc); // cache miss: read document |
101 searcher->doc(hitDoc->id, hitDoc->doc); // cache miss: read document |
96 //#ifdef USE_HIGHLIGHTER |
102 //#ifdef USE_HIGHLIGHTER |
97 // CL_NS(document)::Document* document = hitDoc->doc; |
103 |
98 // |
104 CL_NS(document)::Document* document = hitDoc->doc; |
99 // const TCHAR* text = document->get(LCPIX_EXCERPT_FIELD); |
105 |
100 // |
106 TCHAR* result = NULL; |
101 // if(text) |
107 Query* rwquery[2]; |
102 // { |
108 searcher->getrewritten(hitDoc->id, query, rwquery); |
103 // Query* rwquery = searcher->getrewritten(hitDoc->id, query); |
109 |
104 // |
110 const TCHAR* firstlnHLtxt = document->get(LCPIX_HL_EXCERPT_FIELD); |
105 // TCHAR * str = rwquery->toString(); |
111 |
106 // |
112 if(firstlnHLtxt && rwquery[1]) |
107 // CL_NS2(search,highlight)::QueryScorer hl_scorer(rwquery); |
113 { |
108 // |
114 CL_NS2(search,highlight)::QueryScorer hl_scorer(rwquery[1]); |
109 // CL_NS2(search,highlight)::Highlighter highlighter(&hl_formatter, &hl_scorer); |
115 |
110 // |
116 CL_NS2(search,highlight)::Highlighter highlighter(&hl_formatter, &hl_scorer); |
111 // highlighter.setTextFragmenter(&hl_frag); |
117 |
112 // |
118 highlighter.setTextFragmenter(&hl_frag); |
113 // wstring hlText; |
119 |
114 // |
120 wstring hlText; |
115 // StringReader strreader(text); |
121 |
116 // |
122 StringReader strreader(firstlnHLtxt); |
117 // lucene::analysis::TokenStream * tokenStream = hl_analyzer.tokenStream(LCPIX_EXCERPT_FIELD, &strreader); |
123 |
118 // |
124 lucene::analysis::TokenStream * tokenStream = hl_analyzer.tokenStream(LCPIX_HL_EXCERPT_FIELD, &strreader); |
119 // TCHAR* result = highlighter.getBestFragments(tokenStream, text, 2,L"..."); |
125 |
120 // |
126 result = highlighter.getBestFragments(tokenStream, firstlnHLtxt, 2,L"..."); |
121 // if (result != NULL) |
127 |
122 // { |
128 if (result != NULL && *((int*)result) != 0x00) |
123 // hlText.append(result); |
129 { |
124 // |
130 hlText.append(result); |
125 // document->removeField( LCPIX_EXCERPT_FIELD ); |
131 |
126 // |
132 document->removeField( LCPIX_HL_EXCERPT_FIELD ); |
127 // document->add(*_CLNEW Field(LCPIX_EXCERPT_FIELD, |
133 |
128 // hlText.c_str(), lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO)); |
134 document->add(*_CLNEW Field(LCPIX_HL_EXCERPT_FIELD, |
129 // } |
135 hlText.c_str(), lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO)); |
130 // } |
136 } |
|
137 |
|
138 } |
|
139 |
|
140 const TCHAR* text = document->get(LCPIX_EXCERPT_FIELD); |
|
141 |
|
142 if(text && rwquery[1]) |
|
143 { |
|
144 CL_NS2(search,highlight)::QueryScorer hl_scorer(rwquery[1]); |
|
145 |
|
146 CL_NS2(search,highlight)::Highlighter highlighter(&hl_formatter, &hl_scorer); |
|
147 |
|
148 highlighter.setTextFragmenter(&hl_frag); |
|
149 |
|
150 wstring hlText; |
|
151 |
|
152 StringReader strreader(text); |
|
153 |
|
154 lucene::analysis::TokenStream * tokenStream = hl_analyzer.tokenStream(LCPIX_EXCERPT_FIELD, &strreader); |
|
155 |
|
156 result = highlighter.getBestFragments(tokenStream, text, 2,L"..."); |
|
157 |
|
158 if (result != NULL && *((int*)result) != 0x00) |
|
159 { |
|
160 hlText.append(result); |
|
161 |
|
162 document->removeField( LCPIX_EXCERPT_FIELD ); |
|
163 |
|
164 document->add(*_CLNEW Field(LCPIX_EXCERPT_FIELD, |
|
165 hlText.c_str(), lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO)); |
|
166 } |
|
167 } |
131 //#endif |
168 //#endif |
132 } |
169 } |
133 |
170 |
134 return *hitDoc->doc; |
171 return *hitDoc->doc; |
135 } |
172 } |