Apache Lucene open-source search software
SOLR-2177: Show more examples of faceting in the browse capability
Grant Ingersolla817987d9202
diff --git a/solr/example/solr/conf/solrconfig.xml b/solr/example/solr/conf/solrconfig.xmlindex 348b5a03db1..f4f1a08f204 100755--- a/solr/example/solr/conf/solrconfig.xml+++ b/solr/example/solr/conf/solrconfig.xml@@ -524,7 +524,23 @@<str name="facet">on</str><str name="facet.field">cat</str><str name="facet.field">manu_exact</str>+ <str name="facet.query">ipod</str>+ <str name="facet.query">GB</str><str name="facet.mincount">1</str>+ <str name="facet.pivot">cat,inStock</str>+ <str name="facet.range">price</str>+ <int name="facet.range.start">0</int>+ <int name="facet.range.end">600</int>+ <int name="facet.range.gap">50</int>+ <str name="facet.range.other">after</str>+ <str name="facet.date">manufacturedate_dt</str>+ <str name="facet.date.start">NOW/YEAR-10YEARS</str>+ <str name="facet.date.end">NOW</str>+ <str name="facet.mincount">1</str>+ <str name="facet.date.gap">+1YEAR</str>+ <str name="facet.date.other">before</str>+ <str name="facet.date.other">after</str>+<!-- Highlighting defaults --><str name="hl">on</str>@@ -541,6 +557,7 @@</lst><arr name="last-components"><str>spellcheck</str>+ <str>pivot</str></arr><!--<str name="url-scheme">httpx</str>diff --git a/solr/example/solr/conf/velocity/VM_global_library.vm b/solr/example/solr/conf/velocity/VM_global_library.vmindex a71ef850a08..5f6f8f3eed6 100644--- a/solr/example/solr/conf/velocity/VM_global_library.vm+++ b/solr/example/solr/conf/velocity/VM_global_library.vm@@ -17,9 +17,16 @@#macro(url_for_filters $p)#url_for_home?#q#if($list.size($p) > 0)&#fqs($p)#end#debug#end+#macro(url_for_nested_facet_query $field)#url_for_home#lens&fq=$esc.url($field)#end+## TODO: convert to use {!raw f=$field}$value (with escaping of course)#macro(url_for_facet_filter $field $value)#url_for_home#lens&fq=$esc.url($field):%22$esc.url($value)%22#end+#macro(url_for_facet_date_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end++#macro(url_for_facet_range_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end++#macro(link_to_previous_page $text)#if($page.current_page_number > 1)#set($prev_start = $page.start - $page.results_per_page)@@ -44,3 +51,108 @@#end#end#end++#macro(display_facet_query $field, $display, $fieldName)+ #if($field.size() > 0)+ <span class="facet-field">$display</span>+ <ul>+ #foreach ($facet in $field)+ #if ($facet.value > 0)+ #set($facetURL = "#url_for_nested_facet_query($facet.key)")+ #if ($facetURL != '')+ <li><a href="$facetURL">$facet.key</a> ($facet.value)</li>+ #end+ #end+ #end+ </ul>+ #end+#end++#macro(display_facet_date $field, $display, $fieldName, $gap)+ <span class="facet-field">$display</span>+ <ul>+ #foreach ($facet in $field)+ #set($theDate = $date.toDate("yyyy-MM-dd'T'HH:mm:ss'Z'", $facet.key))+ #set($value = '["' + $facet.key + '" TO "' + $facet.key + $gap + '"]')++ #set($facetURL = "#url_for_facet_date_filter($fieldName, $value)")+ #if ($facetURL != '')+ #if ($facet.key != "gap" && $facet.key != "start" && $facet.key != "end" && $facet.key != "before" && $facet.key != "after")++ <li><a href="$facetURL">$date.format('MMM yyyy', $theDate)</a> ($facet.value)</li>+ #end+ #if ($facet.key == "before" && $facet.value > 0)+ <li><a href="$facetURL">Before</a> ($facet.value)</li>+ #end+ #if ($facet.key == "after" && $facet.value > 0)+ <li><a href="$facetURL">After</a> ($facet.value)</li>+ #end+ #end+ #end+ </ul>+#end++++#macro(display_facet_range $field, $display, $fieldName, $start, $end, $gap, $before, $after)+ <span class="facet-field">$display</span>+ <ul>+ #if($before && $before != "")+ #set($value = '[* TO "' + $start + '"]')+ #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")+ <li><a href="$facetURL">Less than $start</a> ($before)</li>+ #end+ #foreach ($facet in $field)+ #set($rangeEnd = $math.add($facet.key, $gap))+ #set($value = "[" + $facet.key + " TO $rangeEnd]")+ #set($facetURL = "#url_for_facet_filter($fieldName, $value)")+ #if ($facetURL != '')+ <li><a href="$facetURL">$facet.key</a> ($facet.value)</li>+ #end+ #end+ #if($end && $end != "")+ #set($value = "[" + $end + " TO *]")+ #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")+ <li><a href="$facetURL">More than $math.toNumber($end)</a> ($after)</li>+ #end+ </ul>+#end++## <lst name="facet_pivot">+## <arr name="cat,inStock">+## <lst>+## <str name="field">cat</str>+## <str name="value">electronics</str>+## <int name="count">17</int>+## <arr name="pivot">+## <lst>+## <str name="field">inStock</str>+## <str name="value">true</str>+## <int name="count">13</int>+## </lst>+## <lst>+## <str name="field">inStock</str>+## <str name="value">false</str>+## <int name="count">4</int>+## </lst>+## </arr>+## </lst>++## $pivots is a list of facet_pivot+#macro(display_facet_pivot $pivots, $display)+ #if($pivots.size() > 0)+ <span class="facet-field">$display</span>+ <ul>+ #foreach ($pivot in $pivots)+ #foreach ($entry in $pivot.value)+ <a href="#url_for_facet_filter($entry.field, $entry.value)">$entry.field::$entry.value</a> ($entry.count)+ <ul>+ #foreach($nest in $entry.pivot)+ <a href="#url_for_facet_filter($entry.field, $entry.value)&fq=$esc.url($nest.field):%22$esc.url($nest.value)%22">$nest.field::$nest.value</a> ($nest.count)+ #end+ </ul>+ #end+ #end+ </ul>+ #end+#end\ No newline at end of filediff --git a/solr/example/solr/conf/velocity/facet_dates.vm b/solr/example/solr/conf/velocity/facet_dates.vmnew file mode 100644index 00000000000..d2757663c94--- /dev/null+++ b/solr/example/solr/conf/velocity/facet_dates.vm@@ -0,0 +1,4 @@+##TODO: Generically deal with all dates+#set($field = $response.response.facet_counts.facet_dates.manufacturedate_dt)+#set($gap = $response.response.facet_counts.facet_dates.manufacturedate_dt.gap)+#display_facet_date($field, "Manufacture Date", "manufacturedate_dt", $gap)diff --git a/solr/example/solr/conf/velocity/facet_pivot.vm b/solr/example/solr/conf/velocity/facet_pivot.vmnew file mode 100644index 00000000000..1dbf5744d53--- /dev/null+++ b/solr/example/solr/conf/velocity/facet_pivot.vm@@ -0,0 +1,2 @@+#set($pivot = $response.response.facet_counts.facet_pivot)+#display_facet_pivot($pivot, "Pivots")diff --git a/solr/example/solr/conf/velocity/facet_queries.vm b/solr/example/solr/conf/velocity/facet_queries.vmnew file mode 100644index 00000000000..93116d39b1f--- /dev/null+++ b/solr/example/solr/conf/velocity/facet_queries.vm@@ -0,0 +1,2 @@+#set($field = $response.response.facet_counts.facet_queries)+#display_facet_query($field, "Facet Queries", "")\ No newline at end of filediff --git a/solr/example/solr/conf/velocity/facet_ranges.vm b/solr/example/solr/conf/velocity/facet_ranges.vmnew file mode 100644index 00000000000..b5fcd4ccf2c--- /dev/null+++ b/solr/example/solr/conf/velocity/facet_ranges.vm@@ -0,0 +1,9 @@+#set($field = $response.response.facet_counts.facet_ranges.price.counts)+#set($start = $response.response.facet_counts.facet_ranges.price.start)+#set($end = $response.response.facet_counts.facet_ranges.price.end)+#set($gap = $response.response.facet_counts.facet_ranges.price.gap)+#set($before = $response.response.facet_counts.facet_ranges.price.before)+#set($after = $response.response.facet_counts.facet_ranges.price.after)+##TODO: Make this display the "range", not just the lower value+##TODO: Have a generic way to deal with ranges+#display_facet_range($field, "Price (in $)", "price", $start, $end, $gap, $before, $after)diff --git a/solr/example/solr/conf/velocity/facets.vm b/solr/example/solr/conf/velocity/facets.vmindex bd1fd3f085a..5c2355b9904 100644--- a/solr/example/solr/conf/velocity/facets.vm+++ b/solr/example/solr/conf/velocity/facets.vm@@ -10,3 +10,10 @@</ul>#end#end+#parse('facet_queries.vm')+#parse('facet_ranges.vm')+#parse('facet_dates.vm')+#parse('facet_pivot.vm')+++diff --git a/solr/example/solr/conf/velocity/hit.vm b/solr/example/solr/conf/velocity/hit.vmindex a312a0b0dd2..5b5d2ac73b1 100644--- a/solr/example/solr/conf/velocity/hit.vm+++ b/solr/example/solr/conf/velocity/hit.vm@@ -8,9 +8,10 @@#end#end<div class="result-document">- <p><b>#field('name')</b> $!number.currency($doc.getFieldValue('price'))</p>-- <p>#field('features')</p>+ <p><b>#field('name')</b></p>+ <p>Price: $!number.currency($doc.getFieldValue('price'))</p>+ <p>Features: #field('features')</p>+ <p>In Stock: #field('inStock')</p>#if($params.getBool("debugQuery",false))<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle explain</a>