@@ -67,25 +67,57 @@ declare variable $fdh:DOC2 :=
6767 <section><para>map:merge combines maps; array and map are XDM types.</para></section>
6868 </article>;
6969
70+ (: A second collection whose index carries a boost (boost="2.0" on the para field). With a boost
71+ : config present, every query is additionally wrapped in a FunctionScoreQuery, so under facet
72+ : drill-down the query stored on the match is FunctionScoreQuery(DrillDownQuery(content)). That is
73+ : the case the FunctionScoreQuery branch in LuceneUtil.extractTerms must unwrap to reach the
74+ : DrillDownQuery (whose visit() is an opaque leaf); without it, boosted faceted highlights are empty. :)
75+ declare variable $fdh:BOOST-COLLECTION := "/db/lucene-test-facet-highlight-boost" ;
76+ declare variable $fdh:BOOST-CONFIG := "/db/system/config/db/lucene-test-facet-highlight-boost" ;
77+
78+ declare variable $fdh:BOOST-XCONF :=
79+ <collection xmlns = "http://exist-db.org/collection-config/1.0" >
80+ <index>
81+ <lucene>
82+ <analyzer class = "org.apache.lucene.analysis.standard.StandardAnalyzer" />
83+ <text qname = "para" boost = "2.0" >
84+ <field name = "content" expression = "." />
85+ <facet dimension = "kind" expression = "'para'" />
86+ </text>
87+ <text qname = "caption" >
88+ <field name = "content" expression = "." />
89+ <facet dimension = "kind" expression = "'caption'" />
90+ </text>
91+ </lucene>
92+ </index>
93+ </collection>;
94+
7095declare
7196 %test:setUp
7297function fdh:setup () {
7398 let $_ := (xmldb:create-collection ("/db/system" , "config" ), xmldb:create-collection ("/db/system/config" , "db" ))
7499 let $conf := xmldb:create-collection ("/db/system/config/db" , "lucene-test-facet-highlight" )
75100 let $col := xmldb:create-collection ("/db" , "lucene-test-facet-highlight" )
101+ let $boostConf := xmldb:create-collection ("/db/system/config/db" , "lucene-test-facet-highlight-boost" )
102+ let $boostCol := xmldb:create-collection ("/db" , "lucene-test-facet-highlight-boost" )
76103 return (
77104 xmldb:store ($conf, "collection.xconf" , $fdh:XCONF),
78105 xmldb:store ($col, "doc1.xml" , $fdh:DOC1),
79106 xmldb:store ($col, "doc2.xml" , $fdh:DOC2),
80- xmldb:reindex ($col)
107+ xmldb:reindex ($col),
108+ xmldb:store ($boostConf, "collection.xconf" , $fdh:BOOST-XCONF),
109+ xmldb:store ($boostCol, "doc1.xml" , $fdh:DOC1),
110+ xmldb:reindex ($boostCol)
81111 )
82112};
83113
84114declare
85115 %test:tearDown
86116function fdh:tearDown () {
87117 if (xmldb:collection-available ($fdh:COLLECTION)) then xmldb:remove ($fdh:COLLECTION) else (),
88- if (xmldb:collection-available ($fdh:CONFIG)) then xmldb:remove ($fdh:CONFIG) else ()
118+ if (xmldb:collection-available ($fdh:CONFIG)) then xmldb:remove ($fdh:CONFIG) else (),
119+ if (xmldb:collection-available ($fdh:BOOST-COLLECTION)) then xmldb:remove ($fdh:BOOST-COLLECTION) else (),
120+ if (xmldb:collection-available ($fdh:BOOST-CONFIG)) then xmldb:remove ($fdh:BOOST-CONFIG) else ()
89121};
90122
91123(: control: a plain (unfaceted) query highlights fine :)
@@ -129,3 +161,23 @@ function fdh:drilldown-excludes-other-facet() {
129161 let $opts := map { "facets" : map { "kind" : "para" } }
130162 return count (collection ($fdh:COLLECTION)//caption[ft:query (., "content:(array)" , $opts)])
131163};
164+
165+ (: regression: boost config + facet drill-down must STILL highlight. With a boost the match query is
166+ FunctionScoreQuery(DrillDownQuery(content)); the FunctionScoreQuery branch in extractTerms unwraps
167+ to the DrillDownQuery and then its base query. Empty before the fix (and on develop). :)
168+ declare
169+ %test:assertTrue
170+ function fdh:faceted-query-highlights-with-boost () {
171+ let $opts := map { "facets" : map { "kind" : "para" } }
172+ let $hit := (collection ($fdh:BOOST-COLLECTION)//para[ft:query (., "content:(array)" , $opts)])[1 ]
173+ return exists (ft:highlight-field-matches ($hit, "content" )//exist:match)
174+ };
175+
176+ (: the highlighted term is the queried term, under boost + drill-down :)
177+ declare
178+ %test:assertTrue
179+ function fdh:faceted-highlight-marks-the-term-with-boost () {
180+ let $opts := map { "facets" : map { "kind" : "para" } }
181+ let $hit := (collection ($fdh:BOOST-COLLECTION)//para[ft:query (., "content:(array)" , $opts)])[1 ]
182+ return lower-case (string (ft:highlight-field-matches ($hit, "content" )//exist:match[1 ])) = "array"
183+ };
0 commit comments