allow for exact numeric matches with field:val syntax
previously, the only way to get numeric matching was with the range operators :> :>= :< :<= now, when we encounter field:val if the val can be parsed as a number, then we do a disjunction search, which includes searching for val as a text term and as an exact numeric value
This commit is contained in:
parent
f6563ed9f5
commit
23bf986632
@ -127,7 +127,12 @@ tSTRING tCOLON tSTRING tTILDE {
|
|||||||
tNUMBER {
|
tNUMBER {
|
||||||
str := $1
|
str := $1
|
||||||
logDebugGrammar("STRING - %s", str)
|
logDebugGrammar("STRING - %s", str)
|
||||||
q := NewMatchQuery(str)
|
q1 := NewMatchQuery(str)
|
||||||
|
val, _ := strconv.ParseFloat($1, 64)
|
||||||
|
inclusive := true
|
||||||
|
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||||
|
q := NewDisjunctionQuery([]Query{q1,q2})
|
||||||
|
q.queryStringMode = true
|
||||||
$$ = q
|
$$ = q
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
@ -158,8 +163,14 @@ tSTRING tCOLON tNUMBER {
|
|||||||
field := $1
|
field := $1
|
||||||
str := $3
|
str := $3
|
||||||
logDebugGrammar("FIELD - %s STRING - %s", field, str)
|
logDebugGrammar("FIELD - %s STRING - %s", field, str)
|
||||||
q := NewMatchQuery(str)
|
q1 := NewMatchQuery(str)
|
||||||
q.SetField(field)
|
q1.SetField(field)
|
||||||
|
val, _ := strconv.ParseFloat($3, 64)
|
||||||
|
inclusive := true
|
||||||
|
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||||
|
q2.SetField(field)
|
||||||
|
q := NewDisjunctionQuery([]Query{q1,q2})
|
||||||
|
q.queryStringMode = true
|
||||||
$$ = q
|
$$ = q
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
|
@ -581,12 +581,17 @@ yydefault:
|
|||||||
{
|
{
|
||||||
str := yyDollar[1].s
|
str := yyDollar[1].s
|
||||||
logDebugGrammar("STRING - %s", str)
|
logDebugGrammar("STRING - %s", str)
|
||||||
q := NewMatchQuery(str)
|
q1 := NewMatchQuery(str)
|
||||||
|
val, _ := strconv.ParseFloat(yyDollar[1].s, 64)
|
||||||
|
inclusive := true
|
||||||
|
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||||
|
q := NewDisjunctionQuery([]Query{q1, q2})
|
||||||
|
q.queryStringMode = true
|
||||||
yyVAL.q = q
|
yyVAL.q = q
|
||||||
}
|
}
|
||||||
case 12:
|
case 12:
|
||||||
yyDollar = yyS[yypt-1 : yypt+1]
|
yyDollar = yyS[yypt-1 : yypt+1]
|
||||||
//line query_string.y:134
|
//line query_string.y:139
|
||||||
{
|
{
|
||||||
phrase := yyDollar[1].s
|
phrase := yyDollar[1].s
|
||||||
logDebugGrammar("PHRASE - %s", phrase)
|
logDebugGrammar("PHRASE - %s", phrase)
|
||||||
@ -595,7 +600,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 13:
|
case 13:
|
||||||
yyDollar = yyS[yypt-3 : yypt+1]
|
yyDollar = yyS[yypt-3 : yypt+1]
|
||||||
//line query_string.y:141
|
//line query_string.y:146
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
str := yyDollar[3].s
|
str := yyDollar[3].s
|
||||||
@ -613,18 +618,24 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 14:
|
case 14:
|
||||||
yyDollar = yyS[yypt-3 : yypt+1]
|
yyDollar = yyS[yypt-3 : yypt+1]
|
||||||
//line query_string.y:157
|
//line query_string.y:162
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
str := yyDollar[3].s
|
str := yyDollar[3].s
|
||||||
logDebugGrammar("FIELD - %s STRING - %s", field, str)
|
logDebugGrammar("FIELD - %s STRING - %s", field, str)
|
||||||
q := NewMatchQuery(str)
|
q1 := NewMatchQuery(str)
|
||||||
q.SetField(field)
|
q1.SetField(field)
|
||||||
|
val, _ := strconv.ParseFloat(yyDollar[3].s, 64)
|
||||||
|
inclusive := true
|
||||||
|
q2 := NewNumericRangeInclusiveQuery(&val, &val, &inclusive, &inclusive)
|
||||||
|
q2.SetField(field)
|
||||||
|
q := NewDisjunctionQuery([]Query{q1, q2})
|
||||||
|
q.queryStringMode = true
|
||||||
yyVAL.q = q
|
yyVAL.q = q
|
||||||
}
|
}
|
||||||
case 15:
|
case 15:
|
||||||
yyDollar = yyS[yypt-3 : yypt+1]
|
yyDollar = yyS[yypt-3 : yypt+1]
|
||||||
//line query_string.y:166
|
//line query_string.y:177
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
phrase := yyDollar[3].s
|
phrase := yyDollar[3].s
|
||||||
@ -635,7 +646,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 16:
|
case 16:
|
||||||
yyDollar = yyS[yypt-4 : yypt+1]
|
yyDollar = yyS[yypt-4 : yypt+1]
|
||||||
//line query_string.y:175
|
//line query_string.y:186
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
min, _ := strconv.ParseFloat(yyDollar[4].s, 64)
|
min, _ := strconv.ParseFloat(yyDollar[4].s, 64)
|
||||||
@ -647,7 +658,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 17:
|
case 17:
|
||||||
yyDollar = yyS[yypt-5 : yypt+1]
|
yyDollar = yyS[yypt-5 : yypt+1]
|
||||||
//line query_string.y:185
|
//line query_string.y:196
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
min, _ := strconv.ParseFloat(yyDollar[5].s, 64)
|
min, _ := strconv.ParseFloat(yyDollar[5].s, 64)
|
||||||
@ -659,7 +670,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 18:
|
case 18:
|
||||||
yyDollar = yyS[yypt-4 : yypt+1]
|
yyDollar = yyS[yypt-4 : yypt+1]
|
||||||
//line query_string.y:195
|
//line query_string.y:206
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
max, _ := strconv.ParseFloat(yyDollar[4].s, 64)
|
max, _ := strconv.ParseFloat(yyDollar[4].s, 64)
|
||||||
@ -671,7 +682,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 19:
|
case 19:
|
||||||
yyDollar = yyS[yypt-5 : yypt+1]
|
yyDollar = yyS[yypt-5 : yypt+1]
|
||||||
//line query_string.y:205
|
//line query_string.y:216
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
max, _ := strconv.ParseFloat(yyDollar[5].s, 64)
|
max, _ := strconv.ParseFloat(yyDollar[5].s, 64)
|
||||||
@ -683,7 +694,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 20:
|
case 20:
|
||||||
yyDollar = yyS[yypt-4 : yypt+1]
|
yyDollar = yyS[yypt-4 : yypt+1]
|
||||||
//line query_string.y:215
|
//line query_string.y:226
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
minInclusive := false
|
minInclusive := false
|
||||||
@ -700,7 +711,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 21:
|
case 21:
|
||||||
yyDollar = yyS[yypt-5 : yypt+1]
|
yyDollar = yyS[yypt-5 : yypt+1]
|
||||||
//line query_string.y:230
|
//line query_string.y:241
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
minInclusive := true
|
minInclusive := true
|
||||||
@ -717,7 +728,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 22:
|
case 22:
|
||||||
yyDollar = yyS[yypt-4 : yypt+1]
|
yyDollar = yyS[yypt-4 : yypt+1]
|
||||||
//line query_string.y:245
|
//line query_string.y:256
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
maxInclusive := false
|
maxInclusive := false
|
||||||
@ -734,7 +745,7 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 23:
|
case 23:
|
||||||
yyDollar = yyS[yypt-5 : yypt+1]
|
yyDollar = yyS[yypt-5 : yypt+1]
|
||||||
//line query_string.y:260
|
//line query_string.y:271
|
||||||
{
|
{
|
||||||
field := yyDollar[1].s
|
field := yyDollar[1].s
|
||||||
maxInclusive := true
|
maxInclusive := true
|
||||||
@ -751,13 +762,13 @@ yydefault:
|
|||||||
}
|
}
|
||||||
case 24:
|
case 24:
|
||||||
yyDollar = yyS[yypt-0 : yypt+1]
|
yyDollar = yyS[yypt-0 : yypt+1]
|
||||||
//line query_string.y:276
|
//line query_string.y:287
|
||||||
{
|
{
|
||||||
yyVAL.pf = nil
|
yyVAL.pf = nil
|
||||||
}
|
}
|
||||||
case 25:
|
case 25:
|
||||||
yyDollar = yyS[yypt-1 : yypt+1]
|
yyDollar = yyS[yypt-1 : yypt+1]
|
||||||
//line query_string.y:280
|
//line query_string.y:291
|
||||||
{
|
{
|
||||||
yyVAL.pf = nil
|
yyVAL.pf = nil
|
||||||
boost, err := strconv.ParseFloat(yyDollar[1].s, 64)
|
boost, err := strconv.ParseFloat(yyDollar[1].s, 64)
|
||||||
|
@ -24,6 +24,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestQuerySyntaxParserValid(t *testing.T) {
|
func TestQuerySyntaxParserValid(t *testing.T) {
|
||||||
|
thirtyThreePointOh := 33.0
|
||||||
|
twoPointOh := 2.0
|
||||||
fivePointOh := 5.0
|
fivePointOh := 5.0
|
||||||
theTruth := true
|
theTruth := true
|
||||||
theFalsehood := false
|
theFalsehood := false
|
||||||
@ -279,8 +281,16 @@ func TestQuerySyntaxParserValid(t *testing.T) {
|
|||||||
mapping: mapping.NewIndexMapping(),
|
mapping: mapping.NewIndexMapping(),
|
||||||
result: NewBooleanQueryForQueryString(
|
result: NewBooleanQueryForQueryString(
|
||||||
nil,
|
nil,
|
||||||
|
[]Query{
|
||||||
|
func() Query {
|
||||||
|
qo := NewDisjunctionQuery(
|
||||||
[]Query{
|
[]Query{
|
||||||
NewMatchQuery("33"),
|
NewMatchQuery("33"),
|
||||||
|
NewNumericRangeInclusiveQuery(&thirtyThreePointOh, &thirtyThreePointOh, &theTruth, &theTruth),
|
||||||
|
})
|
||||||
|
qo.queryStringMode = true
|
||||||
|
return qo
|
||||||
|
}(),
|
||||||
},
|
},
|
||||||
nil),
|
nil),
|
||||||
},
|
},
|
||||||
@ -289,12 +299,24 @@ func TestQuerySyntaxParserValid(t *testing.T) {
|
|||||||
mapping: mapping.NewIndexMapping(),
|
mapping: mapping.NewIndexMapping(),
|
||||||
result: NewBooleanQueryForQueryString(
|
result: NewBooleanQueryForQueryString(
|
||||||
nil,
|
nil,
|
||||||
|
[]Query{
|
||||||
|
func() Query {
|
||||||
|
qo := NewDisjunctionQuery(
|
||||||
[]Query{
|
[]Query{
|
||||||
func() Query {
|
func() Query {
|
||||||
q := NewMatchQuery("33")
|
q := NewMatchQuery("33")
|
||||||
q.SetField("field")
|
q.SetField("field")
|
||||||
return q
|
return q
|
||||||
}(),
|
}(),
|
||||||
|
func() Query {
|
||||||
|
q := NewNumericRangeInclusiveQuery(&thirtyThreePointOh, &thirtyThreePointOh, &theTruth, &theTruth)
|
||||||
|
q.SetField("field")
|
||||||
|
return q
|
||||||
|
}(),
|
||||||
|
})
|
||||||
|
qo.queryStringMode = true
|
||||||
|
return qo
|
||||||
|
}(),
|
||||||
},
|
},
|
||||||
nil),
|
nil),
|
||||||
},
|
},
|
||||||
@ -347,7 +369,15 @@ func TestQuerySyntaxParserValid(t *testing.T) {
|
|||||||
q.SetFuzziness(1)
|
q.SetFuzziness(1)
|
||||||
return q
|
return q
|
||||||
}(),
|
}(),
|
||||||
|
func() Query {
|
||||||
|
qo := NewDisjunctionQuery(
|
||||||
|
[]Query{
|
||||||
NewMatchQuery("2"),
|
NewMatchQuery("2"),
|
||||||
|
NewNumericRangeInclusiveQuery(&twoPointOh, &twoPointOh, &theTruth, &theTruth),
|
||||||
|
})
|
||||||
|
qo.queryStringMode = true
|
||||||
|
return qo
|
||||||
|
}(),
|
||||||
},
|
},
|
||||||
nil),
|
nil),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user