Mailing List Archive

cvs commit: jakarta-lucene/src/java/org/apache/lucene/queryParser QueryParser.jj
scottganyo 01/09/25 14:54:18

Modified: src/java/org/apache/lucene/queryParser QueryParser.jj
Log:
Added support for RangeQuery. The syntax is expressed as follows:
inclusive range = field:[lowerTerm-upperTerm]
exclusive range = field:{lowerTerm-upperTerm}

Revision Changes Path
1.2 +45 -8 jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj

Index: QueryParser.jj
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QueryParser.jj 2001/09/18 16:29:55 1.1
+++ QueryParser.jj 2001/09/25 21:54:18 1.2
@@ -59,13 +59,13 @@

PARSER_BEGIN(QueryParser)

-package org.apache.lucene.queryParser;
+package com.lucene.queryParser;

import java.util.Vector;
import java.io.*;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.analysis.*;
-import org.apache.lucene.search.*;
+import com.lucene.index.Term;
+import com.lucene.analysis.*;
+import com.lucene.search.*;

/**
* This class is generated by JavaCC. The only method that clients should need
@@ -170,7 +170,7 @@

TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));
Vector v = new Vector();
- org.apache.lucene.analysis.Token t;
+ com.lucene.analysis.Token t;

while (true) {
try {
@@ -197,9 +197,38 @@
}
}

+ private Query getRangeQuery(String field, Analyzer analyzer, String queryText, boolean inclusive)
+ {
+ // Use the analyzer to get all the tokens. There should be 1 or 2.
+ TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));
+ Term[] terms = new Term[2];
+ com.lucene.analysis.Token t;
+
+ for (int i = 0; i < 2; i++)
+ {
+ try
+ {
+ t = source.next();
+ }
+ catch (IOException e)
+ {
+ t = null;
+ }
+ if (t != null)
+ {
+ String text = t.termText();
+ if (!text.equalsIgnoreCase("NULL"))
+ {
+ terms[i] = new Term(field, text);
+ }
+ }
+ }
+ return new RangeQuery(terms[0], terms[1], inclusive);
+ }
+
public static void main(String[] args) throws Exception {
QueryParser qp = new QueryParser("field",
- new org.apache.lucene.analysis.SimpleAnalyzer());
+ new com.lucene.analysis.SimpleAnalyzer());
Query q = qp.parse(args[0]);
System.out.println(q.toString("field"));
}
@@ -245,10 +274,12 @@
| <QUOTED: "\"" (~["\""])+ "\"">
| <NUMBER: (<_NUM_CHAR>)+ "." (<_NUM_CHAR>)+ >
| <TERM: <_IDENTIFIER_CHAR>
- ( ~[."\"", " ", "\t", "(", ")", ":", "&", "|", "^", "*", "?", "~" ] )* >
+ ( ~[."\"", " ", "\t", "(", ")", ":", "&", "|", "^", "*", "?", "~", "{", "}", "[", "]" ] )* >
| <FUZZY: "~" >
| <WILDTERM: <_IDENTIFIER_CHAR>
- ( ~[."\"", " ", "\t", "(", ")", ":", "&", "|", "^", "~" ] )* <_IDENTIFIER_CHAR>>
+ ( ~[."\"", " ", "\t", "(", ")", ":", "&", "|", "^", "~", "{", "}", "[", "]" ] )* <_IDENTIFIER_CHAR>>
+| <RANGEIN: "[" (~["]"])+ "]">
+| <RANGEEX: "{" (~["}"])+ "}">
}

<DEFAULT> SKIP : {
@@ -327,6 +358,7 @@
boolean prefix = false;
boolean wildcard = false;
boolean fuzzy = false;
+ boolean rangein = false;
Query q;
}
{
@@ -340,6 +372,11 @@
q = new FuzzyQuery(new Term(field, term.image));
else
q = getFieldQuery(field, analyzer, term.image); }
+ | (term=<RANGEIN>{rangein=true;}|term=<RANGEEX>)
+ {
+ q = getRangeQuery(field, analyzer,
+ term.image.substring(1, term.image.length()-1), rangein);
+ }
| term=<QUOTED>
{ q = getFieldQuery(field, analyzer,
term.image.substring(1, term.image.length()-1)); }
cvs commit: jakarta-lucene/src/java/org/apache/lucene/queryParser QueryParser.jj [ In reply to ]
scottganyo 01/09/26 07:38:34

Modified: src/java/org/apache/lucene/queryParser QueryParser.jj
Log:
Fix compile error: Was referring to old com.lucene.* packages.

Revision Changes Path
1.3 +7 -7 jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj

Index: QueryParser.jj
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QueryParser.jj 2001/09/25 21:54:18 1.2
+++ QueryParser.jj 2001/09/26 14:38:34 1.3
@@ -59,13 +59,13 @@

PARSER_BEGIN(QueryParser)

-package com.lucene.queryParser;
+package org.apache.lucene.queryParser;

import java.util.Vector;
import java.io.*;
-import com.lucene.index.Term;
-import com.lucene.analysis.*;
-import com.lucene.search.*;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.analysis.*;
+import org.apache.lucene.search.*;

/**
* This class is generated by JavaCC. The only method that clients should need
@@ -170,7 +170,7 @@

TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));
Vector v = new Vector();
- com.lucene.analysis.Token t;
+ org.apache.lucene.analysis.Token t;

while (true) {
try {
@@ -202,7 +202,7 @@
// Use the analyzer to get all the tokens. There should be 1 or 2.
TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));
Term[] terms = new Term[2];
- com.lucene.analysis.Token t;
+ org.apache.lucene.analysis.Token t;

for (int i = 0; i < 2; i++)
{
@@ -228,7 +228,7 @@

public static void main(String[] args) throws Exception {
QueryParser qp = new QueryParser("field",
- new com.lucene.analysis.SimpleAnalyzer());
+ new org.apache.lucene.analysis.SimpleAnalyzer());
Query q = qp.parse(args[0]);
System.out.println(q.toString("field"));
}