Skip to content

Commit 17f2652

Browse files
committed
Upgrade to [org.querqy/querqy-core "3.15.0"]
1 parent 30714c6 commit 17f2652

File tree

4 files changed

+75
-30
lines changed

4 files changed

+75
-30
lines changed

project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
:dependencies
2323
[[org.clojure/clojure "1.11.1"]
24-
[org.querqy/querqy-core "3.14.0"]]
24+
[org.querqy/querqy-core "3.15.0"]]
2525

2626
:repl-options {:init-ns com.nytimes.querqy}
2727

src/com/nytimes/querqy/commonrules.clj

+66-20
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,45 @@
77
[com.nytimes.querqy.model :as model]
88
[com.nytimes.querqy.parser :as parser])
99
(: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)))
2149

2250
(set! *warn-on-reflection* true)
2351

@@ -78,6 +106,15 @@
78106

79107
(defrecord Rule [input instructions])
80108

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+
81118
(defn match*
82119
"Create a "
83120
[head & tail]
@@ -114,7 +151,9 @@
114151

115152
(defn delete
116153
[string]
117-
(DeleteInstruction. (parse-string string)))
154+
(DeleteInstruction.
155+
(parse-string string)
156+
(description {:type "delete", :value string})))
118157

119158
(defn synonym?
120159
[obj]
@@ -123,9 +162,12 @@
123162
(defn synonym
124163
"Create a synonym instruction."
125164
([string]
126-
(SynonymInstruction. (parse-string string)))
165+
(synonym 1.0 string))
127166
([boost string]
128-
(SynonymInstruction. (parse-string string) boost)))
167+
(SynonymInstruction.
168+
(parse-string string)
169+
boost
170+
(description {:type "synonym", :param boost, :value string}))))
129171

130172
(defn boost
131173
"Boost a matching term or query."
@@ -134,15 +176,19 @@
134176
(throw (IllegalArgumentException. "Cannot boost by 0")))
135177
(let [UP BoostInstruction$BoostDirection/UP
136178
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)}))))
141185

142186
(defn filter
143187
"Add a filter to the query."
144188
[query]
145-
(FilterInstruction. (parse-query query)))
189+
(FilterInstruction.
190+
(parse-query query)
191+
(description {:type "filter", :value (pr-str query)})))
146192

147193
;;; match impl
148194

@@ -206,4 +252,4 @@
206252
(.addRule rules-builder input literal)))
207253

208254
;;
209-
(rewriter-factory (.build rules-builder)))))
255+
(rewriter-factory (.build rules-builder)))))

src/com/nytimes/querqy/context.clj

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns com.nytimes.querqy.context
22
(:import
33
(java.util Optional)
4-
(querqy.rewrite SearchEngineRequestAdapter)))
4+
(querqy.rewrite RewriteLoggingConfig SearchEngineRequestAdapter)))
55

66
(defn optional
77
([] (Optional/empty))
@@ -18,12 +18,11 @@
1818
(getFloatRequestParam [_ k] (some-> (get params k) float optional))
1919
(getDoubleRequestParam [_ k] (some-> (get params k) double optional))
2020
(isDebugQuery [_] debug?)
21-
(getInfoLoggingContext [_] (optional)))
21+
(getRewriteLoggingConfig [_] (RewriteLoggingConfig/off)))
2222

2323
(def empty-context
2424
(map->Context
2525
{:chain []
2626
:debug? false
2727
:params {}
28-
:context {}}))
29-
28+
:context {}}))

src/com/nytimes/querqy/protocols.clj

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[com.nytimes.querqy.context :as context])
44
(:import
55
(querqy.model ExpandedQuery Query)
6-
(querqy.rewrite ContextAwareQueryRewriter RewriteChain RewriterFactory SearchEngineRequestAdapter)))
6+
(querqy.rewrite QueryRewriter RewriteChain RewriterFactory SearchEngineRequestAdapter)))
77

88
(defprotocol Parser
99
(parse ^Query [this ^String string]
@@ -21,19 +21,19 @@
2121
;; Some default Rewriter implementations for the Querqy classes.
2222

2323
(extend-protocol Rewriter
24-
ContextAwareQueryRewriter
24+
QueryRewriter
2525
(rewrite
2626
([this query]
2727
(rewrite this query context/empty-context))
2828
([this query context]
29-
(.rewrite this query context)))
29+
(some-> (.rewrite this query context) (.getExpandedQuery))))
3030

3131
RewriteChain
3232
(rewrite
3333
([this query]
3434
(rewrite this query context/empty-context))
3535
([this query context]
36-
(.rewrite this query context)))
36+
(some-> (.rewrite this query context) (.getExpandedQuery))))
3737

3838
RewriterFactory
3939
(rewrite
@@ -47,4 +47,4 @@
4747

4848
(defprotocol Emitter
4949
(emit [this query opts]
50-
"Emit a system-specific query for a given `querqy.model.ExpandedQuery`"))
50+
"Emit a system-specific query for a given `querqy.model.ExpandedQuery`"))

0 commit comments

Comments
 (0)