Changeset 12993
- Timestamp:
- 2006-10-04T11:13:43+13:00 (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java
r12991 r12993 140 140 throws IOException 141 141 { 142 System.out.println("<ResultSet>"); 143 System.out.println(" <QueryString>" + xmlSafe(query_string) + "</QueryString>"); 142 StringBuffer query_results_xml = new StringBuffer(); 143 144 query_results_xml.append("<ResultSet>\n"); 145 query_results_xml.append(" <QueryString>" + xmlSafe(query_string) + "</QueryString>\n"); 144 146 if (filter != null) { 145 System.out.println(" <FilterString>" + filter.toString() + "</FilterString>");147 query_results_xml.append(" <FilterString>" + filter.toString() + "</FilterString>\n"); 146 148 } 147 149 … … 157 159 query.extractTerms(terms); 158 160 Iterator term_iterator = terms.iterator(); 159 System.out.println(" <QueryTermsInfo num=\"" + terms.size() + "\"/>");161 query_results_xml.append(" <QueryTermsInfo num=\"" + terms.size() + "\"/>\n"); 160 162 while (term_iterator.hasNext()) { 161 163 Term term = (Term) term_iterator.next(); … … 171 173 // something like this: 172 174 // if (term.field().equals(TEXTFIELD)) 173 System.out.println(" <Term value=\"" + term.text() + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />");175 query_results_xml.append(" <Term value=\"" + term.text() + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />\n"); 174 176 } 175 177 … … 181 183 Term term = (Term) terms_including_stop_words_iter.next(); 182 184 if (!terms.contains(term)) { 183 System.out.println(" <StopWord value=\"" + term.text() + "\"/>");185 query_results_xml.append(" <StopWord value=\"" + term.text() + "\"/>\n"); 184 186 } 185 187 } … … 189 191 // Perform the query (filter and sorter may be null) 190 192 Hits hits = searcher.search(query, filter, sorter); 191 System.out.println(" <MatchingDocsInfo num=\"" + hits.length() + "\"/>");193 query_results_xml.append(" <MatchingDocsInfo num=\"" + hits.length() + "\"/>\n"); 192 194 193 195 // Output the matching documents 194 System.out.println(" <StartResults num=\"" + start_results + "\" />");195 System.out.println(" <EndsResults num=\"" + hits.length() + "\" />");196 query_results_xml.append(" <StartResults num=\"" + start_results + "\" />\n"); 197 query_results_xml.append(" <EndsResults num=\"" + hits.length() + "\" />\n"); 196 198 for (int i = start_results; i <= hits.length(); i++) { 197 199 Document doc = hits.doc(i - 1); 198 System.out.println(" <Match id=\"" + doc.get("nodeID") + "\" />");200 query_results_xml.append(" <Match id=\"" + doc.get("nodeID") + "\" />\n"); 199 201 } 200 202 } … … 204 206 // Perform the query (filter may be null) 205 207 TopFieldDocs hits = searcher.search(query, filter, end_results, sorter); 206 System.out.println(" <MatchingDocsInfo num=\"" + hits.totalHits + "\"/>");208 query_results_xml.append(" <MatchingDocsInfo num=\"" + hits.totalHits + "\"/>\n"); 207 209 208 210 // Output the matching documents 209 System.out.println(" <StartResults num=\"" + start_results + "\" />");210 System.out.println(" <EndsResults num=\"" + end_results + "\" />");211 query_results_xml.append(" <StartResults num=\"" + start_results + "\" />\n"); 212 query_results_xml.append(" <EndsResults num=\"" + end_results + "\" />\n"); 211 213 for (int i = start_results; (i <= hits.scoreDocs.length && i <= end_results); i++) { 212 214 Document doc = reader.document(hits.scoreDocs[i - 1].doc); 213 System.out.println(" <Match id=\"" + doc.get("nodeID") + "\" />");215 query_results_xml.append(" <Match id=\"" + doc.get("nodeID") + "\" />\n"); 214 216 } 215 217 } 216 218 } 217 219 catch (ParseException parse_exception) { 218 System.out.println(" <Error type=\"PARSE_EXCEPTION\"/>");220 query_results_xml.append(" <Error type=\"PARSE_EXCEPTION\"/>\n"); 219 221 } 220 222 catch (TooManyClauses too_many_clauses_exception) { 221 System.out.println(" <Error type=\"TOO_MANY_CLAUSES\"/>"); 222 } 223 224 System.out.println("</ResultSet>"); 223 query_results_xml.append(" <Error type=\"TOO_MANY_CLAUSES\"/>\n"); 224 } 225 226 query_results_xml.append("</ResultSet>\n"); 227 228 System.out.print(query_results_xml); 225 229 } 226 230 -
trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java
r12991 r12993 140 140 throws IOException 141 141 { 142 System.out.println("<ResultSet>"); 143 System.out.println(" <QueryString>" + xmlSafe(query_string) + "</QueryString>"); 142 StringBuffer query_results_xml = new StringBuffer(); 143 144 query_results_xml.append("<ResultSet>\n"); 145 query_results_xml.append(" <QueryString>" + xmlSafe(query_string) + "</QueryString>\n"); 144 146 if (filter != null) { 145 System.out.println(" <FilterString>" + filter.toString() + "</FilterString>");147 query_results_xml.append(" <FilterString>" + filter.toString() + "</FilterString>\n"); 146 148 } 147 149 … … 157 159 query.extractTerms(terms); 158 160 Iterator term_iterator = terms.iterator(); 159 System.out.println(" <QueryTermsInfo num=\"" + terms.size() + "\"/>");161 query_results_xml.append(" <QueryTermsInfo num=\"" + terms.size() + "\"/>\n"); 160 162 while (term_iterator.hasNext()) { 161 163 Term term = (Term) term_iterator.next(); … … 171 173 // something like this: 172 174 // if (term.field().equals(TEXTFIELD)) 173 System.out.println(" <Term value=\"" + term.text() + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />");175 query_results_xml.append(" <Term value=\"" + term.text() + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />\n"); 174 176 } 175 177 … … 181 183 Term term = (Term) terms_including_stop_words_iter.next(); 182 184 if (!terms.contains(term)) { 183 System.out.println(" <StopWord value=\"" + term.text() + "\"/>");185 query_results_xml.append(" <StopWord value=\"" + term.text() + "\"/>\n"); 184 186 } 185 187 } … … 189 191 // Perform the query (filter and sorter may be null) 190 192 Hits hits = searcher.search(query, filter, sorter); 191 System.out.println(" <MatchingDocsInfo num=\"" + hits.length() + "\"/>");193 query_results_xml.append(" <MatchingDocsInfo num=\"" + hits.length() + "\"/>\n"); 192 194 193 195 // Output the matching documents 194 System.out.println(" <StartResults num=\"" + start_results + "\" />");195 System.out.println(" <EndsResults num=\"" + hits.length() + "\" />");196 query_results_xml.append(" <StartResults num=\"" + start_results + "\" />\n"); 197 query_results_xml.append(" <EndsResults num=\"" + hits.length() + "\" />\n"); 196 198 for (int i = start_results; i <= hits.length(); i++) { 197 199 Document doc = hits.doc(i - 1); 198 System.out.println(" <Match id=\"" + doc.get("nodeID") + "\" />");200 query_results_xml.append(" <Match id=\"" + doc.get("nodeID") + "\" />\n"); 199 201 } 200 202 } … … 204 206 // Perform the query (filter may be null) 205 207 TopFieldDocs hits = searcher.search(query, filter, end_results, sorter); 206 System.out.println(" <MatchingDocsInfo num=\"" + hits.totalHits + "\"/>");208 query_results_xml.append(" <MatchingDocsInfo num=\"" + hits.totalHits + "\"/>\n"); 207 209 208 210 // Output the matching documents 209 System.out.println(" <StartResults num=\"" + start_results + "\" />");210 System.out.println(" <EndsResults num=\"" + end_results + "\" />");211 query_results_xml.append(" <StartResults num=\"" + start_results + "\" />\n"); 212 query_results_xml.append(" <EndsResults num=\"" + end_results + "\" />\n"); 211 213 for (int i = start_results; (i <= hits.scoreDocs.length && i <= end_results); i++) { 212 214 Document doc = reader.document(hits.scoreDocs[i - 1].doc); 213 System.out.println(" <Match id=\"" + doc.get("nodeID") + "\" />");215 query_results_xml.append(" <Match id=\"" + doc.get("nodeID") + "\" />\n"); 214 216 } 215 217 } 216 218 } 217 219 catch (ParseException parse_exception) { 218 System.out.println(" <Error type=\"PARSE_EXCEPTION\"/>");220 query_results_xml.append(" <Error type=\"PARSE_EXCEPTION\"/>\n"); 219 221 } 220 222 catch (TooManyClauses too_many_clauses_exception) { 221 System.out.println(" <Error type=\"TOO_MANY_CLAUSES\"/>"); 222 } 223 224 System.out.println("</ResultSet>"); 223 query_results_xml.append(" <Error type=\"TOO_MANY_CLAUSES\"/>\n"); 224 } 225 226 query_results_xml.append("</ResultSet>\n"); 227 228 System.out.print(query_results_xml); 225 229 } 226 230
Note:
See TracChangeset
for help on using the changeset viewer.