forked from blevesearch/bleve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_string.y
145 lines (127 loc) · 2.45 KB
/
query_string.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
%{
package bleve
import "log"
func logDebugGrammar(format string, v ...interface{}) {
if debugParser {
log.Printf(format, v...)
}
}
%}
%union {
s string
n int
f float64}
%token tSTRING tPHRASE tPLUS tMINUS tCOLON tBOOST tLPAREN tRPAREN tNUMBER tSTRING tGREATER tLESS tEQUAL
%%
input:
searchParts {
logDebugGrammar("INPUT")
};
searchParts:
searchPart searchParts {
logDebugGrammar("SEARCH PARTS")
}
|
searchPart {
logDebugGrammar("SEARCH PART")
};
searchPart:
searchPrefix searchBase searchSuffix {
};
searchPrefix:
/* empty */ {
}
|
searchMustMustNot {
}
;
searchMustMustNot:
tPLUS {
logDebugGrammar("PLUS")
parsingMust = true
}
|
tMINUS {
logDebugGrammar("MINUS")
parsingMustNot = true
};
searchBase:
tSTRING {
str := $1.s
logDebugGrammar("STRING - %s", str)
q := NewMatchQuery(str)
addQueryToList(q)
}
|
tPHRASE {
phrase := $1.s
logDebugGrammar("PHRASE - %s", phrase)
q := NewMatchPhraseQuery(phrase)
addQueryToList(q)
}
|
tSTRING tCOLON tSTRING {
field := $1.s
str := $3.s
logDebugGrammar("FIELD - %s STRING - %s", field, str)
q := NewMatchQuery(str).SetField(field)
addQueryToList(q)
}
|
tSTRING tCOLON tPHRASE {
field := $1.s
phrase := $3.s
logDebugGrammar("FIELD - %s PHRASE - %s", field, phrase)
q := NewMatchPhraseQuery(phrase).SetField(field)
addQueryToList(q)
}
|
tSTRING tCOLON tGREATER tNUMBER {
field := $1.s
min := $4.f
minInclusive := false
logDebugGrammar("FIELD - GREATER THAN %f", min)
q := NewNumericRangeInclusiveQuery(&min, nil, &minInclusive, nil).SetField(field)
addQueryToList(q)
}
|
tSTRING tCOLON tGREATER tEQUAL tNUMBER {
field := $1.s
min := $5.f
minInclusive := true
logDebugGrammar("FIELD - GREATER THAN OR EQUAL %f", min)
q := NewNumericRangeInclusiveQuery(&min, nil, &minInclusive, nil).SetField(field)
addQueryToList(q)
}
|
tSTRING tCOLON tLESS tNUMBER {
field := $1.s
max := $4.f
maxInclusive := false
logDebugGrammar("FIELD - LESS THAN %f", max)
q := NewNumericRangeInclusiveQuery(nil, &max, nil, &maxInclusive).SetField(field)
addQueryToList(q)
}
|
tSTRING tCOLON tLESS tEQUAL tNUMBER {
field := $1.s
max := $5.f
maxInclusive := true
logDebugGrammar("FIELD - LESS THAN OR EQUAL %f", max)
q := NewNumericRangeInclusiveQuery(nil, &max, nil, &maxInclusive).SetField(field)
addQueryToList(q)
};
searchBoost:
tBOOST tNUMBER {
boost := $2.f
if parsingLastQuery != nil {
parsingLastQuery.SetBoost(boost)
}
logDebugGrammar("BOOST %f", boost)
};
searchSuffix:
/* empty */ {
}
|
searchBoost {
};