You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/11/23 20:46:01 UTC
svn commit: r1413042 [1/4] - in /lucene/dev/trunk/solr: ./ core/
core/src/java/org/apache/solr/handler/
core/src/java/org/apache/solr/handler/component/
core/src/java/org/apache/solr/parser/
core/src/java/org/apache/solr/request/ core/src/java/org/apac...
Author: yonik
Date: Fri Nov 23 19:45:50 2012
New Revision: 1413042
URL: http://svn.apache.org/viewvc?rev=1413042&view=rev
Log:
SOLR-4093: solr specific parser + localParams syntax
Added:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/CharStream.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/FastCharStream.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/ParseException.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.jj
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/Token.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/TokenMgrError.java (with props)
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SyntaxError.java (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/build.xml
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/SimpleFacets.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/BoostQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/FunctionRangeQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/Grouping.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/LuceneQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/NestedQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/QParser.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/QueryParsing.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ReturnFields.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SurroundQParserPlugin.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/QueryCommand.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/DummyValueSourceParser.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/FooQParserPlugin.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/NvlValueSourceParser.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri Nov 23 19:45:50 2012
@@ -34,6 +34,13 @@ Velocity 1.6.4 and Velocity Tools 2.0
Apache UIMA 2.3.1
Apache ZooKeeper 3.4.5
+Upgrading from Solr 4.0.0-BETA
+----------------------
+
+Custom java parsing plugins need to migrade from throwing the internal
+ParseException to throwing SyntaxError.
+
+
Detailed Change List
----------------------
@@ -88,6 +95,12 @@ New Features
'storeOffsetsWithPositions' flag on field definitions in the schema.
(Tom Winch, Alan Woodward)
+* SOLR-4093: Solr QParsers may now be directly invoked in the lucene
+ query syntax without the _query_ magic field hack.
+ Example: foo AND {!term f=myfield v=$qq}
+ (yonik)
+
+
Optimizations
----------------------
Modified: lucene/dev/trunk/solr/core/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/build.xml?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/build.xml (original)
+++ lucene/dev/trunk/solr/core/build.xml Fri Nov 23 19:45:50 2012
@@ -42,4 +42,56 @@
</target>
<target name="dist-maven" depends="dist-maven-src-java"/>
+
+
+
+
+ <target name="javacc" depends="javacc-QueryParser"/>
+ <target name="javacc-QueryParser" depends="resolve-javacc">
+ <sequential>
+ <invoke-javacc target="src/java/org/apache/solr/parser/QueryParser.jj"
+ outputDir="src/java/org/apache/solr/parser"/>
+
+ <!-- Change the incorrect public ctors for QueryParser to be protected instead -->
+ <replaceregexp file="src/java/org/apache/solr/parser/QueryParser.java"
+ byline="true"
+ match="public QueryParser\(CharStream "
+ replace="protected QueryParser(CharStream "/>
+ <replaceregexp file="src/java/org/apache/solr/parser/QueryParser.java"
+ byline="true"
+ match="public QueryParser\(QueryParserTokenManager "
+ replace="protected QueryParser(QueryParserTokenManager "/>
+
+ </sequential>
+ </target>
+ <target name="resolve-javacc" xmlns:ivy="antlib:org.apache.ivy.ant">
+ <!-- setup a "fake" JavaCC distribution folder in ${build.dir} to make JavaCC ANT task happy: -->
+ <ivy:retrieve organisation="net.java.dev.javacc" module="javacc" revision="5.0"
+ inline="true" conf="default" transitive="false" type="jar" sync="true"
+ pattern="${build.dir}/javacc/bin/lib/[artifact].[ext]"/>
+ </target>
+
+ <macrodef name="invoke-javacc">
+ <attribute name="target"/>
+ <attribute name="outputDir"/>
+ <sequential>
+ <mkdir dir="@{outputDir}"/>
+ <delete>
+ <fileset dir="@{outputDir}" includes="*.java">
+ <containsregexp expression="Generated.*By.*JavaCC"/>
+ </fileset>
+ </delete>
+ <javacc
+ target="@{target}"
+ outputDirectory="@{outputDir}"
+ javacchome="${build.dir}/javacc"
+ jdkversion="${javac.source}"
+ />
+ <fixcrlf srcdir="@{outputDir}" includes="*.java" encoding="UTF-8">
+ <containsregexp expression="Generated.*By.*JavaCC"/>
+ </fixcrlf>
+ </sequential>
+ </macrodef>
+
+
</project>
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java Fri Nov 23 19:45:50 2012
@@ -29,11 +29,9 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
-import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.index.Term;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.*;
import org.apache.lucene.queries.mlt.MoreLikeThis;
import org.apache.solr.common.SolrException;
@@ -108,7 +106,7 @@ public class MoreLikeThisHandler extends
}
}
}
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java Fri Nov 23 19:45:50 2012
@@ -22,7 +22,6 @@ import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Timer;
import com.yammer.metrics.core.TimerContext;
import com.yammer.metrics.stats.Snapshot;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -32,6 +31,7 @@ import org.apache.solr.core.SolrInfoMBea
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.search.SyntaxError;
import org.apache.solr.util.SolrPluginUtils;
import java.net.URL;
@@ -163,7 +163,7 @@ public abstract class RequestHandlerBase
}
} else {
SolrException.log(SolrCore.log,e);
- if (e instanceof ParseException) {
+ if (e instanceof SyntaxError) {
e = new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java Fri Nov 23 19:45:50 2012
@@ -17,7 +17,6 @@
package org.apache.solr.handler.component;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.util.OpenBitSet;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
@@ -32,6 +31,7 @@ import org.apache.solr.common.util.StrUt
import org.apache.solr.request.SimpleFacets;
import org.apache.solr.schema.FieldType;
import org.apache.solr.search.QueryParsing;
+import org.apache.solr.search.SyntaxError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -670,7 +670,7 @@ public class FacetComponent extends Sear
this.facetStr = facetStr;
try {
this.localParams = QueryParsing.getLocalParams(facetStr, rb.req.getParams());
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
this.facetOn = facetStr;
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java Fri Nov 23 19:45:50 2012
@@ -17,7 +17,6 @@
package org.apache.solr.handler.component;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
@@ -29,6 +28,7 @@ import org.apache.solr.highlight.SolrHig
import org.apache.solr.highlight.DefaultSolrHighlighter;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
+import org.apache.solr.search.SyntaxError;
import org.apache.solr.util.SolrPluginUtils;
import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.solr.util.plugin.SolrCoreAware;
@@ -71,7 +71,7 @@ public class HighlightComponent extends
try {
QParser parser = QParser.getParser(hlq, null, rb.req);
rb.setHighlightQuery(parser.getHighlightQuery());
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java Fri Nov 23 19:45:50 2012
@@ -17,7 +17,6 @@
package org.apache.solr.handler.component;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
@@ -35,6 +34,7 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.index.Term;
+import org.apache.solr.search.SyntaxError;
import java.io.IOException;
import java.util.ArrayList;
@@ -65,7 +65,7 @@ public class PivotFacetHelper extends Si
//ex: pivot == "features,cat" or even "{!ex=mytag}features,cat"
try {
this.parseParams(FacetParams.FACET_PIVOT, pivot);
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(ErrorCode.BAD_REQUEST, e);
}
pivot = facetValue;//facetValue potentially modified from parseParams()
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=1413042&r1=1413041&r2=1413042&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java Fri Nov 23 19:45:50 2012
@@ -23,7 +23,6 @@ import org.apache.lucene.index.AtomicRea
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.index.Term;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.*;
import org.apache.lucene.search.grouping.GroupDocs;
import org.apache.lucene.search.grouping.SearchGroup;
@@ -144,7 +143,7 @@ public class QueryComponent extends Sear
rb.setFilters( filters );
}
}
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
@@ -402,7 +401,7 @@ public class QueryComponent extends Sear
rsp.getToLog().add("hits", grouping.getCommands().get(0).getMatches());
}
return;
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/CharStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/CharStream.java?rev=1413042&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/CharStream.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/CharStream.java Fri Nov 23 19:45:50 2012
@@ -0,0 +1,115 @@
+/* Generated By:JavaCC: Do not edit this line. CharStream.java Version 5.0 */
+/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
+package org.apache.solr.parser;
+
+/**
+ * This interface describes a character stream that maintains line and
+ * column number positions of the characters. It also has the capability
+ * to backup the stream to some extent. An implementation of this
+ * interface is used in the TokenManager implementation generated by
+ * JavaCCParser.
+ *
+ * All the methods except backup can be implemented in any fashion. backup
+ * needs to be implemented correctly for the correct operation of the lexer.
+ * Rest of the methods are all used to get information like line number,
+ * column number and the String that constitutes a token and are not used
+ * by the lexer. Hence their implementation won't affect the generated lexer's
+ * operation.
+ */
+
+public
+interface CharStream {
+
+ /**
+ * Returns the next character from the selected input. The method
+ * of selecting the input is the responsibility of the class
+ * implementing this interface. Can throw any java.io.IOException.
+ */
+ char readChar() throws java.io.IOException;
+
+ @Deprecated
+ /**
+ * Returns the column position of the character last read.
+ * @deprecated
+ * @see #getEndColumn
+ */
+ int getColumn();
+
+ @Deprecated
+ /**
+ * Returns the line number of the character last read.
+ * @deprecated
+ * @see #getEndLine
+ */
+ int getLine();
+
+ /**
+ * Returns the column number of the last character for current token (being
+ * matched after the last call to BeginTOken).
+ */
+ int getEndColumn();
+
+ /**
+ * Returns the line number of the last character for current token (being
+ * matched after the last call to BeginTOken).
+ */
+ int getEndLine();
+
+ /**
+ * Returns the column number of the first character for current token (being
+ * matched after the last call to BeginTOken).
+ */
+ int getBeginColumn();
+
+ /**
+ * Returns the line number of the first character for current token (being
+ * matched after the last call to BeginTOken).
+ */
+ int getBeginLine();
+
+ /**
+ * Backs up the input stream by amount steps. Lexer calls this method if it
+ * had already read some characters, but could not use them to match a
+ * (longer) token. So, they will be used again as the prefix of the next
+ * token and it is the implemetation's responsibility to do this right.
+ */
+ void backup(int amount);
+
+ /**
+ * Returns the next character that marks the beginning of the next token.
+ * All characters must remain in the buffer between two successive calls
+ * to this method to implement backup correctly.
+ */
+ char BeginToken() throws java.io.IOException;
+
+ /**
+ * Returns a string made up of characters from the marked token beginning
+ * to the current buffer position. Implementations have the choice of returning
+ * anything that they want to. For example, for efficiency, one might decide
+ * to just return null, which is a valid implementation.
+ */
+ String GetImage();
+
+ /**
+ * Returns an array of characters that make up the suffix of length 'len' for
+ * the currently matched token. This is used to build up the matched string
+ * for use in actions in the case of MORE. A simple and inefficient
+ * implementation of this is as follows :
+ *
+ * {
+ * String t = GetImage();
+ * return t.substring(t.length() - len, t.length()).toCharArray();
+ * }
+ */
+ char[] GetSuffix(int len);
+
+ /**
+ * The lexer calls this function to indicate that it is done with the stream
+ * and hence implementations can free any resources held by this class.
+ * Again, the body of this function can be just empty and it will not
+ * affect the lexer's operation.
+ */
+ void Done();
+
+}
+/* JavaCC - OriginalChecksum=48b70e7c01825c8f301c7362bf1028d8 (do not edit this line) */
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/FastCharStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/FastCharStream.java?rev=1413042&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/FastCharStream.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/FastCharStream.java Fri Nov 23 19:45:50 2012
@@ -0,0 +1,123 @@
+// FastCharStream.java
+package org.apache.solr.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import java.io.*;
+
+/** An efficient implementation of JavaCC's CharStream interface. <p>Note that
+ * this does not do line-number counting, but instead keeps track of the
+ * character position of the token in the input, as required by Lucene's {@link
+ * org.apache.lucene.analysis.Token} API.
+ * */
+public final class FastCharStream implements CharStream {
+ char[] buffer = null;
+
+ int bufferLength = 0; // end of valid chars
+ int bufferPosition = 0; // next char to read
+
+ int tokenStart = 0; // offset in buffer
+ int bufferStart = 0; // position in file of buffer
+
+ Reader input; // source of chars
+
+ /** Constructs from a Reader. */
+ public FastCharStream(Reader r) {
+ input = r;
+ }
+
+ public final char readChar() throws IOException {
+ if (bufferPosition >= bufferLength)
+ refill();
+ return buffer[bufferPosition++];
+ }
+
+ private final void refill() throws IOException {
+ int newPosition = bufferLength - tokenStart;
+
+ if (tokenStart == 0) { // token won't fit in buffer
+ if (buffer == null) { // first time: alloc buffer
+ buffer = new char[2048];
+ } else if (bufferLength == buffer.length) { // grow buffer
+ char[] newBuffer = new char[buffer.length*2];
+ System.arraycopy(buffer, 0, newBuffer, 0, bufferLength);
+ buffer = newBuffer;
+ }
+ } else { // shift token to front
+ System.arraycopy(buffer, tokenStart, buffer, 0, newPosition);
+ }
+
+ bufferLength = newPosition; // update state
+ bufferPosition = newPosition;
+ bufferStart += tokenStart;
+ tokenStart = 0;
+
+ int charsRead = // fill space in buffer
+ input.read(buffer, newPosition, buffer.length-newPosition);
+ if (charsRead == -1)
+ throw new IOException("read past eof");
+ else
+ bufferLength += charsRead;
+ }
+
+ public final char BeginToken() throws IOException {
+ tokenStart = bufferPosition;
+ return readChar();
+ }
+
+ public final void backup(int amount) {
+ bufferPosition -= amount;
+ }
+
+ public final String GetImage() {
+ return new String(buffer, tokenStart, bufferPosition - tokenStart);
+ }
+
+ public final char[] GetSuffix(int len) {
+ char[] value = new char[len];
+ System.arraycopy(buffer, bufferPosition - len, value, 0, len);
+ return value;
+ }
+
+ public final void Done() {
+ try {
+ input.close();
+ } catch (IOException e) {
+ }
+ }
+
+ public final int getColumn() {
+ return bufferStart + bufferPosition;
+ }
+ public final int getLine() {
+ return 1;
+ }
+ public final int getEndColumn() {
+ return bufferStart + bufferPosition;
+ }
+ public final int getEndLine() {
+ return 1;
+ }
+ public final int getBeginColumn() {
+ return bufferStart + tokenStart;
+ }
+ public final int getBeginLine() {
+ return 1;
+ }
+}
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/ParseException.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/ParseException.java?rev=1413042&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/ParseException.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/ParseException.java Fri Nov 23 19:45:50 2012
@@ -0,0 +1,187 @@
+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */
+/* JavaCCOptions:KEEP_LINE_COL=null */
+package org.apache.solr.parser;
+
+/**
+ * This exception is thrown when parse errors are encountered.
+ * You can explicitly create objects of this exception type by
+ * calling the method generateParseException in the generated
+ * parser.
+ *
+ * You can modify this class to customize your error reporting
+ * mechanisms so long as you retain the public fields.
+ */
+public class ParseException extends Exception {
+
+ /**
+ * The version identifier for this Serializable class.
+ * Increment only if the <i>serialized</i> form of the
+ * class changes.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * This constructor is used by the method "generateParseException"
+ * in the generated parser. Calling this constructor generates
+ * a new object of this type with the fields "currentToken",
+ * "expectedTokenSequences", and "tokenImage" set.
+ */
+ public ParseException(Token currentTokenVal,
+ int[][] expectedTokenSequencesVal,
+ String[] tokenImageVal
+ )
+ {
+ super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
+ currentToken = currentTokenVal;
+ expectedTokenSequences = expectedTokenSequencesVal;
+ tokenImage = tokenImageVal;
+ }
+
+ /**
+ * The following constructors are for use by you for whatever
+ * purpose you can think of. Constructing the exception in this
+ * manner makes the exception behave in the normal way - i.e., as
+ * documented in the class "Throwable". The fields "errorToken",
+ * "expectedTokenSequences", and "tokenImage" do not contain
+ * relevant information. The JavaCC generated code does not use
+ * these constructors.
+ */
+
+ public ParseException() {
+ super();
+ }
+
+ /** Constructor with message. */
+ public ParseException(String message) {
+ super(message);
+ }
+
+
+ /**
+ * This is the last token that has been consumed successfully. If
+ * this object has been created due to a parse error, the token
+ * followng this token will (therefore) be the first error token.
+ */
+ public Token currentToken;
+
+ /**
+ * Each entry in this array is an array of integers. Each array
+ * of integers represents a sequence of tokens (by their ordinal
+ * values) that is expected at this point of the parse.
+ */
+ public int[][] expectedTokenSequences;
+
+ /**
+ * This is a reference to the "tokenImage" array of the generated
+ * parser within which the parse error occurred. This array is
+ * defined in the generated ...Constants interface.
+ */
+ public String[] tokenImage;
+
+ /**
+ * It uses "currentToken" and "expectedTokenSequences" to generate a parse
+ * error message and returns it. If this object has been created
+ * due to a parse error, and you do not catch it (it gets thrown
+ * from the parser) the correct error message
+ * gets displayed.
+ */
+ private static String initialise(Token currentToken,
+ int[][] expectedTokenSequences,
+ String[] tokenImage) {
+ String eol = System.getProperty("line.separator", "\n");
+ StringBuffer expected = new StringBuffer();
+ int maxSize = 0;
+ for (int i = 0; i < expectedTokenSequences.length; i++) {
+ if (maxSize < expectedTokenSequences[i].length) {
+ maxSize = expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < expectedTokenSequences[i].length; j++) {
+ expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
+ }
+ if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
+ expected.append("...");
+ }
+ expected.append(eol).append(" ");
+ }
+ String retval = "Encountered \"";
+ Token tok = currentToken.next;
+ for (int i = 0; i < maxSize; i++) {
+ if (i != 0) retval += " ";
+ if (tok.kind == 0) {
+ retval += tokenImage[0];
+ break;
+ }
+ retval += " " + tokenImage[tok.kind];
+ retval += " \"";
+ retval += add_escapes(tok.image);
+ retval += " \"";
+ tok = tok.next;
+ }
+ retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
+ retval += "." + eol;
+ if (expectedTokenSequences.length == 1) {
+ retval += "Was expecting:" + eol + " ";
+ } else {
+ retval += "Was expecting one of:" + eol + " ";
+ }
+ retval += expected.toString();
+ return retval;
+ }
+
+ /**
+ * The end of line string for this machine.
+ */
+ protected String eol = System.getProperty("line.separator", "\n");
+
+ /**
+ * Used to convert raw characters to their escaped version
+ * when these raw version cannot be used as part of an ASCII
+ * string literal.
+ */
+ static String add_escapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+}
+/* JavaCC - OriginalChecksum=25e1ae9ad9614c4ce31c4b83f8a7397b (do not edit this line) */
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.java?rev=1413042&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.java Fri Nov 23 19:45:50 2012
@@ -0,0 +1,701 @@
+/* Generated By:JavaCC: Do not edit this line. QueryParser.java */
+package org.apache.solr.parser;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.DateTools;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermRangeQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.util.Version;
+import org.apache.solr.search.SyntaxError;
+import org.apache.solr.search.QParser;
+
+
+public class QueryParser extends SolrQueryParserBase implements QueryParserConstants {
+ /** The default operator for parsing queries.
+ * Use {@link QueryParserBase#setDefaultOperator} to change it.
+ */
+ static public enum Operator { OR, AND }
+
+ /** Create a query parser.
+ * @param matchVersion Lucene version to match. See <a href="#version">above</a>.
+ * @param defaultField the default field for query terms.
+ * @param a used to find terms in the query text.
+ */
+ public QueryParser(Version matchVersion, String defaultField, QParser parser) {
+ this(new FastCharStream(new StringReader("")));
+ init(matchVersion, defaultField, parser);
+ }
+
+// * Query ::= ( Clause )*
+// * Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
+ final public int Conjunction() throws ParseException {
+ int ret = CONJ_NONE;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case AND:
+ case OR:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case AND:
+ jj_consume_token(AND);
+ ret = CONJ_AND;
+ break;
+ case OR:
+ jj_consume_token(OR);
+ ret = CONJ_OR;
+ break;
+ default:
+ jj_la1[0] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ break;
+ default:
+ jj_la1[1] = jj_gen;
+ ;
+ }
+ {if (true) return ret;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public int Modifiers() throws ParseException {
+ int ret = MOD_NONE;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case NOT:
+ case PLUS:
+ case MINUS:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PLUS:
+ jj_consume_token(PLUS);
+ ret = MOD_REQ;
+ break;
+ case MINUS:
+ jj_consume_token(MINUS);
+ ret = MOD_NOT;
+ break;
+ case NOT:
+ jj_consume_token(NOT);
+ ret = MOD_NOT;
+ break;
+ default:
+ jj_la1[2] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ break;
+ default:
+ jj_la1[3] = jj_gen;
+ ;
+ }
+ {if (true) return ret;}
+ throw new Error("Missing return statement in function");
+ }
+
+// This makes sure that there is no garbage after the query string
+ final public Query TopLevelQuery(String field) throws ParseException, SyntaxError {
+ Query q;
+ q = Query(field);
+ jj_consume_token(0);
+ {if (true) return q;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Query Query(String field) throws ParseException, SyntaxError {
+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();
+ Query q, firstQuery=null;
+ int conj, mods;
+ mods = Modifiers();
+ q = Clause(field);
+ addClause(clauses, CONJ_NONE, mods, q);
+ if (mods == MOD_NONE)
+ firstQuery=q;
+ label_1:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case AND:
+ case OR:
+ case NOT:
+ case PLUS:
+ case MINUS:
+ case BAREOPER:
+ case LPAREN:
+ case STAR:
+ case QUOTED:
+ case TERM:
+ case PREFIXTERM:
+ case WILDTERM:
+ case REGEXPTERM:
+ case RANGEIN_START:
+ case RANGEEX_START:
+ case LPARAMS:
+ case NUMBER:
+ ;
+ break;
+ default:
+ jj_la1[4] = jj_gen;
+ break label_1;
+ }
+ conj = Conjunction();
+ mods = Modifiers();
+ q = Clause(field);
+ addClause(clauses, conj, mods, q);
+ }
+ if (clauses.size() == 1 && firstQuery != null)
+ {if (true) return firstQuery;}
+ else {
+ {if (true) return getBooleanQuery(clauses);}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Query Clause(String field) throws ParseException, SyntaxError {
+ Query q;
+ Token fieldToken=null, boost=null;
+ Token localParams=null;
+ if (jj_2_1(2)) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case TERM:
+ fieldToken = jj_consume_token(TERM);
+ jj_consume_token(COLON);
+ field=discardEscapeChar(fieldToken.image);
+ break;
+ case STAR:
+ jj_consume_token(STAR);
+ jj_consume_token(COLON);
+ field="*";
+ break;
+ default:
+ jj_la1[5] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ } else {
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BAREOPER:
+ case STAR:
+ case QUOTED:
+ case TERM:
+ case PREFIXTERM:
+ case WILDTERM:
+ case REGEXPTERM:
+ case RANGEIN_START:
+ case RANGEEX_START:
+ case NUMBER:
+ q = Term(field);
+ break;
+ case LPAREN:
+ jj_consume_token(LPAREN);
+ q = Query(field);
+ jj_consume_token(RPAREN);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CARAT:
+ jj_consume_token(CARAT);
+ boost = jj_consume_token(NUMBER);
+ break;
+ default:
+ jj_la1[6] = jj_gen;
+ ;
+ }
+ break;
+ case LPARAMS:
+ localParams = jj_consume_token(LPARAMS);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CARAT:
+ jj_consume_token(CARAT);
+ boost = jj_consume_token(NUMBER);
+ break;
+ default:
+ jj_la1[7] = jj_gen;
+ ;
+ }
+ q=getLocalParams(field, localParams.image);
+ break;
+ default:
+ jj_la1[8] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ {if (true) return handleBoost(q, boost);}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Query Term(String field) throws ParseException, SyntaxError {
+ Token term, boost=null, fuzzySlop=null, goop1, goop2;
+ boolean prefix = false;
+ boolean wildcard = false;
+ boolean fuzzy = false;
+ boolean regexp = false;
+ boolean startInc=false;
+ boolean endInc=false;
+ Query q;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BAREOPER:
+ case STAR:
+ case TERM:
+ case PREFIXTERM:
+ case WILDTERM:
+ case REGEXPTERM:
+ case NUMBER:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case TERM:
+ term = jj_consume_token(TERM);
+ break;
+ case STAR:
+ term = jj_consume_token(STAR);
+ wildcard=true;
+ break;
+ case PREFIXTERM:
+ term = jj_consume_token(PREFIXTERM);
+ prefix=true;
+ break;
+ case WILDTERM:
+ term = jj_consume_token(WILDTERM);
+ wildcard=true;
+ break;
+ case REGEXPTERM:
+ term = jj_consume_token(REGEXPTERM);
+ regexp=true;
+ break;
+ case NUMBER:
+ term = jj_consume_token(NUMBER);
+ break;
+ case BAREOPER:
+ term = jj_consume_token(BAREOPER);
+ term.image = term.image.substring(0,1);
+ break;
+ default:
+ jj_la1[9] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case FUZZY_SLOP:
+ fuzzySlop = jj_consume_token(FUZZY_SLOP);
+ fuzzy=true;
+ break;
+ default:
+ jj_la1[10] = jj_gen;
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CARAT:
+ jj_consume_token(CARAT);
+ boost = jj_consume_token(NUMBER);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case FUZZY_SLOP:
+ fuzzySlop = jj_consume_token(FUZZY_SLOP);
+ fuzzy=true;
+ break;
+ default:
+ jj_la1[11] = jj_gen;
+ ;
+ }
+ break;
+ default:
+ jj_la1[12] = jj_gen;
+ ;
+ }
+ q = handleBareTokenQuery(getField(field), term, fuzzySlop, prefix, wildcard, fuzzy, regexp);
+ break;
+ case RANGEIN_START:
+ case RANGEEX_START:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case RANGEIN_START:
+ jj_consume_token(RANGEIN_START);
+ startInc=true;
+ break;
+ case RANGEEX_START:
+ jj_consume_token(RANGEEX_START);
+ break;
+ default:
+ jj_la1[13] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case RANGE_GOOP:
+ goop1 = jj_consume_token(RANGE_GOOP);
+ break;
+ case RANGE_QUOTED:
+ goop1 = jj_consume_token(RANGE_QUOTED);
+ break;
+ default:
+ jj_la1[14] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case RANGE_TO:
+ jj_consume_token(RANGE_TO);
+ break;
+ default:
+ jj_la1[15] = jj_gen;
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case RANGE_GOOP:
+ goop2 = jj_consume_token(RANGE_GOOP);
+ break;
+ case RANGE_QUOTED:
+ goop2 = jj_consume_token(RANGE_QUOTED);
+ break;
+ default:
+ jj_la1[16] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case RANGEIN_END:
+ jj_consume_token(RANGEIN_END);
+ endInc=true;
+ break;
+ case RANGEEX_END:
+ jj_consume_token(RANGEEX_END);
+ break;
+ default:
+ jj_la1[17] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CARAT:
+ jj_consume_token(CARAT);
+ boost = jj_consume_token(NUMBER);
+ break;
+ default:
+ jj_la1[18] = jj_gen;
+ ;
+ }
+ boolean startOpen=false;
+ boolean endOpen=false;
+ if (goop1.kind == RANGE_QUOTED) {
+ goop1.image = goop1.image.substring(1, goop1.image.length()-1);
+ } else if ("*".equals(goop1.image)) {
+ startOpen=true;
+ }
+ if (goop2.kind == RANGE_QUOTED) {
+ goop2.image = goop2.image.substring(1, goop2.image.length()-1);
+ } else if ("*".equals(goop2.image)) {
+ endOpen=true;
+ }
+ q = getRangeQuery(getField(field), startOpen ? null : discardEscapeChar(goop1.image), endOpen ? null : discardEscapeChar(goop2.image), startInc, endInc);
+ break;
+ case QUOTED:
+ term = jj_consume_token(QUOTED);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case FUZZY_SLOP:
+ fuzzySlop = jj_consume_token(FUZZY_SLOP);
+ break;
+ default:
+ jj_la1[19] = jj_gen;
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CARAT:
+ jj_consume_token(CARAT);
+ boost = jj_consume_token(NUMBER);
+ break;
+ default:
+ jj_la1[20] = jj_gen;
+ ;
+ }
+ q = handleQuotedTerm(getField(field), term, fuzzySlop);
+ break;
+ default:
+ jj_la1[21] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ {if (true) return handleBoost(q, boost);}
+ throw new Error("Missing return statement in function");
+ }
+
+ private boolean jj_2_1(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ try { return !jj_3_1(); }
+ catch(LookaheadSuccess ls) { return true; }
+ finally { jj_save(0, xla); }
+ }
+
+ private boolean jj_3R_3() {
+ if (jj_scan_token(STAR)) return true;
+ if (jj_scan_token(COLON)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_2() {
+ if (jj_scan_token(TERM)) return true;
+ if (jj_scan_token(COLON)) return true;
+ return false;
+ }
+
+ private boolean jj_3_1() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_2()) {
+ jj_scanpos = xsp;
+ if (jj_3R_3()) return true;
+ }
+ return false;
+ }
+
+ /** Generated Token Manager. */
+ public QueryParserTokenManager token_source;
+ /** Current token. */
+ public Token token;
+ /** Next token. */
+ public Token jj_nt;
+ private int jj_ntk;
+ private Token jj_scanpos, jj_lastpos;
+ private int jj_la;
+ private int jj_gen;
+ final private int[] jj_la1 = new int[22];
+ static private int[] jj_la1_0;
+ static private int[] jj_la1_1;
+ static {
+ jj_la1_init_0();
+ jj_la1_init_1();
+ }
+ private static void jj_la1_init_0() {
+ jj_la1_0 = new int[] {0x600,0x600,0x3800,0x3800,0x7f54fe00,0x440000,0x80000,0x80000,0x7f54c000,0x47444000,0x800000,0x800000,0x80000,0x18000000,0x0,0x80000000,0x0,0x0,0x80000,0x800000,0x80000,0x5f544000,};
+ }
+ private static void jj_la1_init_1() {
+ jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc,0x0,0xc,0x3,0x0,0x0,0x0,0x0,};
+ }
+ final private JJCalls[] jj_2_rtns = new JJCalls[1];
+ private boolean jj_rescan = false;
+ private int jj_gc = 0;
+
+ /** Constructor with user supplied CharStream. */
+ protected QueryParser(CharStream stream) {
+ token_source = new QueryParserTokenManager(stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 22; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ /** Reinitialise. */
+ public void ReInit(CharStream stream) {
+ token_source.ReInit(stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 22; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ /** Constructor with generated Token Manager. */
+ protected QueryParser(QueryParserTokenManager tm) {
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 22; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ /** Reinitialise. */
+ public void ReInit(QueryParserTokenManager tm) {
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 22; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ private Token jj_consume_token(int kind) throws ParseException {
+ Token oldToken;
+ if ((oldToken = token).next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ if (token.kind == kind) {
+ jj_gen++;
+ if (++jj_gc > 100) {
+ jj_gc = 0;
+ for (int i = 0; i < jj_2_rtns.length; i++) {
+ JJCalls c = jj_2_rtns[i];
+ while (c != null) {
+ if (c.gen < jj_gen) c.first = null;
+ c = c.next;
+ }
+ }
+ }
+ return token;
+ }
+ token = oldToken;
+ jj_kind = kind;
+ throw generateParseException();
+ }
+
+ static private final class LookaheadSuccess extends java.lang.Error { }
+ final private LookaheadSuccess jj_ls = new LookaheadSuccess();
+ private boolean jj_scan_token(int kind) {
+ if (jj_scanpos == jj_lastpos) {
+ jj_la--;
+ if (jj_scanpos.next == null) {
+ jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
+ } else {
+ jj_lastpos = jj_scanpos = jj_scanpos.next;
+ }
+ } else {
+ jj_scanpos = jj_scanpos.next;
+ }
+ if (jj_rescan) {
+ int i = 0; Token tok = token;
+ while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
+ if (tok != null) jj_add_error_token(kind, i);
+ }
+ if (jj_scanpos.kind != kind) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
+ return false;
+ }
+
+
+/** Get the next Token. */
+ final public Token getNextToken() {
+ if (token.next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ jj_gen++;
+ return token;
+ }
+
+/** Get the specific Token. */
+ final public Token getToken(int index) {
+ Token t = token;
+ for (int i = 0; i < index; i++) {
+ if (t.next != null) t = t.next;
+ else t = t.next = token_source.getNextToken();
+ }
+ return t;
+ }
+
+ private int jj_ntk() {
+ if ((jj_nt=token.next) == null)
+ return (jj_ntk = (token.next=token_source.getNextToken()).kind);
+ else
+ return (jj_ntk = jj_nt.kind);
+ }
+
+ private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
+ private int[] jj_expentry;
+ private int jj_kind = -1;
+ private int[] jj_lasttokens = new int[100];
+ private int jj_endpos;
+
+ private void jj_add_error_token(int kind, int pos) {
+ if (pos >= 100) return;
+ if (pos == jj_endpos + 1) {
+ jj_lasttokens[jj_endpos++] = kind;
+ } else if (jj_endpos != 0) {
+ jj_expentry = new int[jj_endpos];
+ for (int i = 0; i < jj_endpos; i++) {
+ jj_expentry[i] = jj_lasttokens[i];
+ }
+ jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) {
+ int[] oldentry = (int[])(it.next());
+ if (oldentry.length == jj_expentry.length) {
+ for (int i = 0; i < jj_expentry.length; i++) {
+ if (oldentry[i] != jj_expentry[i]) {
+ continue jj_entries_loop;
+ }
+ }
+ jj_expentries.add(jj_expentry);
+ break jj_entries_loop;
+ }
+ }
+ if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
+ }
+ }
+
+ /** Generate ParseException. */
+ public ParseException generateParseException() {
+ jj_expentries.clear();
+ boolean[] la1tokens = new boolean[36];
+ if (jj_kind >= 0) {
+ la1tokens[jj_kind] = true;
+ jj_kind = -1;
+ }
+ for (int i = 0; i < 22; i++) {
+ if (jj_la1[i] == jj_gen) {
+ for (int j = 0; j < 32; j++) {
+ if ((jj_la1_0[i] & (1<<j)) != 0) {
+ la1tokens[j] = true;
+ }
+ if ((jj_la1_1[i] & (1<<j)) != 0) {
+ la1tokens[32+j] = true;
+ }
+ }
+ }
+ }
+ for (int i = 0; i < 36; i++) {
+ if (la1tokens[i]) {
+ jj_expentry = new int[1];
+ jj_expentry[0] = i;
+ jj_expentries.add(jj_expentry);
+ }
+ }
+ jj_endpos = 0;
+ jj_rescan_token();
+ jj_add_error_token(0, 0);
+ int[][] exptokseq = new int[jj_expentries.size()][];
+ for (int i = 0; i < jj_expentries.size(); i++) {
+ exptokseq[i] = jj_expentries.get(i);
+ }
+ return new ParseException(token, exptokseq, tokenImage);
+ }
+
+ /** Enable tracing. */
+ final public void enable_tracing() {
+ }
+
+ /** Disable tracing. */
+ final public void disable_tracing() {
+ }
+
+ private void jj_rescan_token() {
+ jj_rescan = true;
+ for (int i = 0; i < 1; i++) {
+ try {
+ JJCalls p = jj_2_rtns[i];
+ do {
+ if (p.gen > jj_gen) {
+ jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
+ switch (i) {
+ case 0: jj_3_1(); break;
+ }
+ }
+ p = p.next;
+ } while (p != null);
+ } catch(LookaheadSuccess ls) { }
+ }
+ jj_rescan = false;
+ }
+
+ private void jj_save(int index, int xla) {
+ JJCalls p = jj_2_rtns[index];
+ while (p.gen > jj_gen) {
+ if (p.next == null) { p = p.next = new JJCalls(); break; }
+ p = p.next;
+ }
+ p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
+ }
+
+ static final class JJCalls {
+ int gen;
+ Token first;
+ int arg;
+ JJCalls next;
+ }
+
+}
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.jj
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.jj?rev=1413042&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.jj (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParser.jj Fri Nov 23 19:45:50 2012
@@ -0,0 +1,267 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+options {
+ STATIC=false;
+ JAVA_UNICODE_ESCAPE=true;
+ USER_CHAR_STREAM=true;
+}
+
+PARSER_BEGIN(QueryParser)
+
+package org.apache.solr.parser;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.DateTools;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermRangeQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.util.Version;
+import org.apache.solr.search.SyntaxError;
+import org.apache.solr.search.QParser;
+
+
+public class QueryParser extends SolrQueryParserBase {
+ /** The default operator for parsing queries.
+ * Use {@link QueryParserBase#setDefaultOperator} to change it.
+ */
+ static public enum Operator { OR, AND }
+
+ /** Create a query parser.
+ * @param matchVersion Lucene version to match. See <a href="#version">above</a>.
+ * @param defaultField the default field for query terms.
+ * @param a used to find terms in the query text.
+ */
+ public QueryParser(Version matchVersion, String defaultField, QParser parser) {
+ this(new FastCharStream(new StringReader("")));
+ init(matchVersion, defaultField, parser);
+ }
+}
+
+PARSER_END(QueryParser)
+
+/* ***************** */
+/* Token Definitions */
+/* ***************** */
+
+<*> TOKEN : {
+ <#_NUM_CHAR: ["0"-"9"] >
+ // every character that follows a backslash is considered as an escaped character
+ | <#_ESCAPED_CHAR: "\\" ~[] >
+ | <#_TERM_START_CHAR: ( ~[ " ", "\t", "\n", "\r", "\u3000", "+", "-", "!", "(", ")", ":", "^",
+ "[", "]", "\"", "{", "}", "~", "*", "?", "\\", "/" ]
+ | <_ESCAPED_CHAR> ) >
+ | <#_TERM_CHAR: ( <_TERM_START_CHAR>
+ | <_ESCAPED_CHAR> | "-" | "+" | "/" ) >
+ | <#_WHITESPACE: ( " " | "\t" | "\n" | "\r" | "\u3000") >
+ | <#_QUOTED_CHAR: ( ~[ "\"", "\\" ] | <_ESCAPED_CHAR> ) >
+ | <#_SQUOTED_CHAR: ( ~[ "'", "\\" ] | <_ESCAPED_CHAR> ) >
+}
+
+<DEFAULT, Range> SKIP : {
+ < <_WHITESPACE>>
+}
+
+<DEFAULT> TOKEN : {
+ <AND: ("AND" | "&&") >
+ | <OR: ("OR" | "||") >
+ | <NOT: ("NOT" | "!") >
+ | <PLUS: "+" >
+ | <MINUS: "-" >
+ | <BAREOPER: ("+"|"-"|"!") <_WHITESPACE> >
+ | <LPAREN: "(" >
+ | <RPAREN: ")" >
+ | <COLON: ":" >
+ | <STAR: "*" >
+ | <CARAT: "^" > : Boost
+ | <QUOTED: "\"" (<_QUOTED_CHAR>)* "\"">
+ | <SQUOTED: "'" (<_SQUOTED_CHAR>)* "'">
+ | <TERM: <_TERM_START_CHAR> (<_TERM_CHAR>)* >
+ | <FUZZY_SLOP: "~" ( (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? )? >
+ | <PREFIXTERM: ("*") | ( <_TERM_START_CHAR> (<_TERM_CHAR>)* "*" ) >
+ | <WILDTERM: (<_TERM_START_CHAR> | [ "*", "?" ]) (<_TERM_CHAR> | ( [ "*", "?" ] ))* >
+ | <REGEXPTERM: "/" (~[ "/" ] | "\\/" )* "/" >
+ | <RANGEIN_START: "[" > : Range
+ | <RANGEEX_START: "{" > : Range
+ | <LPARAMS: ("{!" ( (<_WHITESPACE>)* (~["=","}"])+ ( "=" (<QUOTED> | <SQUOTED> | (~[" ","}"])+ )? )? )* "}")+ (~[")"," ","\t","\n","{","^"])* >
+}
+
+<Boost> TOKEN : {
+ <NUMBER: ("-")? (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? > : DEFAULT
+}
+
+<Range> TOKEN : {
+ <RANGE_TO: "TO">
+ | <RANGEIN_END: "]"> : DEFAULT
+ | <RANGEEX_END: "}"> : DEFAULT
+ | <RANGE_QUOTED: "\"" (~["\""] | "\\\"")+ "\"">
+ | <RANGE_GOOP: (~[ " ", "]", "}" ])+ >
+}
+
+// * Query ::= ( Clause )*
+// * Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
+
+int Conjunction() : {
+ int ret = CONJ_NONE;
+}
+{
+ [
+ <AND> { ret = CONJ_AND; }
+ | <OR> { ret = CONJ_OR; }
+ ]
+ { return ret; }
+}
+
+int Modifiers() : {
+ int ret = MOD_NONE;
+}
+{
+ [
+ <PLUS> { ret = MOD_REQ; }
+ | <MINUS> { ret = MOD_NOT; }
+ | <NOT> { ret = MOD_NOT; }
+ ]
+ { return ret; }
+}
+
+// This makes sure that there is no garbage after the query string
+Query TopLevelQuery(String field) throws SyntaxError :
+{
+ Query q;
+}
+{
+ q=Query(field) <EOF>
+ {
+ return q;
+ }
+}
+
+Query Query(String field) throws SyntaxError :
+{
+ List<BooleanClause> clauses = new ArrayList<BooleanClause>();
+ Query q, firstQuery=null;
+ int conj, mods;
+}
+{
+ mods=Modifiers() q=Clause(field)
+ {
+ addClause(clauses, CONJ_NONE, mods, q);
+ if (mods == MOD_NONE)
+ firstQuery=q;
+ }
+ (
+ conj=Conjunction() mods=Modifiers() q=Clause(field)
+ { addClause(clauses, conj, mods, q); }
+ )*
+ {
+ if (clauses.size() == 1 && firstQuery != null)
+ return firstQuery;
+ else {
+ return getBooleanQuery(clauses);
+ }
+ }
+}
+
+Query Clause(String field) throws SyntaxError : {
+ Query q;
+ Token fieldToken=null, boost=null;
+ Token localParams=null;
+}
+{
+
+ [
+ LOOKAHEAD(2)
+ (
+ fieldToken=<TERM> <COLON> {field=discardEscapeChar(fieldToken.image);}
+ | <STAR> <COLON> {field="*";}
+ )
+ ]
+
+
+ (
+ q=Term(field)
+ | <LPAREN> q=Query(field) <RPAREN> (<CARAT> boost=<NUMBER>)?
+ | (localParams = <LPARAMS> (<CARAT> boost=<NUMBER>)? { q=getLocalParams(field, localParams.image); } )
+ )
+ { return handleBoost(q, boost); }
+}
+
+
+Query Term(String field) throws SyntaxError : {
+ Token term, boost=null, fuzzySlop=null, goop1, goop2;
+ boolean prefix = false;
+ boolean wildcard = false;
+ boolean fuzzy = false;
+ boolean regexp = false;
+ boolean startInc=false;
+ boolean endInc=false;
+ Query q;
+}
+{
+ (
+ (
+ term=<TERM>
+ | term=<STAR> { wildcard=true; }
+ | term=<PREFIXTERM> { prefix=true; }
+ | term=<WILDTERM> { wildcard=true; }
+ | term=<REGEXPTERM> { regexp=true; }
+ | term=<NUMBER>
+ | term=<BAREOPER> { term.image = term.image.substring(0,1); }
+ )
+ [ fuzzySlop=<FUZZY_SLOP> { fuzzy=true; } ]
+ [ <CARAT> boost=<NUMBER> [ fuzzySlop=<FUZZY_SLOP> { fuzzy=true; } ] ]
+ {
+ q = handleBareTokenQuery(getField(field), term, fuzzySlop, prefix, wildcard, fuzzy, regexp);
+ }
+ | ( ( <RANGEIN_START> {startInc=true;} | <RANGEEX_START> )
+ ( goop1=<RANGE_GOOP>|goop1=<RANGE_QUOTED> )
+ [ <RANGE_TO> ]
+ ( goop2=<RANGE_GOOP>|goop2=<RANGE_QUOTED> )
+ ( <RANGEIN_END> {endInc=true;} | <RANGEEX_END>))
+ [ <CARAT> boost=<NUMBER> ]
+ {
+ boolean startOpen=false;
+ boolean endOpen=false;
+ if (goop1.kind == RANGE_QUOTED) {
+ goop1.image = goop1.image.substring(1, goop1.image.length()-1);
+ } else if ("*".equals(goop1.image)) {
+ startOpen=true;
+ }
+ if (goop2.kind == RANGE_QUOTED) {
+ goop2.image = goop2.image.substring(1, goop2.image.length()-1);
+ } else if ("*".equals(goop2.image)) {
+ endOpen=true;
+ }
+ q = getRangeQuery(getField(field), startOpen ? null : discardEscapeChar(goop1.image), endOpen ? null : discardEscapeChar(goop2.image), startInc, endInc);
+ }
+ | term=<QUOTED>
+ [ fuzzySlop=<FUZZY_SLOP> ]
+ [ <CARAT> boost=<NUMBER> ]
+ {
+ q = handleQuotedTerm(getField(field), term, fuzzySlop);
+ }
+ )
+ {
+ return handleBoost(q, boost);
+ }
+}
Added: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java?rev=1413042&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java (added)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java Fri Nov 23 19:45:50 2012
@@ -0,0 +1,129 @@
+/* Generated By:JavaCC: Do not edit this line. QueryParserConstants.java */
+package org.apache.solr.parser;
+
+
+/**
+ * Token literal values and constants.
+ * Generated by org.javacc.parser.OtherFilesGen#start()
+ */
+public interface QueryParserConstants {
+
+ /** End of File. */
+ int EOF = 0;
+ /** RegularExpression Id. */
+ int _NUM_CHAR = 1;
+ /** RegularExpression Id. */
+ int _ESCAPED_CHAR = 2;
+ /** RegularExpression Id. */
+ int _TERM_START_CHAR = 3;
+ /** RegularExpression Id. */
+ int _TERM_CHAR = 4;
+ /** RegularExpression Id. */
+ int _WHITESPACE = 5;
+ /** RegularExpression Id. */
+ int _QUOTED_CHAR = 6;
+ /** RegularExpression Id. */
+ int _SQUOTED_CHAR = 7;
+ /** RegularExpression Id. */
+ int AND = 9;
+ /** RegularExpression Id. */
+ int OR = 10;
+ /** RegularExpression Id. */
+ int NOT = 11;
+ /** RegularExpression Id. */
+ int PLUS = 12;
+ /** RegularExpression Id. */
+ int MINUS = 13;
+ /** RegularExpression Id. */
+ int BAREOPER = 14;
+ /** RegularExpression Id. */
+ int LPAREN = 15;
+ /** RegularExpression Id. */
+ int RPAREN = 16;
+ /** RegularExpression Id. */
+ int COLON = 17;
+ /** RegularExpression Id. */
+ int STAR = 18;
+ /** RegularExpression Id. */
+ int CARAT = 19;
+ /** RegularExpression Id. */
+ int QUOTED = 20;
+ /** RegularExpression Id. */
+ int SQUOTED = 21;
+ /** RegularExpression Id. */
+ int TERM = 22;
+ /** RegularExpression Id. */
+ int FUZZY_SLOP = 23;
+ /** RegularExpression Id. */
+ int PREFIXTERM = 24;
+ /** RegularExpression Id. */
+ int WILDTERM = 25;
+ /** RegularExpression Id. */
+ int REGEXPTERM = 26;
+ /** RegularExpression Id. */
+ int RANGEIN_START = 27;
+ /** RegularExpression Id. */
+ int RANGEEX_START = 28;
+ /** RegularExpression Id. */
+ int LPARAMS = 29;
+ /** RegularExpression Id. */
+ int NUMBER = 30;
+ /** RegularExpression Id. */
+ int RANGE_TO = 31;
+ /** RegularExpression Id. */
+ int RANGEIN_END = 32;
+ /** RegularExpression Id. */
+ int RANGEEX_END = 33;
+ /** RegularExpression Id. */
+ int RANGE_QUOTED = 34;
+ /** RegularExpression Id. */
+ int RANGE_GOOP = 35;
+
+ /** Lexical state. */
+ int Boost = 0;
+ /** Lexical state. */
+ int Range = 1;
+ /** Lexical state. */
+ int DEFAULT = 2;
+
+ /** Literal token values. */
+ String[] tokenImage = {
+ "<EOF>",
+ "<_NUM_CHAR>",
+ "<_ESCAPED_CHAR>",
+ "<_TERM_START_CHAR>",
+ "<_TERM_CHAR>",
+ "<_WHITESPACE>",
+ "<_QUOTED_CHAR>",
+ "<_SQUOTED_CHAR>",
+ "<token of kind 8>",
+ "<AND>",
+ "<OR>",
+ "<NOT>",
+ "\"+\"",
+ "\"-\"",
+ "<BAREOPER>",
+ "\"(\"",
+ "\")\"",
+ "\":\"",
+ "\"*\"",
+ "\"^\"",
+ "<QUOTED>",
+ "<SQUOTED>",
+ "<TERM>",
+ "<FUZZY_SLOP>",
+ "<PREFIXTERM>",
+ "<WILDTERM>",
+ "<REGEXPTERM>",
+ "\"[\"",
+ "\"{\"",
+ "<LPARAMS>",
+ "<NUMBER>",
+ "\"TO\"",
+ "\"]\"",
+ "\"}\"",
+ "<RANGE_QUOTED>",
+ "<RANGE_GOOP>",
+ };
+
+}