-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This requires sharing the BooleanInputParser among all the rules within the rules-rewriter and adding the input literals all at once at the end.
- Loading branch information
Showing
5 changed files
with
184 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1 @@ | ||
(ns user | ||
(:require | ||
[com.nytimes.querqy :as q] | ||
[com.nytimes.querqy.commonrules :as c])) | ||
|
||
(defn pin | ||
"Pin the given IDs to the top of the result set in the order given. Should only | ||
be used once within a given match rule." | ||
[& ids] | ||
(map-indexed | ||
(fn [idx id] | ||
(c/boost (- Float/MAX_VALUE idx) {:ids {:values [id]}})) | ||
ids)) | ||
|
||
;; Let's assume we have some special thanksgiving related content that editorial | ||
;; wants highly promoted, the documents with IDs 12345 and 5678. Rather than | ||
;; tweak scores or sprinkle boosts around our rule set, we can instead use our | ||
;; new pin rule which makes clear the intent of the boost and serves as | ||
;; documentation for what we're trying to achieve with this rule. | ||
(def rules | ||
(c/rules-rewriter | ||
(c/match "thanksgiving" | ||
(pin "12345" "5678")))) | ||
|
||
;; We can now emit a query which pins results to the top. | ||
|
||
(def opts {:match/fields ["headline"]}) | ||
|
||
(q/emit (q/rewrite rules "thanksgiving recipes") opts) | ||
|
||
{:function_score | ||
{:query | ||
{:bool | ||
{:must [], | ||
:should | ||
[{:match {"headline" {:query "thanksgiving"}}} | ||
{:match {"headline" {:query "recipes"}}}], | ||
:must_not [], | ||
:filter []}}, | ||
:functions | ||
[{:filter {:ids {:values ["5678"]}}, :weight 1.0E37} | ||
{:filter {:ids {:values ["12345"]}}, :weight 1.0E38}]}} | ||
|
||
(def base | ||
{:function_score | ||
{:query | ||
{:bool {:must [], | ||
:should [], | ||
:must_not [], | ||
:filter []}}, | ||
:functions | ||
[{:filter {:ids {:values ["5678"]}}, :weight 1.0E37} | ||
{:filter {:ids {:values ["12345"]}}, :weight 1.0E38}]}}) | ||
(ns user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.