You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2013/01/18 19:31:23 UTC
svn commit: r1435287 [32/41] - in /lucene/dev/branches/LUCENE-2878: ./
dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/
dev-tools/idea/lucene/analysis/icu/ dev-tools/maven/
dev-tools/maven/lucene/benchmark/ dev-tools/maven/solr/ dev-tools/...
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/QueryParsing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/QueryParsing.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/QueryParsing.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/QueryParsing.java Fri Jan 18 18:30:54 2013
@@ -20,8 +20,6 @@ package org.apache.solr.search;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.function.FunctionQuery;
import org.apache.lucene.queries.function.valuesource.QueryValueSource;
-import org.apache.lucene.queryparser.classic.ParseException;
-import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.ConstantScoreQuery;
@@ -39,6 +37,7 @@ import org.apache.lucene.util.CharsRef;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.parser.QueryParser;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
@@ -95,12 +94,12 @@ public class QueryParsing {
}
// note to self: something needs to detect infinite recursion when parsing queries
- public static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params) throws ParseException {
+ public static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params) throws SyntaxError {
return parseLocalParams(txt, start, target, params, LOCALPARAM_START, LOCALPARAM_END);
}
- public static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params, String startString, char endChar) throws ParseException {
+ public static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params, String startString, char endChar) throws SyntaxError {
int off = start;
if (!txt.startsWith(startString, off)) return start;
StrParser p = new StrParser(txt, start, txt.length());
@@ -109,7 +108,7 @@ public class QueryParsing {
for (; ;) {
/*
if (p.pos>=txt.length()) {
- throw new ParseException("Missing '}' parsing local params '" + txt + '"');
+ throw new SyntaxError("Missing '}' parsing local params '" + txt + '"');
}
*/
char ch = p.peek();
@@ -119,7 +118,7 @@ public class QueryParsing {
String id = p.getId();
if (id.length() == 0) {
- throw new ParseException("Expected ending character '" + endChar + "' parsing local params '" + txt + '"');
+ throw new SyntaxError("Expected ending character '" + endChar + "' parsing local params '" + txt + '"');
}
String val = null;
@@ -148,7 +147,7 @@ public class QueryParsing {
int valStart = p.pos;
for (; ;) {
if (p.pos >= p.end) {
- throw new ParseException("Missing end to unquoted value starting at " + valStart + " str='" + txt + "'");
+ throw new SyntaxError("Missing end to unquoted value starting at " + valStart + " str='" + txt + "'");
}
char c = p.val.charAt(p.pos);
if (c == endChar || Character.isWhitespace(c)) {
@@ -202,7 +201,7 @@ public class QueryParsing {
* "{!prefix f=myfield}yes" returns type="prefix",f="myfield",v="yes"
* "{!prefix f=myfield v=$p}" returns type="prefix",f="myfield",v=params.get("p")
*/
- public static SolrParams getLocalParams(String txt, SolrParams params) throws ParseException {
+ public static SolrParams getLocalParams(String txt, SolrParams params) throws SyntaxError {
if (txt == null || !txt.startsWith(LOCALPARAM_START)) {
return null;
}
@@ -352,7 +351,7 @@ public class QueryParsing {
}
}
- } catch (ParseException e) {
+ } catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "error in sort: " + sortSpec, e);
}
@@ -628,13 +627,13 @@ public class QueryParsing {
}
- void expect(String s) throws ParseException {
+ void expect(String s) throws SyntaxError {
eatws();
int slen = s.length();
if (val.regionMatches(pos, s, 0, slen)) {
pos += slen;
} else {
- throw new ParseException("Expected '" + s + "' at position " + pos + " in '" + val + "'");
+ throw new SyntaxError("Expected '" + s + "' at position " + pos + " in '" + val + "'");
}
}
@@ -723,11 +722,11 @@ public class QueryParsing {
}
- String getId() throws ParseException {
+ String getId() throws SyntaxError {
return getId("Expected identifier");
}
- String getId(String errMessage) throws ParseException {
+ String getId(String errMessage) throws SyntaxError {
eatws();
int id_start = pos;
char ch;
@@ -745,12 +744,12 @@ public class QueryParsing {
}
if (errMessage != null) {
- throw new ParseException(errMessage + " at pos " + pos + " str='" + val + "'");
+ throw new SyntaxError(errMessage + " at pos " + pos + " str='" + val + "'");
}
return null;
}
- public String getGlobbedId(String errMessage) throws ParseException {
+ public String getGlobbedId(String errMessage) throws SyntaxError {
eatws();
int id_start = pos;
char ch;
@@ -767,7 +766,7 @@ public class QueryParsing {
}
if (errMessage != null) {
- throw new ParseException(errMessage + " at pos " + pos + " str='" + val + "'");
+ throw new SyntaxError(errMessage + " at pos " + pos + " str='" + val + "'");
}
return null;
}
@@ -793,7 +792,7 @@ public class QueryParsing {
* sort direction. (True is desc, False is asc).
* Position is advanced to after the comma (or end) when result is non null
*/
- Boolean getSortDirection() throws ParseException {
+ Boolean getSortDirection() throws SyntaxError {
final int startPos = pos;
final String order = getId(null);
@@ -823,7 +822,7 @@ public class QueryParsing {
}
// return null if not a string
- String getQuotedString() throws ParseException {
+ String getQuotedString() throws SyntaxError {
eatws();
char delim = peekChar();
if (!(delim == '\"' || delim == '\'')) {
@@ -833,7 +832,7 @@ public class QueryParsing {
StringBuilder sb = new StringBuilder(); // needed for escaping
for (; ;) {
if (pos >= end) {
- throw new ParseException("Missing end quote for string at pos " + (val_start - 1) + " str='" + val + "'");
+ throw new SyntaxError("Missing end quote for string at pos " + (val_start - 1) + " str='" + val + "'");
}
char ch = val.charAt(pos);
if (ch == '\\') {
@@ -858,7 +857,7 @@ public class QueryParsing {
break;
case 'u':
if (pos + 4 >= end) {
- throw new ParseException("bad unicode escape \\uxxxx at pos" + (val_start - 1) + " str='" + val + "'");
+ throw new SyntaxError("bad unicode escape \\uxxxx at pos" + (val_start - 1) + " str='" + val + "'");
}
ch = (char) Integer.parseInt(val.substring(pos + 1, pos + 5), 16);
pos += 4;
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/RawQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/RawQParserPlugin.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/RawQParserPlugin.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/RawQParserPlugin.java Fri Jan 18 18:30:54 2013
@@ -36,6 +36,7 @@ import org.apache.solr.request.SolrQuery
public class RawQParserPlugin extends QParserPlugin {
public static String NAME = "raw";
+ @Override
public void init(NamedList args) {
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ReturnFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ReturnFields.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ReturnFields.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ReturnFields.java Fri Jan 18 18:30:54 2013
@@ -18,26 +18,7 @@ package org.apache.solr.search;
import java.util.*;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.lucene.queries.function.FunctionQuery;
-import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.queries.function.valuesource.QueryValueSource;
-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;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.transform.DocTransformer;
-import org.apache.solr.response.transform.DocTransformers;
-import org.apache.solr.response.transform.RenameFieldTransformer;
-import org.apache.solr.response.transform.ScoreAugmenter;
-import org.apache.solr.response.transform.TransformerFactory;
-import org.apache.solr.response.transform.ValueSourceAugmenter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* A class representing the return fields
@@ -45,376 +26,24 @@ import org.slf4j.LoggerFactory;
*
* @since solr 4.0
*/
-public class ReturnFields
-{
- static final Logger log = LoggerFactory.getLogger( ReturnFields.class );
+public abstract class ReturnFields {
+ /**
+ * Set of field names with their exact names from the lucene index.
+ * <p>
+ * Class such as ResponseWriters pass this to {@link SolrIndexSearcher#doc(int, Set)}.
+ * @return Set of field names or <code>null</code> (all fields).
+ */
+ public abstract Set<String> getLuceneFieldNames();
+
+ /** Returns <code>true</code> if the specified field should be returned. */
+ public abstract boolean wantsField(String name);
- // Special Field Keys
- public static final String SCORE = "score";
+ /** Returns <code>true</code> if all fields should be returned. */
+ public abstract boolean wantsAllFields();
- private final List<String> globs = new ArrayList<String>(1);
-
- // The lucene field names to request from the SolrIndexSearcher
- // Order is important for CSVResponseWriter
- private final Set<String> fields = new LinkedHashSet<String>();
-
- // Field names that are OK to include in the response.
- // This will include pseudo fields, lucene fields, and matching globs
- private Set<String> okFieldNames = new HashSet<String>();
+ /** Returns <code>true</code> if the score should be returned. */
+ public abstract boolean wantsScore();
- // The list of explicitly requested fields
- private Set<String> reqFieldNames = null;
-
- private DocTransformer transformer;
- private boolean _wantsScore = false;
- private boolean _wantsAllFields = false;
-
- public ReturnFields() {
- _wantsAllFields = true;
- }
-
- public ReturnFields(SolrQueryRequest req) {
- this( req.getParams().getParams(CommonParams.FL), req );
- }
-
- public ReturnFields(String fl, SolrQueryRequest req) {
-// this( (fl==null)?null:SolrPluginUtils.split(fl), req );
- if( fl == null ) {
- parseFieldList((String[])null, req);
- }
- else {
- if( fl.trim().length() == 0 ) {
- // legacy thing to support fl=' ' => fl=*,score!
- // maybe time to drop support for this?
- // See ConvertedLegacyTest
- _wantsScore = true;
- _wantsAllFields = true;
- transformer = new ScoreAugmenter(SCORE);
- }
- else {
- parseFieldList( new String[]{fl}, req);
- }
- }
- }
-
- public ReturnFields(String[] fl, SolrQueryRequest req) {
- parseFieldList(fl, req);
- }
-
- private void parseFieldList(String[] fl, SolrQueryRequest req) {
- _wantsScore = false;
- _wantsAllFields = false;
- if (fl == null || fl.length == 0 || fl.length == 1 && fl[0].length()==0) {
- _wantsAllFields = true;
- return;
- }
-
- NamedList<String> rename = new NamedList<String>();
- DocTransformers augmenters = new DocTransformers();
- for (String fieldList : fl) {
- add(fieldList,rename,augmenters,req);
- }
- for( int i=0; i<rename.size(); i++ ) {
- String from = rename.getName(i);
- String to = rename.getVal(i);
- okFieldNames.add( to );
- boolean copy = (reqFieldNames!=null && reqFieldNames.contains(from));
- if(!copy) {
- // Check that subsequent copy/rename requests have the field they need to copy
- for(int j=i+1; j<rename.size(); j++) {
- if(from.equals(rename.getName(j))) {
- rename.setName(j, to); // copy from the current target
- if(reqFieldNames==null) {
- reqFieldNames = new HashSet<String>();
- }
- reqFieldNames.add(to); // don't rename our current target
- }
- }
- }
- augmenters.addTransformer( new RenameFieldTransformer( from, to, copy ) );
- }
-
- if( !_wantsAllFields ) {
- if( !globs.isEmpty() ) {
- // TODO??? need to fill up the fields with matching field names in the index
- // and add them to okFieldNames?
- // maybe just get all fields?
- // this would disable field selection optimization... i think thatis OK
- fields.clear(); // this will get all fields, and use wantsField to limit
- }
- okFieldNames.addAll( fields );
- }
-
- if( augmenters.size() == 1 ) {
- transformer = augmenters.getTransformer(0);
- }
- else if( augmenters.size() > 1 ) {
- transformer = augmenters;
- }
- }
-
-
- // like getId, but also accepts dashes for legacy fields
- String getFieldName(QueryParsing.StrParser sp) {
- sp.eatws();
- int id_start = sp.pos;
- char ch;
- if (sp.pos < sp.end && (ch = sp.val.charAt(sp.pos)) != '$' && Character.isJavaIdentifierStart(ch)) {
- sp.pos++;
- while (sp.pos < sp.end) {
- ch = sp.val.charAt(sp.pos);
- if (!Character.isJavaIdentifierPart(ch) && ch != '.' && ch != '-') {
- break;
- }
- sp.pos++;
- }
- return sp.val.substring(id_start, sp.pos);
- }
-
- return null;
- }
-
- private void add(String fl, NamedList<String> rename, DocTransformers augmenters, SolrQueryRequest req) {
- if( fl == null ) {
- return;
- }
- try {
- QueryParsing.StrParser sp = new QueryParsing.StrParser(fl);
-
- for(;;) {
- sp.opt(',');
- sp.eatws();
- if (sp.pos >= sp.end) break;
-
- int start = sp.pos;
-
- // short circuit test for a really simple field name
- String key = null;
- String field = getFieldName(sp);
- char ch = sp.ch();
-
- if (field != null) {
- if (sp.opt(':')) {
- // this was a key, not a field name
- key = field;
- field = null;
- sp.eatws();
- start = sp.pos;
- } else {
- if (Character.isWhitespace(ch) || ch == ',' || ch==0) {
- addField( field, key, augmenters, req );
- continue;
- }
- // an invalid field name... reset the position pointer to retry
- sp.pos = start;
- field = null;
- }
- }
-
- if (key != null) {
- // we read "key : "
- field = sp.getId(null);
- ch = sp.ch();
- if (field != null && (Character.isWhitespace(ch) || ch == ',' || ch==0)) {
- rename.add(field, key);
- addField( field, key, augmenters, req );
- continue;
- }
- // an invalid field name... reset the position pointer to retry
- sp.pos = start;
- field = null;
- }
-
- if (field == null) {
- // We didn't find a simple name, so let's see if it's a globbed field name.
- // Globbing only works with field names of the recommended form (roughly like java identifiers)
-
- field = sp.getGlobbedId(null);
- ch = sp.ch();
- if (field != null && (Character.isWhitespace(ch) || ch == ',' || ch==0)) {
- // "*" looks and acts like a glob, but we give it special treatment
- if ("*".equals(field)) {
- _wantsAllFields = true;
- } else {
- globs.add(field);
- }
- continue;
- }
-
- // an invalid glob
- sp.pos = start;
- }
-
- String funcStr = sp.val.substring(start);
-
- // Is it an augmenter of the form [augmenter_name foo=1 bar=myfield]?
- // This is identical to localParams syntax except it uses [] instead of {!}
-
- if (funcStr.startsWith("[")) {
- Map<String,String> augmenterArgs = new HashMap<String,String>();
- int end = QueryParsing.parseLocalParams(funcStr, 0, augmenterArgs, req.getParams(), "[", ']');
- sp.pos += end;
-
- // [foo] is short for [type=foo] in localParams syntax
- String augmenterName = augmenterArgs.remove("type");
- String disp = key;
- if( disp == null ) {
- disp = '['+augmenterName+']';
- }
-
- TransformerFactory factory = req.getCore().getTransformerFactory( augmenterName );
- if( factory != null ) {
- MapSolrParams augmenterParams = new MapSolrParams( augmenterArgs );
- augmenters.addTransformer( factory.create(disp, augmenterParams, req) );
- }
- else {
- // unknown transformer?
- }
- addField(field, disp, augmenters, req);
- continue;
- }
-
-
- // let's try it as a function instead
- QParser parser = QParser.getParser(funcStr, FunctionQParserPlugin.NAME, req);
- Query q = null;
- ValueSource vs = null;
-
- try {
- if (parser instanceof FunctionQParser) {
- FunctionQParser fparser = (FunctionQParser)parser;
- fparser.setParseMultipleSources(false);
- fparser.setParseToEnd(false);
-
- q = fparser.getQuery();
-
- if (fparser.localParams != null) {
- if (fparser.valFollowedParams) {
- // need to find the end of the function query via the string parser
- int leftOver = fparser.sp.end - fparser.sp.pos;
- sp.pos = sp.end - leftOver; // reset our parser to the same amount of leftover
- } else {
- // the value was via the "v" param in localParams, so we need to find
- // the end of the local params themselves to pick up where we left off
- sp.pos = start + fparser.localParamsEnd;
- }
- } else {
- // need to find the end of the function query via the string parser
- int leftOver = fparser.sp.end - fparser.sp.pos;
- sp.pos = sp.end - leftOver; // reset our parser to the same amount of leftover
- }
- } else {
- // A QParser that's not for function queries.
- // It must have been specified via local params.
- q = parser.getQuery();
-
- assert parser.getLocalParams() != null;
- sp.pos = start + parser.localParamsEnd;
- }
-
-
- if (q instanceof FunctionQuery) {
- vs = ((FunctionQuery)q).getValueSource();
- } else {
- vs = new QueryValueSource(q, 0.0f);
- }
-
- if (key==null) {
- SolrParams localParams = parser.getLocalParams();
- if (localParams != null) {
- key = localParams.get("key");
- }
- if (key == null) {
- // use the function name itself as the field name
- key = sp.val.substring(start, sp.pos);
- }
- }
-
-
- if (key==null) {
- key = funcStr;
- }
- okFieldNames.add( key );
- okFieldNames.add( funcStr );
- augmenters.addTransformer( new ValueSourceAugmenter( key, parser, vs ) );
- }
- catch (ParseException e) {
- // try again, simple rules for a field name with no whitespace
- sp.pos = start;
- field = sp.getSimpleString();
-
- if (req.getSchema().getFieldOrNull(field) != null) {
- // OK, it was an oddly named field
- fields.add(field);
- if( key != null ) {
- rename.add(field, key);
- }
- } else {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing fieldname: " + e.getMessage(), e);
- }
- }
-
- // end try as function
-
- } // end for(;;)
- } catch (ParseException e) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing fieldname", e);
- }
- }
-
- private void addField( String field, String key, DocTransformers augmenters, SolrQueryRequest req )
- {
- if(key==null) {
- if(reqFieldNames==null) {
- reqFieldNames = new HashSet<String>();
- }
- reqFieldNames.add(field);
- }
-
- fields.add(field); // need to put in the map to maintain order for things like CSVResponseWriter
- okFieldNames.add( field );
- okFieldNames.add( key );
- // a valid field name
- if(SCORE.equals(field)) {
- _wantsScore = true;
-
- String disp = (key==null) ? field : key;
- augmenters.addTransformer( new ScoreAugmenter( disp ) );
- }
- }
-
- public Set<String> getLuceneFieldNames()
- {
- return (_wantsAllFields || fields.isEmpty()) ? null : fields;
- }
-
- public boolean wantsAllFields()
- {
- return _wantsAllFields;
- }
-
- public boolean wantsScore()
- {
- return _wantsScore;
- }
-
- public boolean wantsField( String name )
- {
- if( _wantsAllFields || okFieldNames.contains( name ) ){
- return true;
- }
- for( String s : globs ) {
- // TODO something better?
- if( FilenameUtils.wildcardMatch( name, s ) ) {
- okFieldNames.add(name); // Don't calculate it again
- return true;
- }
- }
- return false;
- }
-
- public DocTransformer getTransformer()
- {
- return transformer;
- }
+ /** Returns the DocTransformer used to modify documents, or <code>null</code> */
+ public abstract DocTransformer getTransformer();
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java Fri Jan 18 18:30:54 2013
@@ -38,19 +38,26 @@ public class SolrFieldCacheMBean impleme
protected FieldCacheSanityChecker checker = new FieldCacheSanityChecker();
+ @Override
public String getName() { return this.getClass().getName(); }
+ @Override
public String getVersion() { return SolrCore.version; }
+ @Override
public String getDescription() {
return "Provides introspection of the Lucene FieldCache, "
+ "this is **NOT** a cache that is managed by Solr.";
}
+ @Override
public Category getCategory() { return Category.CACHE; }
+ @Override
public String getSource() {
return "$URL$";
}
+ @Override
public URL[] getDocs() {
return null;
}
+ @Override
public NamedList getStatistics() {
NamedList stats = new SimpleOrderedMap();
CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries();
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java Fri Jan 18 18:30:54 2013
@@ -50,6 +50,7 @@ import org.apache.solr.core.DirectoryFac
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoMBean;
+import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestInfo;
@@ -110,6 +111,8 @@ public class SolrIndexSearcher extends I
private final SolrCache[] cacheList;
private static final SolrCache[] noCaches = new SolrCache[0];
+ private final FieldInfos fieldInfos;
+ // TODO: do we need this separate set of field names? we can just use the fieldinfos?
private final Collection<String> fieldNames;
private Collection<String> storedHighlightFieldNames;
private DirectoryFactory directoryFactory;
@@ -118,7 +121,7 @@ public class SolrIndexSearcher extends I
public SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, SolrIndexConfig config, String name, boolean enableCache, DirectoryFactory directoryFactory) throws IOException {
// we don't need to reserve the directory because we get it from the factory
- this(core, schema,name, core.getIndexReaderFactory().newReader(directoryFactory.get(path, config.lockType), core), true, enableCache, false, directoryFactory);
+ this(core, schema,name, core.getIndexReaderFactory().newReader(directoryFactory.get(path, DirContext.DEFAULT, config.lockType), core), true, enableCache, false, directoryFactory);
}
private static String getIndexDir(Directory dir) {
@@ -200,7 +203,8 @@ public class SolrIndexSearcher extends I
optimizer = null;
fieldNames = new HashSet<String>();
- for(FieldInfo fieldInfo : atomicReader.getFieldInfos()) {
+ fieldInfos = atomicReader.getFieldInfos();
+ for(FieldInfo fieldInfo : fieldInfos) {
fieldNames.add(fieldInfo.name);
}
@@ -253,6 +257,7 @@ public class SolrIndexSearcher extends I
*
* In particular, the underlying reader and any cache's in use are closed.
*/
+ @Override
public void close() throws IOException {
if (debug) {
if (cachingEnabled) {
@@ -332,6 +337,7 @@ public class SolrIndexSearcher extends I
if (solrConfig.fieldValueCacheConfig != null && solrConfig.fieldValueCacheConfig.getRegenerator() == null) {
solrConfig.fieldValueCacheConfig.setRegenerator(
new CacheRegenerator() {
+ @Override
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException {
if (oldVal instanceof UnInvertedField) {
UnInvertedField.getUnInvertedField((String)oldKey, newSearcher);
@@ -345,6 +351,7 @@ public class SolrIndexSearcher extends I
if (solrConfig.filterCacheConfig != null && solrConfig.filterCacheConfig.getRegenerator() == null) {
solrConfig.filterCacheConfig.setRegenerator(
new CacheRegenerator() {
+ @Override
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException {
newSearcher.cacheDocSet((Query)oldKey, null, false);
return true;
@@ -357,6 +364,7 @@ public class SolrIndexSearcher extends I
final int queryResultWindowSize = solrConfig.queryResultWindowSize;
solrConfig.queryResultCacheConfig.setRegenerator(
new CacheRegenerator() {
+ @Override
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException {
QueryResultKey key = (QueryResultKey)oldKey;
int nDocs=1;
@@ -439,6 +447,7 @@ public class SolrIndexSearcher extends I
lazyDoc = new LazyDocument(reader, docID);
}
+ @Override
public Status needsField(FieldInfo fieldInfo) {
if (fieldsToLoad.contains(fieldInfo.name)) {
return Status.YES;
@@ -505,21 +514,65 @@ public class SolrIndexSearcher extends I
}
/** Visit a document's fields using a {@link StoredFieldVisitor}
- * This method does not currently use the Solr document cache.
+ * This method does not currently add to the Solr document cache.
*
* @see IndexReader#document(int, StoredFieldVisitor) */
@Override
public void doc(int n, StoredFieldVisitor visitor) throws IOException {
+ if (documentCache != null) {
+ StoredDocument cached = documentCache.get(n);
+ if (cached != null) {
+ visitFromCached(cached, visitor);
+ return;
+ }
+ }
getIndexReader().document(n, visitor);
}
+
+ /** Executes a stored field visitor against a hit from the document cache */
+ private void visitFromCached(StoredDocument document, StoredFieldVisitor visitor) throws IOException {
+ for (StorableField f : document) {
+ FieldInfo info = fieldInfos.fieldInfo(f.name());
+ switch(visitor.needsField(info)) {
+ case YES:
+ if (f.binaryValue() != null) {
+ BytesRef binaryValue = f.binaryValue();
+ byte copy[] = new byte[binaryValue.length];
+ System.arraycopy(binaryValue.bytes, binaryValue.offset, copy, 0, copy.length);
+ visitor.binaryField(info, copy);
+ } else if (f.numericValue() != null) {
+ Number numericValue = f.numericValue();
+ if (numericValue instanceof Double) {
+ visitor.doubleField(info, numericValue.doubleValue());
+ } else if (numericValue instanceof Integer) {
+ visitor.intField(info, numericValue.intValue());
+ } else if (numericValue instanceof Float) {
+ visitor.floatField(info, numericValue.floatValue());
+ } else if (numericValue instanceof Long) {
+ visitor.longField(info, numericValue.longValue());
+ } else {
+ throw new AssertionError();
+ }
+ } else {
+ visitor.stringField(info, f.stringValue());
+ }
+ break;
+ case NO:
+ break;
+ case STOP:
+ return;
+ }
+ }
+ }
/**
* Retrieve the {@link Document} instance corresponding to the document id.
- *
- * Note: The document will have all fields accessable, but if a field
+ * <p>
+ * Note: The document will have all fields accessible, but if a field
* filter is provided, only the provided fields will be loaded (the
* remainder will be available lazily).
*/
+ @Override
public StoredDocument doc(int i, Set<String> fields) throws IOException {
StoredDocument d;
@@ -595,7 +648,7 @@ public class SolrIndexSearcher extends I
if (!termsEnum.seekExact(termBytes, false)) {
return -1;
}
- DocsEnum docs = termsEnum.docs(atomicReader.getLiveDocs(), null, 0);
+ DocsEnum docs = termsEnum.docs(atomicReader.getLiveDocs(), null, DocsEnum.FLAG_NONE);
if (docs == null) return -1;
int id = docs.nextDoc();
return id == DocIdSetIterator.NO_MORE_DOCS ? -1 : id;
@@ -617,7 +670,7 @@ public class SolrIndexSearcher extends I
TermsEnum te = terms.iterator(null);
if (te.seekExact(idBytes, true)) {
- DocsEnum docs = te.docs(reader.getLiveDocs(), null, 0);
+ DocsEnum docs = te.docs(reader.getLiveDocs(), null, DocsEnum.FLAG_NONE);
int id = docs.nextDoc();
if (id == DocIdSetIterator.NO_MORE_DOCS) continue;
assert docs.nextDoc() == DocIdSetIterator.NO_MORE_DOCS;
@@ -921,7 +974,7 @@ public class SolrIndexSearcher extends I
int bitsSet = 0;
OpenBitSet obs = null;
- DocsEnum docsEnum = deState.termsEnum.docs(deState.liveDocs, deState.docsEnum, 0);
+ DocsEnum docsEnum = deState.termsEnum.docs(deState.liveDocs, deState.docsEnum, DocsEnum.FLAG_NONE);
if (deState.docsEnum == null) {
deState.docsEnum = docsEnum;
}
@@ -999,7 +1052,7 @@ public class SolrIndexSearcher extends I
if (terms != null) {
final TermsEnum termsEnum = terms.iterator(null);
if (termsEnum.seekExact(termBytes, false)) {
- docsEnum = termsEnum.docs(liveDocs, null, 0);
+ docsEnum = termsEnum.docs(liveDocs, null, DocsEnum.FLAG_NONE);
}
}
@@ -1954,36 +2007,44 @@ public class SolrIndexSearcher extends I
// SolrInfoMBean stuff: Statistics and Module Info
/////////////////////////////////////////////////////////////////////
+ @Override
public String getName() {
return SolrIndexSearcher.class.getName();
}
+ @Override
public String getVersion() {
return SolrCore.version;
}
+ @Override
public String getDescription() {
return "index searcher";
}
+ @Override
public Category getCategory() {
return Category.CORE;
}
+ @Override
public String getSource() {
return "$URL$";
}
+ @Override
public URL[] getDocs() {
return null;
}
+ @Override
public NamedList<Object> getStatistics() {
NamedList<Object> lst = new SimpleOrderedMap<Object>();
lst.add("searcherName", name);
lst.add("caching", cachingEnabled);
lst.add("numDocs", reader.numDocs());
lst.add("maxDoc", reader.maxDoc());
+ lst.add("deletedDocs", reader.maxDoc() - reader.numDocs());
lst.add("reader", reader.toString());
lst.add("readerDir", reader.directory());
lst.add("indexVersion", reader.getVersion());
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java Fri Jan 18 18:30:54 2013
@@ -20,12 +20,9 @@ package org.apache.solr.search;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.lucene.analysis.util.TokenFilterFactory;
import org.apache.lucene.index.Term;
-import org.apache.lucene.queryparser.classic.ParseException;
-import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.util.ToStringUtils;
import org.apache.lucene.util.automaton.Automaton;
@@ -36,6 +33,8 @@ import org.apache.lucene.analysis.Analyz
import org.apache.solr.analysis.ReversedWildcardFilterFactory;
import org.apache.solr.analysis.TokenizerChain;
import org.apache.solr.common.SolrException;
+import org.apache.solr.parser.ParseException;
+import org.apache.solr.parser.QueryParser;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
@@ -43,215 +42,12 @@ import org.apache.solr.schema.TextField;
/**
- * A variation on the Lucene QueryParser which knows about the field
- * types and query time analyzers configured in Solr's schema.xml.
- *
- * <p>
- * This class also deviates from the Lucene QueryParser by using
- * ConstantScore versions of RangeQuery and PrefixQuery to prevent
- * TooManyClauses exceptions.
- * </p>
- *
- * <p>
- * If the magic field name "<code>_val_</code>" is used in a term or
- * phrase query, the value is parsed as a function.
- * </p>
+ * Solr's default query parser, a schema-driven superset of the classic lucene query parser.
*/
public class SolrQueryParser extends QueryParser {
- protected final IndexSchema schema;
- protected final QParser parser;
- protected final String defaultField;
-
- /**
- * Identifies the list of all known "magic fields" that trigger
- * special parsing behavior
- */
- public static enum MagicFieldName {
- VAL("_val_", "func"), QUERY("_query_", null);
-
- public final String field;
- public final String subParser;
- MagicFieldName(final String field, final String subParser) {
- this.field = field;
- this.subParser = subParser;
- }
- public String toString() {
- return field;
- }
- private final static Map<String,MagicFieldName> lookup
- = new HashMap<String,MagicFieldName>();
- static {
- for(MagicFieldName s : EnumSet.allOf(MagicFieldName.class))
- lookup.put(s.toString(), s);
- }
- public static MagicFieldName get(final String field) {
- return lookup.get(field);
- }
- }
-
- // implementation detail - caching ReversedWildcardFilterFactory based on type
- private Map<FieldType, ReversedWildcardFilterFactory> leadingWildcards;
public SolrQueryParser(QParser parser, String defaultField) {
- this(parser, defaultField, parser.getReq().getSchema().getQueryAnalyzer());
- }
-
- public SolrQueryParser(QParser parser, String defaultField, Analyzer analyzer) {
- super(parser.getReq().getCore().getSolrConfig().luceneMatchVersion, defaultField, analyzer);
- this.schema = parser.getReq().getSchema();
- this.parser = parser;
- this.defaultField = defaultField;
- setEnablePositionIncrements(true);
- setLowercaseExpandedTerms(false);
- setAllowLeadingWildcard(true);
- }
-
- protected ReversedWildcardFilterFactory getReversedWildcardFilterFactory(FieldType fieldType) {
- if (leadingWildcards == null) leadingWildcards = new HashMap<FieldType, ReversedWildcardFilterFactory>();
- ReversedWildcardFilterFactory fac = leadingWildcards.get(fieldType);
- if (fac == null && leadingWildcards.containsKey(fac)) {
- return fac;
- }
-
- Analyzer a = fieldType.getAnalyzer();
- if (a instanceof TokenizerChain) {
- // examine the indexing analysis chain if it supports leading wildcards
- TokenizerChain tc = (TokenizerChain)a;
- TokenFilterFactory[] factories = tc.getTokenFilterFactories();
- for (TokenFilterFactory factory : factories) {
- if (factory instanceof ReversedWildcardFilterFactory) {
- fac = (ReversedWildcardFilterFactory)factory;
- break;
- }
- }
- }
-
- leadingWildcards.put(fieldType, fac);
- return fac;
- }
-
-
- private void checkNullField(String field) throws SolrException {
- if (field == null && defaultField == null) {
- throw new SolrException
- (SolrException.ErrorCode.BAD_REQUEST,
- "no field name specified in query and no default specified via 'df' param");
- }
- }
-
- protected String analyzeIfMultitermTermText(String field, String part, FieldType fieldType) {
- if (part == null) return part;
-
- SchemaField sf = schema.getFieldOrNull((field));
- if (sf == null || ! (fieldType instanceof TextField)) return part;
- String out = TextField.analyzeMultiTerm(field, part, ((TextField)fieldType).getMultiTermAnalyzer()).utf8ToString();
- // System.out.println("INPUT="+part + " OUTPUT="+out);
- return out;
- }
-
- @Override
- protected Query getFieldQuery(String field, String queryText, boolean quoted) throws ParseException {
- checkNullField(field);
- // intercept magic field name of "_" to use as a hook for our
- // own functions.
- if (field.charAt(0) == '_' && parser != null) {
- MagicFieldName magic = MagicFieldName.get(field);
- if (null != magic) {
- QParser nested = parser.subQuery(queryText, magic.subParser);
- return nested.getQuery();
- }
- }
- SchemaField sf = schema.getFieldOrNull(field);
- if (sf != null) {
- FieldType ft = sf.getType();
- // delegate to type for everything except tokenized fields
- if (ft.isTokenized()) {
- return super.getFieldQuery(field, queryText, quoted || (ft instanceof TextField && ((TextField)ft).getAutoGeneratePhraseQueries()));
- } else {
- return sf.getType().getFieldQuery(parser, sf, queryText);
- }
- }
-
- // default to a normal field query
- return super.getFieldQuery(field, queryText, quoted);
- }
-
- @Override
- protected Query getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws ParseException {
- checkNullField(field);
- SchemaField sf = schema.getField(field);
- return sf.getType().getRangeQuery(parser, sf, part1, part2, startInclusive, endInclusive);
- }
-
- @Override
- protected Query getPrefixQuery(String field, String termStr) throws ParseException {
- checkNullField(field);
-
- termStr = analyzeIfMultitermTermText(field, termStr, schema.getFieldType(field));
-
- // Solr has always used constant scoring for prefix queries. This should return constant scoring by default.
- return newPrefixQuery(new Term(field, termStr));
- }
- @Override
- protected Query getWildcardQuery(String field, String termStr) throws ParseException {
- checkNullField(field);
- // *:* -> MatchAllDocsQuery
- if ("*".equals(field) && "*".equals(termStr)) {
- return newMatchAllDocsQuery();
- }
- FieldType fieldType = schema.getFieldType(field);
- termStr = analyzeIfMultitermTermText(field, termStr, fieldType);
- // can we use reversed wildcards in this field?
- ReversedWildcardFilterFactory factory = getReversedWildcardFilterFactory(fieldType);
- if (factory != null) {
- Term term = new Term(field, termStr);
- // fsa representing the query
- Automaton automaton = WildcardQuery.toAutomaton(term);
- // TODO: we should likely use the automaton to calculate shouldReverse, too.
- if (factory.shouldReverse(termStr)) {
- automaton = BasicOperations.concatenate(automaton, BasicAutomata.makeChar(factory.getMarkerChar()));
- SpecialOperations.reverse(automaton);
- } else {
- // reverse wildcardfilter is active: remove false positives
- // fsa representing false positives (markerChar*)
- Automaton falsePositives = BasicOperations.concatenate(
- BasicAutomata.makeChar(factory.getMarkerChar()),
- BasicAutomata.makeAnyString());
- // subtract these away
- automaton = BasicOperations.minus(automaton, falsePositives);
- }
- return new AutomatonQuery(term, automaton) {
- // override toString so its completely transparent
- @Override
- public String toString(String field) {
- StringBuilder buffer = new StringBuilder();
- if (!getField().equals(field)) {
- buffer.append(getField());
- buffer.append(":");
- }
- buffer.append(term.text());
- buffer.append(ToStringUtils.boost(getBoost()));
- return buffer.toString();
- }
- };
- }
-
- // Solr has always used constant scoring for wildcard queries. This should return constant scoring by default.
- return newWildcardQuery(new Term(field, termStr));
- }
-
- @Override
- protected Query getRegexpQuery(String field, String termStr) throws ParseException
- {
- termStr = analyzeIfMultitermTermText(field, termStr, schema.getFieldType(field));
- return newRegexpQuery(new Term(field, termStr));
- }
-
- @Override
- protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException {
- termStr = analyzeIfMultitermTermText(field, termStr, schema.getFieldType(field));
- Term t = new Term(field, termStr);
- return newFuzzyQuery(t, minSimilarity, getFuzzyPrefixLength());
+ super(parser.getReq().getCore().getSolrConfig().luceneMatchVersion, defaultField, parser);
}
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SortedIntDocSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SortedIntDocSet.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SortedIntDocSet.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SortedIntDocSet.java Fri Jan 18 18:30:54 2013
@@ -50,8 +50,10 @@ public class SortedIntDocSet extends Doc
public int[] getDocs() { return docs; }
+ @Override
public int size() { return docs.length; }
+ @Override
public long memSize() {
return (docs.length<<2)+8;
}
@@ -219,6 +221,7 @@ public class SortedIntDocSet extends Doc
return false;
}
+ @Override
public int intersectionSize(DocSet other) {
if (!(other instanceof SortedIntDocSet)) {
// assume other implementations are better at random access than we are,
@@ -567,6 +570,7 @@ public class SortedIntDocSet extends Doc
}
+ @Override
public boolean exists(int doc) {
// this could be faster by estimating where in the list the doc is likely to appear,
// but we should get away from using exists() anyway.
@@ -591,13 +595,16 @@ public class SortedIntDocSet extends Doc
}
+ @Override
public DocIterator iterator() {
return new DocIterator() {
int pos=0;
+ @Override
public boolean hasNext() {
return pos < docs.length;
}
+ @Override
public Integer next() {
return nextDoc();
}
@@ -605,14 +612,17 @@ public class SortedIntDocSet extends Doc
/**
* The remove operation is not supported by this Iterator.
*/
+ @Override
public void remove() {
throw new UnsupportedOperationException("The remove operation is not supported by this Iterator.");
}
+ @Override
public int nextDoc() {
return docs[pos++];
}
+ @Override
public float score() {
return 0.0f;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java Fri Jan 18 18:30:54 2013
@@ -17,7 +17,6 @@ package org.apache.solr.search;
*/
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import com.spatial4j.core.distance.DistanceUtils;
import org.apache.solr.common.SolrException;
@@ -44,7 +43,7 @@ public class SpatialFilterQParser extend
@Override
- public Query parse() throws ParseException {
+ public Query parse() throws SyntaxError {
//if more than one, we need to treat them as a point...
//TODO: Should we accept multiple fields
String[] fields = localParams.getParams("f");
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParserPlugin.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParserPlugin.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SpatialFilterQParserPlugin.java Fri Jan 18 18:30:54 2013
@@ -58,6 +58,7 @@ public class SpatialFilterQParserPlugin
return new SpatialFilterQParser(qstr, localParams, params, req, false);
}
+ @Override
public void init(NamedList args) {
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SurroundQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SurroundQParserPlugin.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SurroundQParserPlugin.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/SurroundQParserPlugin.java Fri Jan 18 18:30:54 2013
@@ -18,12 +18,10 @@ package org.apache.solr.search;
*/
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.solr.handler.SnapPuller;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.lucene.queryparser.surround.parser.*;
import org.apache.lucene.queryparser.surround.query.*;
@@ -74,7 +72,7 @@ class SurroundQParser extends QParser {
@Override
public Query parse()
- throws org.apache.lucene.queryparser.classic.ParseException {
+ throws SyntaxError {
SrndQuery sq;
String qstr = getString();
if (qstr == null)
@@ -95,8 +93,7 @@ class SurroundQParser extends QParser {
sq = org.apache.lucene.queryparser.surround.parser.QueryParser
.parse(qstr);
} catch (org.apache.lucene.queryparser.surround.parser.ParseException pe) {
- throw new org.apache.lucene.queryparser.classic.ParseException(
- pe.getMessage());
+ throw new SyntaxError(pe);
}
// so what do we do with the SrndQuery ??
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java Fri Jan 18 18:30:54 2013
@@ -43,6 +43,7 @@ import org.apache.solr.schema.FieldType;
public class TermQParserPlugin extends QParserPlugin {
public static String NAME = "term";
+ @Override
public void init(NamedList args) {
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java Fri Jan 18 18:30:54 2013
@@ -26,7 +26,6 @@ import org.apache.lucene.queries.functio
import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
import org.apache.lucene.queries.function.docvalues.LongDocValues;
import org.apache.lucene.queries.function.valuesource.*;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.SortField;
@@ -56,12 +55,13 @@ public abstract class ValueSourceParser
/**
* Initialize the plugin.
*/
+ @Override
public void init(NamedList args) {}
/**
* Parse the user input into a ValueSource.
*/
- public abstract ValueSource parse(FunctionQParser fp) throws ParseException;
+ public abstract ValueSource parse(FunctionQParser fp) throws SyntaxError;
/* standard functions */
public static Map<String, ValueSourceParser> standardValueSourceParsers = new HashMap<String, ValueSourceParser>();
@@ -87,33 +87,33 @@ public abstract class ValueSourceParser
static {
addParser("testfunc", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
final ValueSource source = fp.parseValueSource();
return new TestValueSource(source);
}
});
addParser("ord", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String field = fp.parseId();
return new OrdFieldSource(field);
}
});
addParser("literal", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
return new LiteralValueSource(fp.parseArg());
}
});
addParser("threadid", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
return new LongConstValueSource(Thread.currentThread().getId());
}
});
addParser("sleep", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
int ms = fp.parseInt();
ValueSource source = fp.parseValueSource();
try {
@@ -126,14 +126,14 @@ public abstract class ValueSourceParser
});
addParser("rord", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String field = fp.parseId();
return new ReverseOrdFieldSource(field);
}
});
addParser("top", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
// top(vs) is now a no-op
ValueSource source = fp.parseValueSource();
return source;
@@ -141,7 +141,7 @@ public abstract class ValueSourceParser
});
addParser("linear", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource source = fp.parseValueSource();
float slope = fp.parseFloat();
float intercept = fp.parseFloat();
@@ -150,7 +150,7 @@ public abstract class ValueSourceParser
});
addParser("recip", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource source = fp.parseValueSource();
float m = fp.parseFloat();
float a = fp.parseFloat();
@@ -160,7 +160,7 @@ public abstract class ValueSourceParser
});
addParser("scale", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource source = fp.parseValueSource();
float min = fp.parseFloat();
float max = fp.parseFloat();
@@ -169,7 +169,7 @@ public abstract class ValueSourceParser
});
addParser("div", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource a = fp.parseValueSource();
ValueSource b = fp.parseValueSource();
return new DivFloatFunction(a, b);
@@ -177,7 +177,7 @@ public abstract class ValueSourceParser
});
addParser("mod", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource a = fp.parseValueSource();
ValueSource b = fp.parseValueSource();
return new DualFloatFunction(a, b) {
@@ -194,7 +194,7 @@ public abstract class ValueSourceParser
});
addParser("map", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource source = fp.parseValueSource();
float min = fp.parseFloat();
float max = fp.parseFloat();
@@ -206,7 +206,7 @@ public abstract class ValueSourceParser
addParser("abs", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource source = fp.parseValueSource();
return new SimpleFloatFunction(source) {
@Override
@@ -223,7 +223,7 @@ public abstract class ValueSourceParser
});
addParser("sum", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new SumFloatFunction(sources.toArray(new ValueSource[sources.size()]));
}
@@ -232,7 +232,7 @@ public abstract class ValueSourceParser
addParser("product", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new ProductFloatFunction(sources.toArray(new ValueSource[sources.size()]));
}
@@ -241,7 +241,7 @@ public abstract class ValueSourceParser
addParser("sub", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource a = fp.parseValueSource();
ValueSource b = fp.parseValueSource();
return new DualFloatFunction(a, b) {
@@ -259,14 +259,14 @@ public abstract class ValueSourceParser
});
addParser("vector", new ValueSourceParser(){
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException{
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
return new VectorValueSource(fp.parseValueSourceList());
}
});
addParser("query", new ValueSourceParser() {
// boost(query($q),rating)
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
Query q = fp.parseNestedQuery();
float defVal = 0.0f;
if (fp.hasMoreArguments()) {
@@ -277,7 +277,7 @@ public abstract class ValueSourceParser
});
addParser("boost", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
Query q = fp.parseNestedQuery();
ValueSource vs = fp.parseValueSource();
BoostedQuery bq = new BoostedQuery(q, vs);
@@ -286,7 +286,7 @@ public abstract class ValueSourceParser
});
addParser("joindf", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String f0 = fp.parseArg();
String qf = fp.parseArg();
return new JoinDocFreqValueSource( f0, qf );
@@ -297,7 +297,7 @@ public abstract class ValueSourceParser
addParser("hsin", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
double radius = fp.parseDouble();
//SOLR-2114, make the convert flag required, since the parser doesn't support much in the way of lookahead or the ability to convert a String into a ValueSource
@@ -338,7 +338,7 @@ public abstract class ValueSourceParser
addParser("ghhsin", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
double radius = fp.parseDouble();
ValueSource gh1 = fp.parseValueSource();
@@ -350,7 +350,7 @@ public abstract class ValueSourceParser
addParser("geohash", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource lat = fp.parseValueSource();
ValueSource lon = fp.parseValueSource();
@@ -360,7 +360,7 @@ public abstract class ValueSourceParser
});
addParser("strdist", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource str1 = fp.parseValueSource();
ValueSource str2 = fp.parseValueSource();
@@ -385,7 +385,7 @@ public abstract class ValueSourceParser
});
addParser("field", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String fieldName = fp.parseArg();
SchemaField f = fp.getReq().getSchema().getField(fieldName);
@@ -527,21 +527,21 @@ public abstract class ValueSourceParser
});
addParser("max", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new MaxFloatFunction(sources.toArray(new ValueSource[sources.size()]));
}
});
addParser("min", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new MinFloatFunction(sources.toArray(new ValueSource[sources.size()]));
}
});
addParser("sqedist", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
MVResult mvr = getMultiValueSources(sources);
@@ -551,7 +551,7 @@ public abstract class ValueSourceParser
addParser("dist", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
float power = fp.parseFloat();
List<ValueSource> sources = fp.parseValueSourceList();
MVResult mvr = getMultiValueSources(sources);
@@ -577,7 +577,7 @@ public abstract class ValueSourceParser
addParser("docfreq", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
TInfo tinfo = parseTerm(fp);
return new DocFreqValueSource(tinfo.field, tinfo.val, tinfo.indexedField, tinfo.indexedBytes);
}
@@ -585,7 +585,7 @@ public abstract class ValueSourceParser
addParser("totaltermfreq", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
TInfo tinfo = parseTerm(fp);
return new TotalTermFreqValueSource(tinfo.field, tinfo.val, tinfo.indexedField, tinfo.indexedBytes);
}
@@ -594,7 +594,7 @@ public abstract class ValueSourceParser
addParser("sumtotaltermfreq", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String field = fp.parseArg();
return new SumTotalTermFreqValueSource(field);
}
@@ -603,7 +603,7 @@ public abstract class ValueSourceParser
addParser("idf", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
TInfo tinfo = parseTerm(fp);
return new IDFValueSource(tinfo.field, tinfo.val, tinfo.indexedField, tinfo.indexedBytes);
}
@@ -611,7 +611,7 @@ public abstract class ValueSourceParser
addParser("termfreq", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
TInfo tinfo = parseTerm(fp);
return new TermFreqValueSource(tinfo.field, tinfo.val, tinfo.indexedField, tinfo.indexedBytes);
}
@@ -619,7 +619,7 @@ public abstract class ValueSourceParser
addParser("tf", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
TInfo tinfo = parseTerm(fp);
return new TFValueSource(tinfo.field, tinfo.val, tinfo.indexedField, tinfo.indexedBytes);
}
@@ -627,7 +627,7 @@ public abstract class ValueSourceParser
addParser("norm", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String field = fp.parseArg();
return new NormValueSource(field);
}
@@ -663,7 +663,7 @@ public abstract class ValueSourceParser
addParser("exists", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource vs = fp.parseValueSource();
return new SimpleBoolFunction(vs) {
@Override
@@ -680,7 +680,7 @@ public abstract class ValueSourceParser
addParser("not", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource vs = fp.parseValueSource();
return new SimpleBoolFunction(vs) {
@Override
@@ -698,7 +698,7 @@ public abstract class ValueSourceParser
addParser("and", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new MultiBoolFunction(sources) {
@Override
@@ -717,7 +717,7 @@ public abstract class ValueSourceParser
addParser("or", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new MultiBoolFunction(sources) {
@Override
@@ -736,7 +736,7 @@ public abstract class ValueSourceParser
addParser("xor", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
List<ValueSource> sources = fp.parseValueSourceList();
return new MultiBoolFunction(sources) {
@Override
@@ -758,7 +758,7 @@ public abstract class ValueSourceParser
addParser("if", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
ValueSource ifValueSource = fp.parseValueSource();
ValueSource trueValueSource = fp.parseValueSource();
ValueSource falseValueSource = fp.parseValueSource();
@@ -769,14 +769,14 @@ public abstract class ValueSourceParser
addParser("def", new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
return new DefFunction(fp.parseValueSourceList());
}
});
}
- private static TInfo parseTerm(FunctionQParser fp) throws ParseException {
+ private static TInfo parseTerm(FunctionQParser fp) throws SyntaxError {
TInfo tinfo = new TInfo();
tinfo.indexedField = tinfo.field = fp.parseArg();
@@ -888,7 +888,7 @@ class DateValueSourceParser extends Valu
}
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String first = fp.parseArg();
String second = fp.parseArg();
if (first == null) first = "NOW";
@@ -1079,7 +1079,7 @@ abstract class DoubleParser extends Name
public abstract double func(int doc, FunctionValues vals);
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
return new Function(fp.parseValueSource());
}
@@ -1119,7 +1119,7 @@ abstract class Double2Parser extends Nam
public abstract double func(int doc, FunctionValues a, FunctionValues b);
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException {
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
return new Function(fp.parseValueSource(), fp.parseValueSource());
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java Fri Jan 18 18:30:54 2013
@@ -305,7 +305,7 @@ public class FileFloatSource extends Val
continue;
}
- docsEnum = termsEnum.docs(null, docsEnum, 0);
+ docsEnum = termsEnum.docs(null, docsEnum, DocsEnum.FLAG_NONE);
int doc;
while ((doc = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
vals[doc] = fval;
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java Fri Jan 18 18:30:54 2013
@@ -24,7 +24,6 @@ import org.apache.lucene.queries.functio
import org.apache.lucene.queries.function.valuesource.DoubleConstValueSource;
import org.apache.lucene.queries.function.valuesource.MultiValueSource;
import org.apache.lucene.queries.function.valuesource.VectorValueSource;
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.IndexSearcher;
import com.spatial4j.core.io.ParseUtils;
import com.spatial4j.core.distance.DistanceUtils;
@@ -32,6 +31,7 @@ import com.spatial4j.core.exception.Inva
import org.apache.solr.common.params.SpatialParams;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.FunctionQParser;
+import org.apache.solr.search.SyntaxError;
import org.apache.solr.search.ValueSourceParser;
import java.io.IOException;
@@ -48,7 +48,7 @@ public class HaversineConstFunction exte
public static ValueSourceParser parser = new ValueSourceParser() {
@Override
- public ValueSource parse(FunctionQParser fp) throws ParseException
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError
{
// TODO: dispatch through SpatialQueryable in the future?
List<ValueSource> sources = fp.parseValueSourceList();
@@ -65,7 +65,7 @@ public class HaversineConstFunction exte
} else if (sources.size() == 1) {
ValueSource vs = sources.get(0);
if (!(vs instanceof MultiValueSource)) {
- throw new ParseException("geodist - invalid parameters:" + sources);
+ throw new SyntaxError("geodist - invalid parameters:" + sources);
}
mv1 = (MultiValueSource)vs;
} else if (sources.size() == 2) {
@@ -88,7 +88,7 @@ public class HaversineConstFunction exte
mv1 = makeMV(sources.subList(0,2), sources);
vs1 = sources.get(2);
if (!(vs1 instanceof MultiValueSource)) {
- throw new ParseException("geodist - invalid parameters:" + sources);
+ throw new SyntaxError("geodist - invalid parameters:" + sources);
}
mv2 = (MultiValueSource)vs1;
}
@@ -96,7 +96,7 @@ public class HaversineConstFunction exte
mv1 = makeMV(sources.subList(0,2), sources);
mv2 = makeMV(sources.subList(2,4), sources);
} else if (sources.size() > 4) {
- throw new ParseException("geodist - invalid parameters:" + sources);
+ throw new SyntaxError("geodist - invalid parameters:" + sources);
}
if (mv1 == null) {
@@ -109,7 +109,7 @@ public class HaversineConstFunction exte
}
if (mv1 == null || mv2 == null) {
- throw new ParseException("geodist - not enough parameters:" + sources);
+ throw new SyntaxError("geodist - not enough parameters:" + sources);
}
// We have all the parameters at this point, now check if one of the points is constant
@@ -130,24 +130,24 @@ public class HaversineConstFunction exte
};
/** make a MultiValueSource from two non MultiValueSources */
- private static VectorValueSource makeMV(List<ValueSource> sources, List<ValueSource> orig) throws ParseException {
+ private static VectorValueSource makeMV(List<ValueSource> sources, List<ValueSource> orig) throws SyntaxError {
ValueSource vs1 = sources.get(0);
ValueSource vs2 = sources.get(1);
if (vs1 instanceof MultiValueSource || vs2 instanceof MultiValueSource) {
- throw new ParseException("geodist - invalid parameters:" + orig);
+ throw new SyntaxError("geodist - invalid parameters:" + orig);
}
return new VectorValueSource(sources);
}
- private static MultiValueSource parsePoint(FunctionQParser fp) throws ParseException {
+ private static MultiValueSource parsePoint(FunctionQParser fp) throws SyntaxError {
String pt = fp.getParam(SpatialParams.POINT);
if (pt == null) return null;
double[] point = null;
try {
point = ParseUtils.parseLatitudeLongitude(pt);
} catch (InvalidShapeException e) {
- throw new ParseException("Bad spatial pt:" + pt);
+ throw new SyntaxError("Bad spatial pt:" + pt);
}
return new VectorValueSource(Arrays.<ValueSource>asList(new DoubleConstValueSource(point[0]),new DoubleConstValueSource(point[1])));
}
@@ -161,13 +161,13 @@ public class HaversineConstFunction exte
return null;
}
- private static MultiValueSource parseSfield(FunctionQParser fp) throws ParseException {
+ private static MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
String sfield = fp.getParam(SpatialParams.FIELD);
if (sfield == null) return null;
SchemaField sf = fp.getReq().getSchema().getField(sfield);
ValueSource vs = sf.getType().getValueSource(sf, fp);
if (!(vs instanceof MultiValueSource)) {
- throw new ParseException("Spatial field must implement MultiValueSource:" + sf);
+ throw new SyntaxError("Spatial field must implement MultiValueSource:" + sf);
}
return (MultiValueSource)vs;
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java Fri Jan 18 18:30:54 2013
@@ -23,6 +23,7 @@ import org.apache.lucene.search.grouping
import org.apache.lucene.util.OpenBitSet;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.search.*;
+import org.apache.solr.search.SolrIndexSearcher.ProcessedFilter;
import org.apache.solr.search.QueryUtils;
import org.apache.solr.search.grouping.distributed.shardresultserializer.ShardResultTransformer;
import org.slf4j.Logger;
@@ -132,32 +133,30 @@ public class CommandHandler {
collectors.addAll(command.create());
}
- SolrIndexSearcher.ProcessedFilter pf = searcher.getProcessedFilter(
- queryCommand.getFilter(), queryCommand.getFilterList()
- );
- Filter luceneFilter = pf.filter;
+ ProcessedFilter filter = searcher.getProcessedFilter
+ (queryCommand.getFilter(), queryCommand.getFilterList());
Query query = QueryUtils.makeQueryable(queryCommand.getQuery());
if (truncateGroups) {
- docSet = computeGroupedDocSet(query, luceneFilter, collectors);
+ docSet = computeGroupedDocSet(query, filter, collectors);
} else if (needDocset) {
- docSet = computeDocSet(query, luceneFilter, collectors);
+ docSet = computeDocSet(query, filter, collectors);
} else if (!collectors.isEmpty()) {
- searchWithTimeLimiter(query, luceneFilter, MultiCollector.wrap(collectors.toArray(new Collector[nrOfCommands])));
+ searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[nrOfCommands])));
} else {
- searchWithTimeLimiter(query, luceneFilter, null);
+ searchWithTimeLimiter(query, filter, null);
}
}
- private DocSet computeGroupedDocSet(Query query, Filter luceneFilter, List<Collector> collectors) throws IOException {
+ private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
Command firstCommand = commands.get(0);
AbstractAllGroupHeadsCollector termAllGroupHeadsCollector =
TermAllGroupHeadsCollector.create(firstCommand.getKey(), firstCommand.getSortWithinGroup());
if (collectors.isEmpty()) {
- searchWithTimeLimiter(query, luceneFilter, termAllGroupHeadsCollector);
+ searchWithTimeLimiter(query, filter, termAllGroupHeadsCollector);
} else {
collectors.add(termAllGroupHeadsCollector);
- searchWithTimeLimiter(query, luceneFilter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
+ searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
}
int maxDoc = searcher.maxDoc();
@@ -165,7 +164,7 @@ public class CommandHandler {
return new BitDocSet(new OpenBitSet(bits, bits.length));
}
- private DocSet computeDocSet(Query query, Filter luceneFilter, List<Collector> collectors) throws IOException {
+ private DocSet computeDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
int maxDoc = searcher.maxDoc();
DocSetCollector docSetCollector;
if (collectors.isEmpty()) {
@@ -174,7 +173,7 @@ public class CommandHandler {
Collector wrappedCollectors = MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()]));
docSetCollector = new DocSetDelegateCollector(maxDoc >> 6, maxDoc, wrappedCollectors);
}
- searchWithTimeLimiter(query, luceneFilter, docSetCollector);
+ searchWithTimeLimiter(query, filter, docSetCollector);
return docSetCollector.getDocSet();
}
@@ -191,7 +190,9 @@ public class CommandHandler {
* Invokes search with the specified filter and collector.
* If a time limit has been specified then wrap the collector in the TimeLimitingCollector
*/
- private void searchWithTimeLimiter(final Query query, final Filter luceneFilter, Collector collector) throws IOException {
+ private void searchWithTimeLimiter(final Query query,
+ final ProcessedFilter filter,
+ Collector collector) throws IOException {
if (queryCommand.getTimeAllowed() > 0 ) {
collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), queryCommand.getTimeAllowed());
}
@@ -201,6 +202,12 @@ public class CommandHandler {
collector = MultiCollector.wrap(collector, hitCountCollector);
}
+ Filter luceneFilter = filter.filter;
+ if (filter.postFilter != null) {
+ filter.postFilter.setLastDelegate(collector);
+ collector = filter.postFilter;
+ }
+
try {
searcher.search(query, luceneFilter, collector);
} catch (TimeLimitingCollector.TimeExceededException x) {
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/collector/FilterCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/collector/FilterCollector.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/collector/FilterCollector.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/collector/FilterCollector.java Fri Jan 18 18:30:54 2013
@@ -41,10 +41,12 @@ public class FilterCollector extends Col
this.delegate = delegate;
}
+ @Override
public void setScorer(Scorer scorer) throws IOException {
delegate.setScorer(scorer);
}
+ @Override
public void collect(int doc) throws IOException {
matches++;
if (filter.exists(doc + docBase)) {
@@ -52,11 +54,13 @@ public class FilterCollector extends Col
}
}
+ @Override
public void setNextReader(AtomicReaderContext context) throws IOException {
this.docBase = context.docBase;
delegate.setNextReader(context);
}
+ @Override
public boolean acceptsDocsOutOfOrder() {
return delegate.acceptsDocsOutOfOrder();
}
Modified: lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/QueryCommand.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/QueryCommand.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/QueryCommand.java (original)
+++ lucene/dev/branches/LUCENE-2878/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/QueryCommand.java Fri Jan 18 18:30:54 2013
@@ -17,12 +17,12 @@ package org.apache.solr.search.grouping.
* limitations under the License.
*/
-import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.*;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.DocSet;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.SyntaxError;
import org.apache.solr.search.grouping.Command;
import org.apache.solr.search.grouping.collector.FilterCollector;
@@ -61,9 +61,8 @@ public class QueryCommand implements Com
* @param groupQueryString The group query string to parse
* @param request The current request
* @return this
- * @throws ParseException If parsing the groupQueryString failed
*/
- public Builder setQuery(String groupQueryString, SolrQueryRequest request) throws ParseException {
+ public Builder setQuery(String groupQueryString, SolrQueryRequest request) throws SyntaxError {
QParser parser = QParser.getParser(groupQueryString, null, request);
this.queryString = groupQueryString;
return setQuery(parser.getQuery());
@@ -124,6 +123,7 @@ public class QueryCommand implements Com
this.queryString = queryString;
}
+ @Override
public List<Collector> create() throws IOException {
if (sort == null || sort == Sort.RELEVANCE) {
collector = TopScoreDocCollector.create(docsToCollect, true);
@@ -134,18 +134,22 @@ public class QueryCommand implements Com
return Arrays.asList((Collector) filterCollector);
}
+ @Override
public QueryCommandResult result() {
return new QueryCommandResult(collector.topDocs(), filterCollector.getMatches());
}
+ @Override
public String getKey() {
return queryString != null ? queryString : query.toString();
}
+ @Override
public Sort getGroupSort() {
return sort;
}
+ @Override
public Sort getSortWithinGroup() {
return null;
}