Merge pull request #544 from mschoch/work_on_query_string_parser
add ability to perform exact numeric matches
This commit is contained in:
commit
a7ebb84805
@ -127,7 +127,15 @@ tSTRING tCOLON tSTRING tTILDE {
|
||||
tNUMBER {
|
||||
str := $1
|
||||
logDebugGrammar("STRING - %s", str)
|
||||
q := NewMatchQuery(str)
|
||||
q1 := NewMatchQuery(str)
|
||||
val, err := strconv.ParseFloat($1, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
inclusive := true
|
||||
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||
q := NewDisjunctionQuery([]Query{q1,q2})
|
||||
q.queryStringMode = true
|
||||
$$ = q
|
||||
}
|
||||
|
|
||||
@ -158,8 +166,17 @@ tSTRING tCOLON tNUMBER {
|
||||
field := $1
|
||||
str := $3
|
||||
logDebugGrammar("FIELD - %s STRING - %s", field, str)
|
||||
q := NewMatchQuery(str)
|
||||
q.SetField(field)
|
||||
q1 := NewMatchQuery(str)
|
||||
q1.SetField(field)
|
||||
val, err := strconv.ParseFloat($3, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
inclusive := true
|
||||
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||
q2.SetField(field)
|
||||
q := NewDisjunctionQuery([]Query{q1,q2})
|
||||
q.queryStringMode = true
|
||||
$$ = q
|
||||
}
|
||||
|
|
||||
@ -174,7 +191,10 @@ tSTRING tCOLON tPHRASE {
|
||||
|
|
||||
tSTRING tCOLON tGREATER tNUMBER {
|
||||
field := $1
|
||||
min, _ := strconv.ParseFloat($4, 64)
|
||||
min, err := strconv.ParseFloat($4, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
minInclusive := false
|
||||
logDebugGrammar("FIELD - GREATER THAN %f", min)
|
||||
q := NewNumericRangeInclusiveQuery(&min, nil, &minInclusive, nil)
|
||||
@ -184,7 +204,10 @@ tSTRING tCOLON tGREATER tNUMBER {
|
||||
|
|
||||
tSTRING tCOLON tGREATER tEQUAL tNUMBER {
|
||||
field := $1
|
||||
min, _ := strconv.ParseFloat($5, 64)
|
||||
min, err := strconv.ParseFloat($5, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
minInclusive := true
|
||||
logDebugGrammar("FIELD - GREATER THAN OR EQUAL %f", min)
|
||||
q := NewNumericRangeInclusiveQuery(&min, nil, &minInclusive, nil)
|
||||
@ -194,7 +217,10 @@ tSTRING tCOLON tGREATER tEQUAL tNUMBER {
|
||||
|
|
||||
tSTRING tCOLON tLESS tNUMBER {
|
||||
field := $1
|
||||
max, _ := strconv.ParseFloat($4, 64)
|
||||
max, err := strconv.ParseFloat($4, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
maxInclusive := false
|
||||
logDebugGrammar("FIELD - LESS THAN %f", max)
|
||||
q := NewNumericRangeInclusiveQuery(nil, &max, nil, &maxInclusive)
|
||||
@ -204,7 +230,10 @@ tSTRING tCOLON tLESS tNUMBER {
|
||||
|
|
||||
tSTRING tCOLON tLESS tEQUAL tNUMBER {
|
||||
field := $1
|
||||
max, _ := strconv.ParseFloat($5, 64)
|
||||
max, err := strconv.ParseFloat($5, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
maxInclusive := true
|
||||
logDebugGrammar("FIELD - LESS THAN OR EQUAL %f", max)
|
||||
q := NewNumericRangeInclusiveQuery(nil, &max, nil, &maxInclusive)
|
||||
|
@ -581,12 +581,20 @@ yydefault:
|
||||
{
|
||||
str := yyDollar[1].s
|
||||
logDebugGrammar("STRING - %s", str)
|
||||
q := NewMatchQuery(str)
|
||||
q1 := NewMatchQuery(str)
|
||||
val, err := strconv.ParseFloat(yyDollar[1].s, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
inclusive := true
|
||||
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||
q := NewDisjunctionQuery([]Query{q1, q2})
|
||||
q.queryStringMode = true
|
||||
yyVAL.q = q
|
||||
}
|
||||
case 12:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
//line query_string.y:134
|
||||
//line query_string.y:142
|
||||
{
|
||||
phrase := yyDollar[1].s
|
||||
logDebugGrammar("PHRASE - %s", phrase)
|
||||
@ -595,7 +603,7 @@ yydefault:
|
||||
}
|
||||
case 13:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
//line query_string.y:141
|
||||
//line query_string.y:149
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
str := yyDollar[3].s
|
||||
@ -613,18 +621,27 @@ yydefault:
|
||||
}
|
||||
case 14:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
//line query_string.y:157
|
||||
//line query_string.y:165
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
str := yyDollar[3].s
|
||||
logDebugGrammar("FIELD - %s STRING - %s", field, str)
|
||||
q := NewMatchQuery(str)
|
||||
q.SetField(field)
|
||||
q1 := NewMatchQuery(str)
|
||||
q1.SetField(field)
|
||||
val, err := strconv.ParseFloat(yyDollar[3].s, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
inclusive := true
|
||||
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||
q2.SetField(field)
|
||||
q := NewDisjunctionQuery([]Query{q1, q2})
|
||||
q.queryStringMode = true
|
||||
yyVAL.q = q
|
||||
}
|
||||
case 15:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
//line query_string.y:166
|
||||
//line query_string.y:183
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
phrase := yyDollar[3].s
|
||||
@ -635,10 +652,13 @@ yydefault:
|
||||
}
|
||||
case 16:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line query_string.y:175
|
||||
//line query_string.y:192
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
min, _ := strconv.ParseFloat(yyDollar[4].s, 64)
|
||||
min, err := strconv.ParseFloat(yyDollar[4].s, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
minInclusive := false
|
||||
logDebugGrammar("FIELD - GREATER THAN %f", min)
|
||||
q := NewNumericRangeInclusiveQuery(&min, nil, &minInclusive, nil)
|
||||
@ -647,10 +667,13 @@ yydefault:
|
||||
}
|
||||
case 17:
|
||||
yyDollar = yyS[yypt-5 : yypt+1]
|
||||
//line query_string.y:185
|
||||
//line query_string.y:205
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
min, _ := strconv.ParseFloat(yyDollar[5].s, 64)
|
||||
min, err := strconv.ParseFloat(yyDollar[5].s, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
minInclusive := true
|
||||
logDebugGrammar("FIELD - GREATER THAN OR EQUAL %f", min)
|
||||
q := NewNumericRangeInclusiveQuery(&min, nil, &minInclusive, nil)
|
||||
@ -659,10 +682,13 @@ yydefault:
|
||||
}
|
||||
case 18:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line query_string.y:195
|
||||
//line query_string.y:218
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
max, _ := strconv.ParseFloat(yyDollar[4].s, 64)
|
||||
max, err := strconv.ParseFloat(yyDollar[4].s, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
maxInclusive := false
|
||||
logDebugGrammar("FIELD - LESS THAN %f", max)
|
||||
q := NewNumericRangeInclusiveQuery(nil, &max, nil, &maxInclusive)
|
||||
@ -671,10 +697,13 @@ yydefault:
|
||||
}
|
||||
case 19:
|
||||
yyDollar = yyS[yypt-5 : yypt+1]
|
||||
//line query_string.y:205
|
||||
//line query_string.y:231
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
max, _ := strconv.ParseFloat(yyDollar[5].s, 64)
|
||||
max, err := strconv.ParseFloat(yyDollar[5].s, 64)
|
||||
if err != nil {
|
||||
yylex.(*lexerWrapper).lex.Error(fmt.Sprintf("error parsing number: %v", err))
|
||||
}
|
||||
maxInclusive := true
|
||||
logDebugGrammar("FIELD - LESS THAN OR EQUAL %f", max)
|
||||
q := NewNumericRangeInclusiveQuery(nil, &max, nil, &maxInclusive)
|
||||
@ -683,7 +712,7 @@ yydefault:
|
||||
}
|
||||
case 20:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line query_string.y:215
|
||||
//line query_string.y:244
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
minInclusive := false
|
||||
@ -700,7 +729,7 @@ yydefault:
|
||||
}
|
||||
case 21:
|
||||
yyDollar = yyS[yypt-5 : yypt+1]
|
||||
//line query_string.y:230
|
||||
//line query_string.y:259
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
minInclusive := true
|
||||
@ -717,7 +746,7 @@ yydefault:
|
||||
}
|
||||
case 22:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line query_string.y:245
|
||||
//line query_string.y:274
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
maxInclusive := false
|
||||
@ -734,7 +763,7 @@ yydefault:
|
||||
}
|
||||
case 23:
|
||||
yyDollar = yyS[yypt-5 : yypt+1]
|
||||
//line query_string.y:260
|
||||
//line query_string.y:289
|
||||
{
|
||||
field := yyDollar[1].s
|
||||
maxInclusive := true
|
||||
@ -751,13 +780,13 @@ yydefault:
|
||||
}
|
||||
case 24:
|
||||
yyDollar = yyS[yypt-0 : yypt+1]
|
||||
//line query_string.y:276
|
||||
//line query_string.y:305
|
||||
{
|
||||
yyVAL.pf = nil
|
||||
}
|
||||
case 25:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
//line query_string.y:280
|
||||
//line query_string.y:309
|
||||
{
|
||||
yyVAL.pf = nil
|
||||
boost, err := strconv.ParseFloat(yyDollar[1].s, 64)
|
||||
|
@ -12,7 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:generate go tool yacc -o query_string.y.go query_string.y
|
||||
// as of Go 1.8 this requires the goyacc external tool
|
||||
// available from golang.org/x/tools/cmd/goyacc
|
||||
|
||||
//go:generate goyacc -o query_string.y.go query_string.y
|
||||
//go:generate sed -i.tmp -e 1d query_string.y.go
|
||||
//go:generate rm query_string.y.go.tmp
|
||||
|
||||
|
@ -24,6 +24,8 @@ import (
|
||||
)
|
||||
|
||||
func TestQuerySyntaxParserValid(t *testing.T) {
|
||||
thirtyThreePointOh := 33.0
|
||||
twoPointOh := 2.0
|
||||
fivePointOh := 5.0
|
||||
theTruth := true
|
||||
theFalsehood := false
|
||||
@ -279,8 +281,16 @@ func TestQuerySyntaxParserValid(t *testing.T) {
|
||||
mapping: mapping.NewIndexMapping(),
|
||||
result: NewBooleanQueryForQueryString(
|
||||
nil,
|
||||
[]Query{
|
||||
func() Query {
|
||||
qo := NewDisjunctionQuery(
|
||||
[]Query{
|
||||
NewMatchQuery("33"),
|
||||
NewNumericRangeInclusiveQuery(&thirtyThreePointOh, &thirtyThreePointOh, &theTruth, &theTruth),
|
||||
})
|
||||
qo.queryStringMode = true
|
||||
return qo
|
||||
}(),
|
||||
},
|
||||
nil),
|
||||
},
|
||||
@ -289,12 +299,24 @@ func TestQuerySyntaxParserValid(t *testing.T) {
|
||||
mapping: mapping.NewIndexMapping(),
|
||||
result: NewBooleanQueryForQueryString(
|
||||
nil,
|
||||
[]Query{
|
||||
func() Query {
|
||||
qo := NewDisjunctionQuery(
|
||||
[]Query{
|
||||
func() Query {
|
||||
q := NewMatchQuery("33")
|
||||
q.SetField("field")
|
||||
return q
|
||||
}(),
|
||||
func() Query {
|
||||
q := NewNumericRangeInclusiveQuery(&thirtyThreePointOh, &thirtyThreePointOh, &theTruth, &theTruth)
|
||||
q.SetField("field")
|
||||
return q
|
||||
}(),
|
||||
})
|
||||
qo.queryStringMode = true
|
||||
return qo
|
||||
}(),
|
||||
},
|
||||
nil),
|
||||
},
|
||||
@ -347,7 +369,15 @@ func TestQuerySyntaxParserValid(t *testing.T) {
|
||||
q.SetFuzziness(1)
|
||||
return q
|
||||
}(),
|
||||
func() Query {
|
||||
qo := NewDisjunctionQuery(
|
||||
[]Query{
|
||||
NewMatchQuery("2"),
|
||||
NewNumericRangeInclusiveQuery(&twoPointOh, &twoPointOh, &theTruth, &theTruth),
|
||||
})
|
||||
qo.queryStringMode = true
|
||||
return qo
|
||||
}(),
|
||||
},
|
||||
nil),
|
||||
},
|
||||
@ -726,6 +756,12 @@ func TestQuerySyntaxParserInvalid(t *testing.T) {
|
||||
{`cat^3\0`},
|
||||
{`cat~3\:`},
|
||||
{`cat~3\0`},
|
||||
{`99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`},
|
||||
{`field:99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`},
|
||||
{`field:>99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`},
|
||||
{`field:>=99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`},
|
||||
{`field:<99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`},
|
||||
{`field:<=99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`},
|
||||
}
|
||||
|
||||
// turn on lexer debugging
|
||||
|
Loading…
Reference in New Issue
Block a user