Changeset 12980 for trunk/indexers
- Timestamp:
- 2006-10-03T15:35:04+13:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java
r12976 r12980 31 31 import org.apache.lucene.search.RangeFilter; 32 32 import org.apache.lucene.search.Searcher; 33 import org.apache.lucene.search.ScoreDoc; 33 34 import org.apache.lucene.search.Sort; 35 import org.apache.lucene.search.TopFieldDocs; 34 36 35 37 … … 57 59 QueryParser query_parser_no_stop_words = new QueryParser(TEXTFIELD, new StandardAnalyzer(new String[] { })); 58 60 59 Sort sorter = n ull;61 Sort sorter = new Sort(); 60 62 Filter filter = null; 61 63 String fuzziness = null; … … 63 65 // Paging 64 66 int start_results = 1; 65 int end_results = -1;67 int end_results = Integer.MAX_VALUE; 66 68 67 69 // New code to allow the default conjunction operator to be … … 157 159 } 158 160 159 // Perform the query (filter and sorter may be null) 160 Hits hits = searcher.search(query, filter, sorter); 161 162 // Do we need to use a hit iterator to get sorted results? 163 System.out.println(" <MatchingDocsInfo num=\"" + hits.length() + "\"/>"); 164 System.out.println(" <StartResults num=\"" + start_results + "\" />"); 165 System.out.println(" <EndsResults num=\"" + end_results + "\" />"); 166 167 int counter = 1; 168 Iterator hit_iter = hits.iterator(); 169 while (hit_iter.hasNext()) { 170 Hit hit = (Hit) hit_iter.next(); 171 Document doc = hit.getDocument(); 172 173 // May not be paging results 174 if (start_results == 1 && end_results == -1) { 175 String node_id = doc.get("nodeID"); 176 System.out.println(" <Match id=\"" + node_id + "\" />"); 161 // Simple case for getting all the matching documents 162 if (end_results == Integer.MAX_VALUE) { 163 // Perform the query (filter and sorter may be null) 164 Hits hits = searcher.search(query, filter, sorter); 165 System.out.println(" <MatchingDocsInfo num=\"" + hits.length() + "\"/>"); 166 167 // Output the matching documents 168 System.out.println(" <StartResults num=\"" + start_results + "\" />"); 169 System.out.println(" <EndsResults num=\"" + hits.length() + "\" />"); 170 for (int i = start_results; i <= hits.length(); i++) { 171 Document doc = hits.doc(i - 1); 172 System.out.println(" <Match id=\"" + doc.get("nodeID") + "\" />"); 177 173 } 178 // Otherwise skip up until page offset 179 else if (start_results <= counter && counter <= end_results) { 180 String node_id = doc.get("nodeID"); 181 System.out.println(" <Match id=\"" + node_id + "\" />"); 174 } 175 176 // Slightly more complicated case for returning a subset of the matching documents 177 else { 178 // Perform the query (filter may be null) 179 TopFieldDocs hits = searcher.search(query, filter, end_results, sorter); 180 System.out.println(" <MatchingDocsInfo num=\"" + hits.totalHits + "\"/>"); 181 182 // Output the matching documents 183 System.out.println(" <StartResults num=\"" + start_results + "\" />"); 184 System.out.println(" <EndsResults num=\"" + end_results + "\" />"); 185 for (int i = start_results; (i <= hits.scoreDocs.length && i <= end_results); i++) { 186 Document doc = reader.document(hits.scoreDocs[i - 1].doc); 187 System.out.println(" <Match id=\"" + doc.get("nodeID") + "\" />"); 182 188 } 183 // And skip all the rest184 185 ++counter;186 189 } 187 190 }
Note:
See TracChangeset
for help on using the changeset viewer.