SOLR-7219: add filter() to query syntax

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1694708 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2015-08-07 16:14:41 +00:00
parent 29e1d19b73
commit c61b8e7678
9 changed files with 569 additions and 121 deletions

View File

@ -100,6 +100,11 @@ New Features
http://localhost:8983/solr/admin/collections?action=MIGRATESTATEFORMAT&collection=<collection_name>
(Noble Paul, Scott Blum, shalin)
* SOLR-7219: filterCache access added to the solr query syntax.
Example: description:HDTV OR filter(+promotion:tv +promotion_date:[NOW/DAY TO NOW/DAY+7DAY])
(yonik)
Bug Fixes
----------------------

View File

@ -127,6 +127,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
case RANGEIN_START:
case RANGEEX_START:
case LPARAMS:
case FILTER:
case NUMBER:
;
break;
@ -198,8 +199,10 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
;
}
break;
case LPARAMS:
localParams = jj_consume_token(LPARAMS);
case FILTER:
jj_consume_token(FILTER);
q = Query(field);
jj_consume_token(RPAREN);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case CARAT:
jj_consume_token(CARAT);
@ -208,11 +211,24 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
default:
jj_la1[7] = jj_gen;
;
}
q=getFilter(q);
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[8] = jj_gen;
;
}
q=getLocalParams(field, localParams.image);
break;
default:
jj_la1[8] = jj_gen;
jj_la1[9] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -265,7 +281,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
term.image = term.image.substring(0,1);
break;
default:
jj_la1[9] = jj_gen;
jj_la1[10] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -275,7 +291,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
fuzzy=true;
break;
default:
jj_la1[10] = jj_gen;
jj_la1[11] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@ -288,12 +304,12 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
fuzzy=true;
break;
default:
jj_la1[11] = jj_gen;
jj_la1[12] = jj_gen;
;
}
break;
default:
jj_la1[12] = jj_gen;
jj_la1[13] = jj_gen;
;
}
q = handleBareTokenQuery(getField(field), term, fuzzySlop, prefix, wildcard, fuzzy, regexp);
@ -309,7 +325,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
jj_consume_token(RANGEEX_START);
break;
default:
jj_la1[13] = jj_gen;
jj_la1[14] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -321,7 +337,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
goop1 = jj_consume_token(RANGE_QUOTED);
break;
default:
jj_la1[14] = jj_gen;
jj_la1[15] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -330,7 +346,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
jj_consume_token(RANGE_TO);
break;
default:
jj_la1[15] = jj_gen;
jj_la1[16] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@ -341,7 +357,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
goop2 = jj_consume_token(RANGE_QUOTED);
break;
default:
jj_la1[16] = jj_gen;
jj_la1[17] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -354,7 +370,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
jj_consume_token(RANGEEX_END);
break;
default:
jj_la1[17] = jj_gen;
jj_la1[18] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -364,7 +380,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
boost = jj_consume_token(NUMBER);
break;
default:
jj_la1[18] = jj_gen;
jj_la1[19] = jj_gen;
;
}
boolean startOpen=false;
@ -388,7 +404,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
fuzzySlop = jj_consume_token(FUZZY_SLOP);
break;
default:
jj_la1[19] = jj_gen;
jj_la1[20] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@ -397,13 +413,13 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
boost = jj_consume_token(NUMBER);
break;
default:
jj_la1[20] = jj_gen;
jj_la1[21] = jj_gen;
;
}
q = handleQuotedTerm(getField(field), term, fuzzySlop);
break;
default:
jj_la1[21] = jj_gen;
jj_la1[22] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@ -450,7 +466,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
private Token jj_scanpos, jj_lastpos;
private int jj_la;
private int jj_gen;
final private int[] jj_la1 = new int[22];
final private int[] jj_la1 = new int[23];
static private int[] jj_la1_0;
static private int[] jj_la1_1;
static {
@ -458,10 +474,10 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
jj_la1_init_1();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0x6000,0x6000,0x38000,0x38000,0xfb4fe000,0x2400000,0x800000,0x800000,0xfb4c0000,0x3a440000,0x4000000,0x4000000,0x800000,0xc0000000,0x0,0x0,0x0,0x0,0x800000,0x4000000,0x800000,0xfb440000,};
jj_la1_0 = new int[] {0x6000,0x6000,0x38000,0x38000,0xfb4fe000,0x2400000,0x800000,0x800000,0x800000,0xfb4c0000,0x3a440000,0x4000000,0x4000000,0x800000,0xc0000000,0x0,0x0,0x0,0x0,0x800000,0x4000000,0x800000,0xfb440000,};
}
private static void jj_la1_init_1() {
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x3,0x2,0x0,0x0,0x0,0x0,0x60,0x4,0x60,0x18,0x0,0x0,0x0,0x2,};
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0x0,0x7,0x4,0x0,0x0,0x0,0x0,0xc0,0x8,0xc0,0x30,0x0,0x0,0x0,0x4,};
}
final private JJCalls[] jj_2_rtns = new JJCalls[1];
private boolean jj_rescan = false;
@ -473,7 +489,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
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 < 23; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@ -483,7 +499,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
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 < 23; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@ -493,7 +509,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
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 < 23; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@ -503,7 +519,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
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 < 23; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@ -615,12 +631,12 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
/** Generate ParseException. */
public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[39];
boolean[] la1tokens = new boolean[40];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 22; i++) {
for (int i = 0; i < 23; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
@ -632,7 +648,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
}
}
}
for (int i = 0; i < 39; i++) {
for (int i = 0; i < 40; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;

View File

@ -118,6 +118,7 @@ TOKEN_MGR_DECLS : {
// | <SQUOTED: "'" (<_SQUOTED_CHAR>)* "'">
// | <LPARAMS: ("{!" ( (<_WHITESPACE>)* (~["=","}"])+ ( "=" (<QUOTED> | <SQUOTED> | (~[" ","}"])+ )? )? )* "}")+ (~[")"," ","\t","\n","{","^"])* >
| <LPARAMS: ("{!" ( (<_WHITESPACE>)* (~["=","}"])+ ( "=" (<QUOTED> | ("'" (<_SQUOTED_CHAR>)* "'") | (~[" ","}"])+ )? )? )* "}")+ (~[")"," ","\t","\n","{","^"])* >
| <FILTER: "filter(" >
}
<Boost> TOKEN : {
@ -215,6 +216,7 @@ Query Clause(String field) throws SyntaxError : {
(
q=Term(field)
| <LPAREN> q=Query(field) <RPAREN> (<CARAT> boost=<NUMBER>)?
| (<FILTER> q=Query(field) <RPAREN> (<CARAT> boost=<NUMBER>)? { q=getFilter(q); } )
| (localParams = <LPARAMS> (<CARAT> boost=<NUMBER>)? { q=getLocalParams(field, localParams.image); } )
)
{ return handleBoost(q, boost); }

View File

@ -65,17 +65,19 @@ public interface QueryParserConstants {
/** RegularExpression Id. */
int LPARAMS = 32;
/** RegularExpression Id. */
int NUMBER = 33;
int FILTER = 33;
/** RegularExpression Id. */
int RANGE_TO = 34;
int NUMBER = 34;
/** RegularExpression Id. */
int RANGEIN_END = 35;
int RANGE_TO = 35;
/** RegularExpression Id. */
int RANGEEX_END = 36;
int RANGEIN_END = 36;
/** RegularExpression Id. */
int RANGE_QUOTED = 37;
int RANGEEX_END = 37;
/** RegularExpression Id. */
int RANGE_GOOP = 38;
int RANGE_QUOTED = 38;
/** RegularExpression Id. */
int RANGE_GOOP = 39;
/** Lexical state. */
int Boost = 0;
@ -121,6 +123,7 @@ public interface QueryParserConstants {
"\"[\"",
"\"{\"",
"<LPARAMS>",
"\"filter(\"",
"<NUMBER>",
"\"TO\"",
"\"]\"",

View File

@ -32,11 +32,56 @@ private final int jjStopStringLiteralDfa_3(int pos, long active0)
return 36;
if ((active0 & 0x200L) != 0L)
return 31;
if ((active0 & 0x400000L) != 0L)
if ((active0 & 0x200000000L) != 0L)
{
jjmatchedKind = 25;
return 62;
}
if ((active0 & 0x400000L) != 0L)
return 63;
if ((active0 & 0x30000L) != 0L)
return 15;
return -1;
case 1:
if ((active0 & 0x200000000L) != 0L)
{
jjmatchedKind = 25;
jjmatchedPos = 1;
return 62;
}
return -1;
case 2:
if ((active0 & 0x200000000L) != 0L)
{
jjmatchedKind = 25;
jjmatchedPos = 2;
return 62;
}
return -1;
case 3:
if ((active0 & 0x200000000L) != 0L)
{
jjmatchedKind = 25;
jjmatchedPos = 3;
return 62;
}
return -1;
case 4:
if ((active0 & 0x200000000L) != 0L)
{
jjmatchedKind = 25;
jjmatchedPos = 4;
return 62;
}
return -1;
case 5:
if ((active0 & 0x200000000L) != 0L)
{
jjmatchedKind = 25;
jjmatchedPos = 5;
return 62;
}
return -1;
default :
return -1;
}
@ -60,7 +105,7 @@ private int jjMoveStringLiteralDfa0_3()
case 41:
return jjStopAtPos(0, 20);
case 42:
return jjStartNfaWithStates_3(0, 22, 62);
return jjStartNfaWithStates_3(0, 22, 63);
case 43:
return jjStartNfaWithStates_3(0, 16, 15);
case 45:
@ -73,6 +118,8 @@ private int jjMoveStringLiteralDfa0_3()
return jjStopAtPos(0, 30);
case 94:
return jjStopAtPos(0, 23);
case 102:
return jjMoveStringLiteralDfa1_3(0x200000000L);
case 123:
return jjStartNfaWithStates_3(0, 31, 36);
default :
@ -92,11 +139,105 @@ private int jjMoveStringLiteralDfa1_3(long active0)
if ((active0 & 0x200L) != 0L)
return jjStopAtPos(1, 9);
break;
case 105:
return jjMoveStringLiteralDfa2_3(active0, 0x200000000L);
default :
break;
}
return jjStartNfa_3(0, active0);
}
private int jjMoveStringLiteralDfa2_3(long old0, long active0)
{
if (((active0 &= old0)) == 0L)
return jjStartNfa_3(0, old0);
try { curChar = input_stream.readChar(); }
catch(java.io.IOException e) {
jjStopStringLiteralDfa_3(1, active0);
return 2;
}
switch(curChar)
{
case 108:
return jjMoveStringLiteralDfa3_3(active0, 0x200000000L);
default :
break;
}
return jjStartNfa_3(1, active0);
}
private int jjMoveStringLiteralDfa3_3(long old0, long active0)
{
if (((active0 &= old0)) == 0L)
return jjStartNfa_3(1, old0);
try { curChar = input_stream.readChar(); }
catch(java.io.IOException e) {
jjStopStringLiteralDfa_3(2, active0);
return 3;
}
switch(curChar)
{
case 116:
return jjMoveStringLiteralDfa4_3(active0, 0x200000000L);
default :
break;
}
return jjStartNfa_3(2, active0);
}
private int jjMoveStringLiteralDfa4_3(long old0, long active0)
{
if (((active0 &= old0)) == 0L)
return jjStartNfa_3(2, old0);
try { curChar = input_stream.readChar(); }
catch(java.io.IOException e) {
jjStopStringLiteralDfa_3(3, active0);
return 4;
}
switch(curChar)
{
case 101:
return jjMoveStringLiteralDfa5_3(active0, 0x200000000L);
default :
break;
}
return jjStartNfa_3(3, active0);
}
private int jjMoveStringLiteralDfa5_3(long old0, long active0)
{
if (((active0 &= old0)) == 0L)
return jjStartNfa_3(3, old0);
try { curChar = input_stream.readChar(); }
catch(java.io.IOException e) {
jjStopStringLiteralDfa_3(4, active0);
return 5;
}
switch(curChar)
{
case 114:
return jjMoveStringLiteralDfa6_3(active0, 0x200000000L);
default :
break;
}
return jjStartNfa_3(4, active0);
}
private int jjMoveStringLiteralDfa6_3(long old0, long active0)
{
if (((active0 &= old0)) == 0L)
return jjStartNfa_3(4, old0);
try { curChar = input_stream.readChar(); }
catch(java.io.IOException e) {
jjStopStringLiteralDfa_3(5, active0);
return 6;
}
switch(curChar)
{
case 40:
if ((active0 & 0x200000000L) != 0L)
return jjStopAtPos(6, 33);
break;
default :
break;
}
return jjStartNfa_3(5, active0);
}
private int jjStartNfaWithStates_3(int pos, int kind, int state)
{
jjmatchedKind = kind;
@ -135,7 +276,7 @@ private int jjMoveNfa_3(int startState, int curPos)
{
switch(jjstateSet[--i])
{
case 62:
case 63:
case 27:
if ((0xfbfffcfaffffd9ffL & l) == 0L)
break;
@ -143,6 +284,27 @@ private int jjMoveNfa_3(int startState, int curPos)
kind = 28;
jjCheckNAddTwoStates(27, 28);
break;
case 62:
if ((0xfbfffcfaffffd9ffL & l) != 0L)
{
if (kind > 28)
kind = 28;
jjCheckNAddTwoStates(27, 28);
}
if ((0x7bfff8faffffd9ffL & l) != 0L)
jjCheckNAddStates(0, 2);
else if (curChar == 42)
{
if (kind > 27)
kind = 27;
}
if ((0x7bfff8faffffd9ffL & l) != 0L)
{
if (kind > 25)
kind = 25;
jjCheckNAddTwoStates(55, 56);
}
break;
case 0:
if ((0xfbff54f8ffffd9ffL & l) != 0L)
{
@ -160,12 +322,12 @@ private int jjMoveNfa_3(int startState, int curPos)
else if (curChar == 47)
jjstateSet[jjnewStateCnt++] = 31;
else if (curChar == 34)
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
if ((0x7bff50f8ffffd9ffL & l) != 0L)
{
if (kind > 25)
kind = 25;
jjCheckNAddStates(3, 7);
jjCheckNAddStates(6, 10);
}
else if (curChar == 42)
{
@ -202,14 +364,14 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 16:
if (curChar == 34)
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
break;
case 17:
if ((0xfffffffbffffffffL & l) != 0L)
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
break;
case 19:
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
break;
case 20:
if (curChar == 34 && kind > 24)
@ -220,7 +382,7 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
if (kind > 26)
kind = 26;
jjAddStates(8, 9);
jjAddStates(11, 12);
break;
case 23:
if (curChar == 46)
@ -255,15 +417,15 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 31:
if ((0xffff7bffffffffffL & l) != 0L)
jjCheckNAddStates(10, 12);
jjCheckNAddStates(13, 15);
break;
case 32:
if ((0xffff7fffffffffffL & l) != 0L)
jjCheckNAddStates(10, 12);
jjCheckNAddStates(13, 15);
break;
case 33:
if (curChar == 47)
jjCheckNAddStates(10, 12);
jjCheckNAddStates(13, 15);
break;
case 35:
if (curChar == 47 && kind > 29)
@ -271,7 +433,7 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 36:
if (curChar == 33)
jjCheckNAddStates(13, 15);
jjCheckNAddStates(16, 18);
break;
case 37:
if ((0x100002600L & l) != 0L)
@ -279,26 +441,26 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 38:
if ((0xdfffffffffffffffL & l) != 0L)
jjCheckNAddStates(16, 19);
jjCheckNAddStates(19, 22);
break;
case 39:
if (curChar == 61)
jjCheckNAddStates(20, 25);
jjCheckNAddStates(23, 28);
break;
case 40:
if (curChar == 34)
jjCheckNAddStates(26, 28);
jjCheckNAddStates(29, 31);
break;
case 41:
if ((0xfffffffbffffffffL & l) != 0L)
jjCheckNAddStates(26, 28);
jjCheckNAddStates(29, 31);
break;
case 43:
jjCheckNAddStates(26, 28);
jjCheckNAddStates(29, 31);
break;
case 44:
if (curChar == 34)
jjCheckNAddStates(13, 15);
jjCheckNAddStates(16, 18);
break;
case 47:
if ((0xfffffdfefffff9ffL & l) == 0L)
@ -309,29 +471,29 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 48:
if (curChar == 39)
jjCheckNAddStates(29, 31);
jjCheckNAddStates(32, 34);
break;
case 49:
if ((0xffffff7fffffffffL & l) != 0L)
jjCheckNAddStates(29, 31);
jjCheckNAddStates(32, 34);
break;
case 51:
jjCheckNAddStates(29, 31);
jjCheckNAddStates(32, 34);
break;
case 52:
if (curChar == 39)
jjCheckNAddStates(13, 15);
jjCheckNAddStates(16, 18);
break;
case 53:
if ((0xfffffffeffffffffL & l) != 0L)
jjCheckNAddStates(32, 35);
jjCheckNAddStates(35, 38);
break;
case 54:
if ((0x7bff50f8ffffd9ffL & l) == 0L)
break;
if (kind > 25)
kind = 25;
jjCheckNAddStates(3, 7);
jjCheckNAddStates(6, 10);
break;
case 55:
if ((0x7bfff8faffffd9ffL & l) == 0L)
@ -347,10 +509,10 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 58:
if ((0x7bfff8faffffd9ffL & l) != 0L)
jjCheckNAddStates(36, 38);
jjCheckNAddStates(0, 2);
break;
case 60:
jjCheckNAddStates(36, 38);
jjCheckNAddStates(0, 2);
break;
default : break;
}
@ -363,7 +525,7 @@ private int jjMoveNfa_3(int startState, int curPos)
{
switch(jjstateSet[--i])
{
case 62:
case 63:
if ((0x97ffffff87ffffffL & l) != 0L)
{
if (kind > 28)
@ -373,12 +535,34 @@ private int jjMoveNfa_3(int startState, int curPos)
else if (curChar == 92)
jjCheckNAddTwoStates(29, 29);
break;
case 62:
if ((0x97ffffff87ffffffL & l) != 0L)
{
if (kind > 28)
kind = 28;
jjCheckNAddTwoStates(27, 28);
}
else if (curChar == 92)
jjCheckNAddTwoStates(57, 57);
if ((0x97ffffff87ffffffL & l) != 0L)
jjCheckNAddStates(0, 2);
else if (curChar == 92)
jjCheckNAddTwoStates(60, 60);
if ((0x97ffffff87ffffffL & l) != 0L)
{
if (kind > 25)
kind = 25;
jjCheckNAddTwoStates(55, 56);
}
else if (curChar == 92)
jjCheckNAddTwoStates(29, 29);
break;
case 0:
if ((0x97ffffff87ffffffL & l) != 0L)
{
if (kind > 25)
kind = 25;
jjCheckNAddStates(3, 7);
jjCheckNAddStates(6, 10);
}
else if (curChar == 92)
jjCheckNAddStates(39, 41);
@ -447,14 +631,14 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 17:
if ((0xffffffffefffffffL & l) != 0L)
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
break;
case 18:
if (curChar == 92)
jjstateSet[jjnewStateCnt++] = 19;
break;
case 19:
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
break;
case 21:
if (curChar != 126)
@ -488,7 +672,7 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 31:
case 32:
jjCheckNAddStates(10, 12);
jjCheckNAddStates(13, 15);
break;
case 34:
if (curChar == 92)
@ -496,18 +680,18 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 38:
if ((0xdfffffffffffffffL & l) != 0L)
jjCheckNAddStates(16, 19);
jjCheckNAddStates(19, 22);
break;
case 41:
if ((0xffffffffefffffffL & l) != 0L)
jjCheckNAddStates(26, 28);
jjCheckNAddStates(29, 31);
break;
case 42:
if (curChar == 92)
jjstateSet[jjnewStateCnt++] = 43;
break;
case 43:
jjCheckNAddStates(26, 28);
jjCheckNAddStates(29, 31);
break;
case 45:
if (curChar != 125)
@ -529,25 +713,25 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 49:
if ((0xffffffffefffffffL & l) != 0L)
jjCheckNAddStates(29, 31);
jjCheckNAddStates(32, 34);
break;
case 50:
if (curChar == 92)
jjstateSet[jjnewStateCnt++] = 51;
break;
case 51:
jjCheckNAddStates(29, 31);
jjCheckNAddStates(32, 34);
break;
case 53:
if ((0xdfffffffffffffffL & l) != 0L)
jjCheckNAddStates(32, 35);
jjCheckNAddStates(35, 38);
break;
case 54:
if ((0x97ffffff87ffffffL & l) == 0L)
break;
if (kind > 25)
kind = 25;
jjCheckNAddStates(3, 7);
jjCheckNAddStates(6, 10);
break;
case 55:
if ((0x97ffffff87ffffffL & l) == 0L)
@ -567,14 +751,14 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 58:
if ((0x97ffffff87ffffffL & l) != 0L)
jjCheckNAddStates(36, 38);
jjCheckNAddStates(0, 2);
break;
case 59:
if (curChar == 92)
jjCheckNAddTwoStates(60, 60);
break;
case 60:
jjCheckNAddStates(36, 38);
jjCheckNAddStates(0, 2);
break;
case 61:
if (curChar == 92)
@ -595,7 +779,7 @@ private int jjMoveNfa_3(int startState, int curPos)
{
switch(jjstateSet[--i])
{
case 62:
case 63:
case 27:
if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
break;
@ -603,6 +787,22 @@ private int jjMoveNfa_3(int startState, int curPos)
kind = 28;
jjCheckNAddTwoStates(27, 28);
break;
case 62:
if (jjCanMove_2(hiByte, i1, i2, l1, l2))
{
if (kind > 25)
kind = 25;
jjCheckNAddTwoStates(55, 56);
}
if (jjCanMove_2(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(0, 2);
if (jjCanMove_2(hiByte, i1, i2, l1, l2))
{
if (kind > 28)
kind = 28;
jjCheckNAddTwoStates(27, 28);
}
break;
case 0:
if (jjCanMove_0(hiByte, i1, i2, l1, l2))
{
@ -619,7 +819,7 @@ private int jjMoveNfa_3(int startState, int curPos)
{
if (kind > 25)
kind = 25;
jjCheckNAddStates(3, 7);
jjCheckNAddStates(6, 10);
}
break;
case 15:
@ -629,7 +829,7 @@ private int jjMoveNfa_3(int startState, int curPos)
case 17:
case 19:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(0, 2);
jjCheckNAddStates(3, 5);
break;
case 26:
if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
@ -648,7 +848,7 @@ private int jjMoveNfa_3(int startState, int curPos)
case 31:
case 32:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(10, 12);
jjCheckNAddStates(13, 15);
break;
case 37:
if (jjCanMove_0(hiByte, i1, i2, l1, l2))
@ -656,12 +856,12 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 38:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(16, 19);
jjCheckNAddStates(19, 22);
break;
case 41:
case 43:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(26, 28);
jjCheckNAddStates(29, 31);
break;
case 47:
if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
@ -673,18 +873,18 @@ private int jjMoveNfa_3(int startState, int curPos)
case 49:
case 51:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(29, 31);
jjCheckNAddStates(32, 34);
break;
case 53:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(32, 35);
jjCheckNAddStates(35, 38);
break;
case 54:
if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
break;
if (kind > 25)
kind = 25;
jjCheckNAddStates(3, 7);
jjCheckNAddStates(6, 10);
break;
case 55:
if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
@ -702,11 +902,11 @@ private int jjMoveNfa_3(int startState, int curPos)
break;
case 58:
if (jjCanMove_2(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(36, 38);
jjCheckNAddStates(0, 2);
break;
case 60:
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
jjCheckNAddStates(36, 38);
jjCheckNAddStates(0, 2);
break;
default : break;
}
@ -865,8 +1065,8 @@ private int jjMoveNfa_0(int startState, int curPos)
case 0:
if ((0x3ff000000000000L & l) != 0L)
{
if (kind > 33)
kind = 33;
if (kind > 34)
kind = 34;
jjCheckNAddTwoStates(2, 3);
}
else if (curChar == 45)
@ -881,8 +1081,8 @@ private int jjMoveNfa_0(int startState, int curPos)
case 2:
if ((0x3ff000000000000L & l) == 0L)
break;
if (kind > 33)
kind = 33;
if (kind > 34)
kind = 34;
jjCheckNAddTwoStates(2, 3);
break;
case 3:
@ -892,8 +1092,8 @@ private int jjMoveNfa_0(int startState, int curPos)
case 4:
if ((0x3ff000000000000L & l) == 0L)
break;
if (kind > 33)
kind = 33;
if (kind > 34)
kind = 34;
jjCheckNAdd(4);
break;
default : break;
@ -944,9 +1144,9 @@ private final int jjStopStringLiteralDfa_1(int pos, long active0)
switch (pos)
{
case 0:
if ((active0 & 0x400000000L) != 0L)
if ((active0 & 0x800000000L) != 0L)
{
jjmatchedKind = 38;
jjmatchedKind = 39;
return 6;
}
return -1;
@ -963,11 +1163,11 @@ private int jjMoveStringLiteralDfa0_1()
switch(curChar)
{
case 84:
return jjMoveStringLiteralDfa1_1(0x400000000L);
return jjMoveStringLiteralDfa1_1(0x800000000L);
case 93:
return jjStopAtPos(0, 35);
case 125:
return jjStopAtPos(0, 36);
case 125:
return jjStopAtPos(0, 37);
default :
return jjMoveNfa_1(0, 0);
}
@ -982,8 +1182,8 @@ private int jjMoveStringLiteralDfa1_1(long active0)
switch(curChar)
{
case 79:
if ((active0 & 0x400000000L) != 0L)
return jjStartNfaWithStates_1(1, 34, 6);
if ((active0 & 0x800000000L) != 0L)
return jjStartNfaWithStates_1(1, 35, 6);
break;
default :
break;
@ -1019,8 +1219,8 @@ private int jjMoveNfa_1(int startState, int curPos)
case 0:
if ((0xfffffffeffffffffL & l) != 0L)
{
if (kind > 38)
kind = 38;
if (kind > 39)
kind = 39;
jjCheckNAdd(6);
}
if ((0x100002600L & l) != 0L)
@ -1044,14 +1244,14 @@ private int jjMoveNfa_1(int startState, int curPos)
jjCheckNAddStates(42, 44);
break;
case 5:
if (curChar == 34 && kind > 37)
kind = 37;
if (curChar == 34 && kind > 38)
kind = 38;
break;
case 6:
if ((0xfffffffeffffffffL & l) == 0L)
break;
if (kind > 38)
kind = 38;
if (kind > 39)
kind = 39;
jjCheckNAdd(6);
break;
default : break;
@ -1069,8 +1269,8 @@ private int jjMoveNfa_1(int startState, int curPos)
case 6:
if ((0xdfffffffdfffffffL & l) == 0L)
break;
if (kind > 38)
kind = 38;
if (kind > 39)
kind = 39;
jjCheckNAdd(6);
break;
case 2:
@ -1103,8 +1303,8 @@ private int jjMoveNfa_1(int startState, int curPos)
}
if (jjCanMove_1(hiByte, i1, i2, l1, l2))
{
if (kind > 38)
kind = 38;
if (kind > 39)
kind = 39;
jjCheckNAdd(6);
}
break;
@ -1115,8 +1315,8 @@ private int jjMoveNfa_1(int startState, int curPos)
case 6:
if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
break;
if (kind > 38)
kind = 38;
if (kind > 39)
kind = 39;
jjCheckNAdd(6);
break;
default : break;
@ -1137,9 +1337,9 @@ private int jjMoveNfa_1(int startState, int curPos)
}
}
static final int[] jjnextStates = {
17, 18, 20, 55, 58, 25, 59, 56, 22, 23, 32, 34, 35, 37, 38, 45,
37, 38, 39, 45, 37, 38, 40, 48, 53, 45, 41, 42, 44, 49, 50, 52,
37, 38, 53, 45, 58, 25, 59, 57, 60, 29, 2, 4, 5,
58, 25, 59, 17, 18, 20, 55, 58, 25, 59, 56, 22, 23, 32, 34, 35,
37, 38, 45, 37, 38, 39, 45, 37, 38, 40, 48, 53, 45, 41, 42, 44,
49, 50, 52, 37, 38, 53, 45, 57, 60, 29, 2, 4, 5,
};
private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
{
@ -1182,8 +1382,8 @@ private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, lo
public static final String[] jjstrLiteralImages = {
"", null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, "\53", "\55", null, "\50", "\51", "\72", "\52", "\136", null, null,
null, null, null, null, "\133", "\173", null, null, "\124\117", "\135", "\175", null,
null, };
null, null, null, null, "\133", "\173", null, "\146\151\154\164\145\162\50", null,
"\124\117", "\135", "\175", null, null, };
/** Lexer state names. */
public static final String[] lexStateNames = {
@ -1196,10 +1396,10 @@ public static final String[] lexStateNames = {
/** Lex State array. */
public static final int[] jjnewLexState = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1,
-1, -1, -1, -1, -1, 1, 1, -1, 3, -1, 3, 3, -1, -1,
-1, -1, -1, -1, -1, 1, 1, -1, -1, 3, -1, 3, 3, -1, -1,
};
static final long[] jjtoToken = {
0x7fffffe001L,
0xffffffe001L,
};
static final long[] jjtoSkip = {
0x1f00L,

View File

@ -48,11 +48,13 @@ import org.apache.solr.analysis.ReversedWildcardFilterFactory;
import org.apache.solr.analysis.TokenizerChain;
import org.apache.solr.common.SolrException;
import org.apache.solr.parser.QueryParser.Operator;
import org.apache.solr.query.FilterQuery;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.TextField;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SolrConstantScoreQuery;
import org.apache.solr.search.SyntaxError;
/** This class is overridden by QueryParser in QueryParser.jj
@ -566,13 +568,11 @@ public abstract class SolrQueryParserBase extends QueryBuilder {
if (boost == null || boost.image.length()==0 || q == null) {
return q;
}
if (boost.image.charAt(0) == '=') {
// syntax looks like foo:x^=3
float val = Float.parseFloat(boost.image.substring(1));
Query newQ = q;
if (// q instanceof FilterQuery || // TODO: fix this when FilterQuery is introduced to avoid needless wrapping: SOLR-7219
q instanceof ConstantScoreQuery) {
if (q instanceof FilterQuery || q instanceof ConstantScoreQuery || q instanceof SolrConstantScoreQuery) {
newQ.setBoost(val);
} else {
newQ = new ConstantScoreQuery(q);
@ -851,4 +851,9 @@ public abstract class SolrQueryParserBase extends QueryBuilder {
return nested.getQuery();
}
// called from parser for filter(query)
Query getFilter(Query q) {
return new FilterQuery(q);
}
}

View File

@ -0,0 +1,98 @@
package org.apache.solr.query;
/*
* 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.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.ToStringUtils;
import org.apache.solr.search.DocSet;
import org.apache.solr.search.ExtendedQueryBase;
import org.apache.solr.search.SolrIndexSearcher;
public class FilterQuery extends ExtendedQueryBase {
protected final Query q;
public FilterQuery(Query q) {
this.q = q;
setBoost(0); // default boost is 0;
}
public Query getQuery() {
return q;
}
@Override
public int hashCode() {
return q.hashCode() + 0xc0e65615;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof FilterQuery)) return false;
FilterQuery fq = (FilterQuery)obj;
return this.q.equals(fq.q) && this.getBoost() == fq.getBoost();
}
@Override
public String toString(String field) {
StringBuilder sb = new StringBuilder();
sb.append("field(");
sb.append(q.toString(""));
sb.append(')');
sb.append(ToStringUtils.boost(getBoost()));
return sb.toString();
}
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query newQ = q.rewrite(reader);
if (newQ != q) {
FilterQuery fq = new FilterQuery(newQ);
fq.setBoost(this.getBoost());
return fq;
} else {
return this;
}
}
@Override
public Weight createWeight(IndexSearcher searcher, boolean needScores) throws IOException {
// SolrRequestInfo reqInfo = SolrRequestInfo.getRequestInfo();
if (!(searcher instanceof SolrIndexSearcher)) {
// delete-by-query won't have SolrIndexSearcher
ConstantScoreQuery csq = new ConstantScoreQuery(q);
csq.setBoost(this.getBoost());
return csq.createWeight(searcher, needScores);
}
SolrIndexSearcher solrSearcher = (SolrIndexSearcher)searcher;
DocSet docs = solrSearcher.getDocSet(q);
// reqInfo.addCloseHook(docs); // needed for off-heap refcounting
ConstantScoreQuery csq = new ConstantScoreQuery( docs.getTopFilter() );
csq.setBoost( this.getBoost() );
return csq.createWeight(searcher, needScores);
}
}

View File

@ -0,0 +1,27 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<!--
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.
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>
Solr Queries
</p>
</body>
</html>

View File

@ -19,6 +19,7 @@ package org.apache.solr.search;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.SolrInfoMBean;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.transform.ScoreAugmenter;
import org.junit.BeforeClass;
@ -197,8 +198,8 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
// don't match comment start in string
assertJQ(req("q"," \"/*\" id:1 id:2 \"*/\" id:3")
,"/response/numFound==3"
assertJQ(req("q", " \"/*\" id:1 id:2 \"*/\" id:3")
, "/response/numFound==3"
);
// don't match an end of comment within a string
@ -215,5 +216,96 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
}
@Test
public void testFilter() throws Exception {
// normal test "solrconfig.xml" has autowarm set to 2...
for (int i=0; i<10; i++) {
assertJQ(req("q","*:* "+ i, "fq","filter(just_to_clear_the_cache) filter(id:10000" + i + ") filter(id:10001" + i + ")")
,"/response/numFound==0"
);
}
assertU(adoc("id","777"));
delI("777");
assertU(commit()); // arg... commit no longer "commits" unless there has been a change.
final SolrInfoMBean filterCacheStats
= h.getCore().getInfoRegistry().get("filterCache");
assertNotNull(filterCacheStats);
final SolrInfoMBean queryCacheStats
= h.getCore().getInfoRegistry().get("queryResultCache");
assertNotNull(queryCacheStats);
long inserts = (Long) filterCacheStats.getStatistics().get("inserts");
long hits = (Long) filterCacheStats.getStatistics().get("hits");
assertJQ(req("q","doesnotexist filter(id:1) filter(qqq_s:X) filter(abcdefg)")
,"/response/numFound==2"
);
inserts+=3;
assertEquals(inserts, ((Long) filterCacheStats.getStatistics().get("inserts")).longValue() );
assertEquals(hits, ((Long) filterCacheStats.getStatistics().get("hits")).longValue() );
assertJQ(req("q","doesnotexist2 filter(id:1) filter(qqq_s:X) filter(abcdefg)")
,"/response/numFound==2"
);
hits+=3;
assertEquals(inserts, ((Long) filterCacheStats.getStatistics().get("inserts")).longValue() );
assertEquals(hits, ((Long) filterCacheStats.getStatistics().get("hits")).longValue() );
// make sure normal "fq" parameters also hit the cache the same way
assertJQ(req("q","doesnotexist3", "fq","id:1", "fq", "qqq_s:X", "fq", "abcdefg")
,"/response/numFound==0"
);
hits+=3;
assertEquals(inserts, ((Long) filterCacheStats.getStatistics().get("inserts")).longValue() );
assertEquals(hits, ((Long) filterCacheStats.getStatistics().get("hits")).longValue() );
// try a query deeply nested in a FQ
assertJQ(req("q","*:* doesnotexist4", "fq","(id:* +(filter(id:1) filter(qqq_s:X) filter(abcdefg)) )")
,"/response/numFound==2"
);
inserts+=1; // +1 for top level fq
hits+=3;
assertEquals(inserts, ((Long) filterCacheStats.getStatistics().get("inserts")).longValue() );
assertEquals(hits, ((Long) filterCacheStats.getStatistics().get("hits")).longValue() );
// retry the complex FQ and make sure hashCode/equals works as expected w/ filter queries
assertJQ(req("q","*:* doesnotexist5", "fq","(id:* +(filter(id:1) filter(qqq_s:X) filter(abcdefg)) )")
,"/response/numFound==2"
);
hits+=1; // top-level fq should have been found.
assertEquals(inserts, ((Long) filterCacheStats.getStatistics().get("inserts")).longValue() );
assertEquals(hits, ((Long) filterCacheStats.getStatistics().get("hits")).longValue() );
// try nested filter with multiple top-level args (i.e. a boolean query)
assertJQ(req("q","*:* +filter(id:1 filter(qqq_s:X) abcdefg)")
,"/response/numFound==2"
);
hits+=1; // the inner filter
inserts+=1; // the outer filter
assertEquals(inserts, ((Long) filterCacheStats.getStatistics().get("inserts")).longValue() );
assertEquals(hits, ((Long) filterCacheStats.getStatistics().get("hits")).longValue() );
// test the score for a filter, and that default score is 0
assertJQ(req("q","+filter(*:*) +filter(id:1)", "fl","id,score", "sort","id asc")
,"/response/docs/[0]/score==0.0"
);
assertJQ(req("q","+filter(*:*)^=10 +filter(id:1)", "fl","id,score", "sort","id asc")
,"/response/docs/[0]/score==1.0" // normalization reduces to 1
);
}
}