7
7
[com.nytimes.querqy.model :as model]
8
8
[com.nytimes.querqy.parser :as parser])
9
9
(:import
10
- (java.io Reader)
11
- (java.net URL)
12
- (java.util List UUID)
13
- (querqy.model Input Input$BooleanInput Input$SimpleInput)
14
- (querqy.parser QuerqyParser)
15
- (querqy.rewrite RewriterFactory)
16
- (querqy.rewrite.commonrules CommonRulesRewriter LineParser QuerqyParserFactory SimpleCommonRulesParser WhiteSpaceQuerqyParserFactory)
17
- (querqy.rewrite.commonrules.model BoostInstruction BoostInstruction$BoostDirection BoostInstruction$BoostMethod DeleteInstruction FilterInstruction Instructions SynonymInstruction TrieMapRulesCollectionBuilder)
18
- (querqy.rewrite.commonrules.select SelectionStrategyFactory)
19
- (querqy.rewrite.commonrules.select.booleaninput BooleanInputParser)
20
- (querqy.rewrite.commonrules.select.booleaninput.model BooleanInputElement BooleanInputElement$Type BooleanInputLiteral)))
10
+ (java.io
11
+ Reader)
12
+ (java.net
13
+ URL)
14
+ (java.util
15
+ List
16
+ UUID)
17
+ (querqy.model
18
+ Input
19
+ Input$BooleanInput
20
+ Input$SimpleInput)
21
+ (querqy.parser
22
+ QuerqyParser)
23
+ (querqy.rewrite
24
+ RewriterFactory)
25
+ (querqy.rewrite.commonrules
26
+ CommonRulesRewriter
27
+ LineParser
28
+ QuerqyParserFactory
29
+ SimpleCommonRulesParser
30
+ WhiteSpaceQuerqyParserFactory)
31
+ (querqy.rewrite.commonrules.model
32
+ BoostInstruction
33
+ BoostInstruction$BoostDirection
34
+ BoostInstruction$BoostMethod
35
+ DeleteInstruction
36
+ FilterInstruction
37
+ InstructionDescription
38
+ Instructions
39
+ SynonymInstruction
40
+ TrieMapRulesCollectionBuilder)
41
+ (querqy.rewrite.commonrules.select
42
+ SelectionStrategyFactory)
43
+ (querqy.rewrite.commonrules.select.booleaninput
44
+ BooleanInputParser)
45
+ (querqy.rewrite.commonrules.select.booleaninput.model
46
+ BooleanInputElement
47
+ BooleanInputElement$Type
48
+ BooleanInputLiteral)))
21
49
22
50
(set! *warn-on-reflection* true )
23
51
78
106
79
107
(defrecord Rule [input instructions])
80
108
109
+ (defn- description
110
+ ^InstructionDescription
111
+ [& {:keys [^String type, param, ^String value]}]
112
+ (cond-> (InstructionDescription/builder )
113
+ (some? type) (.typeName type)
114
+ (some? param) (.param param)
115
+ (some? value) (.value value)
116
+ :finally (.build )))
117
+
81
118
(defn match*
82
119
" Create a "
83
120
[head & tail]
114
151
115
152
(defn delete
116
153
[string]
117
- (DeleteInstruction. (parse-string string)))
154
+ (DeleteInstruction.
155
+ (parse-string string)
156
+ (description {:type " delete" , :value string})))
118
157
119
158
(defn synonym?
120
159
[obj]
123
162
(defn synonym
124
163
" Create a synonym instruction."
125
164
([string]
126
- (SynonymInstruction. ( parse- string string) ))
165
+ (synonym 1.0 string))
127
166
([boost string]
128
- (SynonymInstruction. (parse-string string) boost)))
167
+ (SynonymInstruction.
168
+ (parse-string string)
169
+ boost
170
+ (description {:type " synonym" , :param boost, :value string}))))
129
171
130
172
(defn boost
131
173
" Boost a matching term or query."
134
176
(throw (IllegalArgumentException. " Cannot boost by 0" )))
135
177
(let [UP BoostInstruction$BoostDirection/UP
136
178
DOWN BoostInstruction$BoostDirection/DOWN]
137
- (BoostInstruction. (parse-query query)
138
- (if (>= boost 0 ) UP DOWN)
139
- BoostInstruction$BoostMethod/ADDITIVE
140
- (abs boost))))
179
+ (BoostInstruction.
180
+ (parse-query query)
181
+ (if (>= boost 0 ) UP DOWN)
182
+ BoostInstruction$BoostMethod/ADDITIVE
183
+ (abs boost)
184
+ (description {:type " boost" , :param boost, :value (pr-str query)}))))
141
185
142
186
(defn filter
143
187
" Add a filter to the query."
144
188
[query]
145
- (FilterInstruction. (parse-query query)))
189
+ (FilterInstruction.
190
+ (parse-query query)
191
+ (description {:type " filter" , :value (pr-str query)})))
146
192
147
193
; ;; match impl
148
194
206
252
(.addRule rules-builder input literal)))
207
253
208
254
; ;
209
- (rewriter-factory (.build rules-builder)))))
255
+ (rewriter-factory (.build rules-builder)))))
0 commit comments