Changes for page Solr Search Macros

Last modified by Administrator on 2025/09/06 09:59

From version 1.1
edited by Administrator
on 2018/07/24 00:25
Change comment: Install extension [org.xwiki.platform:xwiki-platform-search-solr-ui/9.11.7]
To version 4.1
edited by Administrator
on 2024/02/03 10:14
Change comment: Install extension [org.xwiki.platform:xwiki-platform-search-solr-ui/15.10.5]

Summary

Details

Page properties
Content
... ... @@ -29,7 +29,10 @@
29 29   </div>
30 30   <div class="col-xs-12 col-sm-6">
31 31   <div class="input-group">
32 - <input type="search" name="text" class="form-control withTip useTitleAsTip"
32 + <label class='sr-only' for='search-page-bar-input'>
33 + $services.localization.render('search.page.bar.query.title')
34 + </label>
35 + <input id='search-page-bar-input' type='search' name='text' class='form-control withTip useTitleAsTip'
33 33   title="$services.localization.render('search.page.bar.query.title')" value="$escapetool.xml($text)"/>
34 34   <span class="input-group-btn">
35 35   <button type="submit" class="btn btn-primary">
... ... @@ -178,11 +178,18 @@
178 178   #else
179 179   #set ($facetPrettyName = $facetField.name)
180 180   #end
181 - <div class="search-facet-header">$escapetool.xml($facetPrettyName)</div>
184 + <div class="search-facet-header">
185 + <span id="$escapetool.xml($facetField.name)-toggler-hint">$escapetool.xml($facetPrettyName)</span>
186 + <button class="btn btn-xs facet-toggler"
187 + aria-controls="$escapetool.xml($facetField.name)-dropdown"
188 + aria-labelledby="$escapetool.xml($facetField.name)-toggler-hint">
189 + $services.icon.renderHTML('caret-down')
190 + </button>
191 + </div>
182 182  #end
183 183  
184 184  #macro (displaySearchFacetBody $facetField)
185 - <div class="search-facet-body">
195 + <div id="$escapetool.xml($facetField.name)-dropdown" class="search-facet-body">
186 186   #set ($facetDisplayer = $solrConfig.facetDisplayers.get($facetField.name))
187 187   #if (!$facetDisplayer && $facetField.name.startsWith('property.'))
188 188   ## Choose a facet displayer based on the property type.
... ... @@ -214,7 +214,7 @@
214 214  
215 215  #macro (displaySearchFacetValuesLimited $facetValues $customQueryStringParameters $customValueDisplayer)
216 216   #set ($limitRequestParameter = "l_$facetField.name")
217 - #set ($limit = $mathtool.toInteger($request.getParameter($limitRequestParameter)))
227 + #set ($limit = $numbertool.toNumber($request.getParameter($limitRequestParameter)).intValue())
218 218   #if ("$!limit" == '')
219 219   #set ($limit = $solrConfig.facetPaginationStep)
220 220   #end
... ... @@ -232,6 +232,10 @@
232 232  #end
233 233  
234 234  #macro (displaySearchFacetValue $facetValue $customQueryStringParameters $customValueDisplayer)
245 + #displaySearchFacetValue($facetValue $customQueryStringParameters $customValueDisplayer false)
246 +#end
247 +
248 +#macro (displaySearchFacetValue $facetValue $customQueryStringParameters $customValueDisplayer $displayToggler)
235 235   #set ($selectedValues = [])
236 236   #if ($facetRequestValues)
237 237   #set ($discard = $selectedValues.addAll($facetRequestValues.subList(0, $facetRequestValues.size())))
... ... @@ -246,7 +246,6 @@
246 246   #set ($discard = $queryStringParameters.putAll($customQueryStringParameters))
247 247   #end
248 248   #extendQueryString($url $queryStringParameters)
249 - <div class="itemCount">$facetValue.count</div>
250 250   <a href="$url" class="itemName#if ($selected) selected#end#if ($facetValue.name == '') empty#end">
251 251   #if ($facetValue.name == '')
252 252   #set ($facetPrettyValueKey = "solr.field.${facetField.name}.emptyValue")
... ... @@ -263,7 +263,13 @@
263 263   $escapetool.xml($facetPrettyValue)
264 264   #end
265 265   </a>
266 - <div class="clearfloats"></div>
279 + <div class="itemCount">$facetValue.count</div>
280 + #if ($displayToggler)
281 + <button class="btn btn-xs facet-value-toggler">
282 + <span class='sr-only'>$escapetool.xml($facetPrettyValue)</span>
283 + $services.icon.renderHTML('caret-down')
284 + </button>
285 + #end
267 267  #end
268 268  
269 269  #**
... ... @@ -298,9 +298,9 @@
298 298   (% class="search-options" %)
299 299   * {{translation key="solr.options"/}}
300 300   #if($highlightEnabled)#extendQueryString($url {'highlight': [false]})#else#extendQueryString($url {'highlight': [true]})#end
301 - * [[{{translation key="solr.options.highlight"/}}>>path:$url||class="options-item#if($highlightEnabled) active#end" title="$services.localization.render('solr.options.highlight.title')"]]
320 + * [[{{translation key="solr.options.highlight"/}}>>path:${url}||class="options-item#if($highlightEnabled) active#end" title="$services.localization.render('solr.options.highlight.title')"]]
302 302   #if($facetEnabled)#extendQueryString($url {'facet': [false]})#else#extendQueryString($url {'facet': [true]})#end
303 - * [[{{translation key="solr.options.facet"/}}>>path:$url||class="options-item#if($facetEnabled) active#end" title="$services.localization.render('solr.options.facet.title')"]]
322 + * [[{{translation key="solr.options.facet"/}}>>path:${url}||class="options-item#if($facetEnabled) active#end" title="$services.localization.render('solr.options.facet.title')"]]
304 304  
305 305   (% class="search-results-sort" %)
306 306   * {{translation key="solr.sortBy"/}}
... ... @@ -315,7 +315,7 @@
315 315   #set ($targetSortOrder = "#if ($sortOrder == 'asc')desc#{else}asc#end")
316 316   #end
317 317   #extendQueryString($url {'sort': [$entry.key], 'sortOrder': [$targetSortOrder]})
318 - * [[{{translation key="solr.sortBy.$entry.key"/}}$!sortOrderIndicator>>path:$url||class="$class"]]
337 + * [[{{translation key="solr.sortBy.$entry.key"/}}$!sortOrderIndicator>>path:${url}||class="$class"]]
319 319   #end
320 320  #end
321 321  
... ... @@ -561,7 +561,7 @@
561 561   'matches': $matches
562 562   }))
563 563   #end
564 - #set ($highlighting = $sorttool.sort($highlighting, 'priority:desc'))
583 + #set ($highlighting = $collectiontool.sort($highlighting, 'priority:desc'))
565 565   #set ($return = $NULL)
566 566   #setVariable("$return" $highlighting)
567 567  #end
... ... @@ -576,7 +576,10 @@
576 576   #set ($discard = $query.setLimit($rows))
577 577   #set ($discard = $query.setOffset($start))
578 578   #set ($discard = $query.bindValue('sort', "${sort} ${sortOrder}"))
598 + #set ($discard = $query.bindValue('tie', $solrConfig.tieBreaker))
599 + #set ($discard = $query.bindValue('mm', $solrConfig.minShouldMatch))
579 579   #setQueryFields($query)
601 + #setPhraseFields($query)
580 580   #setFacetFields($query)
581 581   #setFilterQuery($query)
582 582   #setHighlightQuery($query)
... ... @@ -604,6 +604,55 @@
604 604   #set ($discard = $query.bindValue('qf', $boost))
605 605   #end
606 606  #end
629 +
630 +#macro (setPhraseFields $query)
631 + ## Set the main phrase field parameter boosts so that queries with all search terms
632 + ## in close proximity have high relevance
633 + #if ($solrConfig.phraseFields.substring(0, 0) == '')
634 + ## If the value of the 'phraseFields' parameter is a string then it means that the
635 + ## same query fields are used for all result types.
636 + #set ($phraseFieldsBoost = $solrConfig.phraseFields)
637 + #else
638 + ## There are different phrase fields for each result type.
639 + ## Including type = null, which will result from all facets being deselected
640 + #set ($phraseFieldsBoost = $solrConfig.phraseFields.get("$!type"))
641 + #end
642 + #if ("$!phraseFieldsBoost" != '')
643 + #set ($discard = $query.bindValue('pf', $phraseFieldsBoost))
644 + #set ($discard = $query.bindValue('ps', $solrConfig.phraseFieldSlop))
645 + #end
646 + ## Set the bigram phrase field parameter boosts so that queries with groups of two
647 + ## search terms in close proximity have high relevance
648 + #if ($solrConfig.bigramPhraseFields.substring(0, 0) == '')
649 + ## If the value of the 'bigramPhraseFields' parameter is a string then it means that the
650 + ## same query fields are used for all result types.
651 + #set ($bigramPhraseFieldsBoost = $solrConfig.bigramPhraseFields)
652 + #else
653 + ## There are different phrase fields for each result type.
654 + ## Including type = null, which will result from all facets being deselected
655 + #set ($bigramPhraseFieldsBoost = $solrConfig.bigramPhraseFields.get("$!type"))
656 + #end
657 + #if ("$!bigramPhraseFieldsBoost" != '')
658 + #set ($discard = $query.bindValue('pf2', $bigramPhraseFieldsBoost))
659 + #set ($discard = $query.bindValue('ps2', $solrConfig.bigramPhraseFieldSlop))
660 + #end
661 + ## Set the trigram phrase field parameter boosts so that queries with groups of three
662 + ## search terms in close proximity have high relevance.
663 + ## Generally (pf boost) > (pf3 boost) > (pf2 boost)
664 + #if ($solrConfig.trigramPhraseFields.substring(0, 0) == '')
665 + ## If the value of the 'trigramPhraseFields' parameter is a string then it means that the
666 + ## same query fields are used for all result types.
667 + #set ($trigramPhraseFieldsBoost = $solrConfig.trigramPhraseFields)
668 + #else
669 + ## There are different phrase fields for each result type.
670 + ## including type = null, which will result from all facets being deselected
671 + #set ($trigramPhraseFieldsBoost = $solrConfig.trigramPhraseFields.get("$!type"))
672 + #end
673 + #if ("$!trigramPhraseFieldsBoost" != '')
674 + #set ($discard = $query.bindValue('pf3', $trigramPhraseFieldsBoost))
675 + #set ($discard = $query.bindValue('ps3', $solrConfig.trigramPhraseFieldSlop))
676 + #end
677 +#end
607 607  
608 608  #macro (setFacetFields $query)
609 609   #set ($discard = $query.bindValue('facet', $facetEnabled))
... ... @@ -663,7 +663,7 @@
663 663   #set ($discard = $filters.put($fieldName, $escapedValues))
664 664   #if ($prefixFacets.contains($fieldName))
665 665   #set ($parts = $parameter.value.get(0).split('/', 2))
666 - #set ($length = $mathtool.toInteger($parts.get(0)) + 1)
737 + #set ($length = $numbertool.toNumber($parts.get(0)).intValue() + 1)
667 667   #set ($prefix = "$length/$parts.get(1)")
668 668   #set ($discard = $query.bindValue("f.${fieldName}.facet.prefix", $prefix))
669 669   #set ($discard = $prefixFacets.remove($fieldName))
... ... @@ -727,11 +727,11 @@
727 727   #end
728 728   ##
729 729   ## Pagination
730 - #set ($rows = $numbertool.integer($request.rows))
801 + #set ($rows = $numbertool.toNumber($request.rows).intValue())
731 731   #if ("$!rows" == '')
732 732   #set ($rows = 10)
733 733   #end
734 - #set ($start = $numbertool.integer($request.firstIndex))
805 + #set ($start = $numbertool.toNumber($request.firstIndex).intValue())
735 735   #if ("$!start" == '')
736 736   #set ($start = 0)
737 737   #end