Changeset 12429
- Timestamp:
- 2006-08-10T16:59:21+12:00 (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java
r12418 r12429 9 9 10 10 11 import java.io.BufferedReader; 12 import java.io.InputStreamReader; 13 import java.io.IOException; 14 import java.util.Collections; 15 import java.util.HashMap; 16 import java.util.HashSet; 17 import java.util.Iterator; 18 import java.util.Set; 11 import java.io.*; 12 import java.util.*; 19 13 20 14 import org.apache.lucene.analysis.Analyzer; … … 32 26 import org.apache.lucene.search.IndexSearcher; 33 27 import org.apache.lucene.search.Query; 28 import org.apache.lucene.search.QueryFilter; 34 29 import org.apache.lucene.search.RangeFilter; 35 30 import org.apache.lucene.search.Searcher; … … 50 45 IndexReader reader = ((IndexSearcher) searcher).getIndexReader(); 51 46 47 // Create one query parser with the standard set of stop words, and one with none 48 QueryParser query_parser = new QueryParser("TX", new StandardAnalyzer()); 49 QueryParser query_parser_no_stop_words = new QueryParser("TX", new StandardAnalyzer(new String[] { })); 50 52 51 Sort sorter = new Sort(); 53 Filter filter = null;52 QueryFilter filter = null; 54 53 boolean fuzzy = false; 55 54 … … 67 66 { 68 67 i++; 69 filter = parseFilterString(args[i]); 68 try { 69 filter = new QueryFilter(query_parser.parse(args[i])); 70 } 71 catch (ParseException exception) { 72 exception.printStackTrace(); 73 } 70 74 } 71 75 if (args[i].equals("-dco")) … … 79 83 } 80 84 } 81 82 // Create one query parser with the standard set of stop words, and one with none83 QueryParser query_parser = new QueryParser("TX", new StandardAnalyzer());84 QueryParser query_parser_no_stop_words = new QueryParser("TX", new StandardAnalyzer(new String[] { }));85 85 86 86 // Lucene does "OR" queries by default; do an "AND" query if specified … … 227 227 228 228 229 private static Filter parseFilterString(String filter_string)230 {231 // Range filters232 if (filter_string.matches("(.*):[\\{\\[](.+) TO (.+)[\\}\\]]")) {233 String field_name = filter_string.substring(0, filter_string.indexOf(":"));234 boolean include_lower = (filter_string.charAt(filter_string.indexOf(":") + 1) == '[');235 String lower_term = filter_string.substring(filter_string.indexOf(":") + 2, filter_string.indexOf(" TO "));236 String upper_term = filter_string.substring(filter_string.indexOf(" TO ") + " TO ".length(), filter_string.length() - 1);237 boolean include_upper = (filter_string.charAt(filter_string.length() - 1) == ']');238 return new RangeFilter(field_name, lower_term, upper_term, include_lower, include_upper);239 }240 241 System.err.println("Error: Could not understand filter string \"" + filter_string + "\"");242 return null;243 }244 245 246 229 private static Query parseQuery(IndexReader reader, QueryParser query_parser, String query_string, boolean fuzzy) 247 230 throws java.io.IOException, org.apache.lucene.queryParser.ParseException -
trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java
r12418 r12429 9 9 10 10 11 import java.io.BufferedReader; 12 import java.io.InputStreamReader; 13 import java.io.IOException; 14 import java.util.Collections; 15 import java.util.HashMap; 16 import java.util.HashSet; 17 import java.util.Iterator; 18 import java.util.Set; 11 import java.io.*; 12 import java.util.*; 19 13 20 14 import org.apache.lucene.analysis.Analyzer; … … 32 26 import org.apache.lucene.search.IndexSearcher; 33 27 import org.apache.lucene.search.Query; 28 import org.apache.lucene.search.QueryFilter; 34 29 import org.apache.lucene.search.RangeFilter; 35 30 import org.apache.lucene.search.Searcher; … … 50 45 IndexReader reader = ((IndexSearcher) searcher).getIndexReader(); 51 46 47 // Create one query parser with the standard set of stop words, and one with none 48 QueryParser query_parser = new QueryParser("TX", new StandardAnalyzer()); 49 QueryParser query_parser_no_stop_words = new QueryParser("TX", new StandardAnalyzer(new String[] { })); 50 52 51 Sort sorter = new Sort(); 53 Filter filter = null;52 QueryFilter filter = null; 54 53 boolean fuzzy = false; 55 54 … … 67 66 { 68 67 i++; 69 filter = parseFilterString(args[i]); 68 try { 69 filter = new QueryFilter(query_parser.parse(args[i])); 70 } 71 catch (ParseException exception) { 72 exception.printStackTrace(); 73 } 70 74 } 71 75 if (args[i].equals("-dco")) … … 79 83 } 80 84 } 81 82 // Create one query parser with the standard set of stop words, and one with none83 QueryParser query_parser = new QueryParser("TX", new StandardAnalyzer());84 QueryParser query_parser_no_stop_words = new QueryParser("TX", new StandardAnalyzer(new String[] { }));85 85 86 86 // Lucene does "OR" queries by default; do an "AND" query if specified … … 227 227 228 228 229 private static Filter parseFilterString(String filter_string)230 {231 // Range filters232 if (filter_string.matches("(.*):[\\{\\[](.+) TO (.+)[\\}\\]]")) {233 String field_name = filter_string.substring(0, filter_string.indexOf(":"));234 boolean include_lower = (filter_string.charAt(filter_string.indexOf(":") + 1) == '[');235 String lower_term = filter_string.substring(filter_string.indexOf(":") + 2, filter_string.indexOf(" TO "));236 String upper_term = filter_string.substring(filter_string.indexOf(" TO ") + " TO ".length(), filter_string.length() - 1);237 boolean include_upper = (filter_string.charAt(filter_string.length() - 1) == ']');238 return new RangeFilter(field_name, lower_term, upper_term, include_lower, include_upper);239 }240 241 System.err.println("Error: Could not understand filter string \"" + filter_string + "\"");242 return null;243 }244 245 246 229 private static Query parseQuery(IndexReader reader, QueryParser query_parser, String query_string, boolean fuzzy) 247 230 throws java.io.IOException, org.apache.lucene.queryParser.ParseException
Note:
See TracChangeset
for help on using the changeset viewer.