mirror of https://github.com/apache/lucene.git
SOLR-2178: Hook in result grouping, separate out into examples to declutter the screen a bit
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1027788 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0f52c2de16
commit
c62a0192bc
|
@ -18,14 +18,19 @@
|
|||
|
||||
#macro(spatial)#if($request.params.get('sfield'))&sfield=store#end#if($request.params.get('pt'))&pt=$request.params.get('pt')#end#if($request.params.get('d'))&d=$request.params.get('d')#end#end
|
||||
|
||||
#macro(lensNoQ)?#if($request.params.getParams('fq') and $list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#debug#boostPrice#annotate#spatial#end
|
||||
#macro(qOpts)#set($queryOpts = $request.params.get("queryOpts"))#if($queryOpts && $queryOpts != "")&queryOpts=$queryOpts#end#end
|
||||
|
||||
#macro(group)#if($request.params.getBool("group") == true)&group=true#end#if($request.params.get("group.field"))#foreach($grp in $request.params.getParams('group.field'))&group.field=$grp#end#end#end
|
||||
|
||||
#macro(lensNoQ)?#if($request.params.getParams('fq') and $list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#debug#boostPrice#annotate#spatial#qOpts#group#end
|
||||
#macro(lens)#lensNoQ#q#end
|
||||
|
||||
|
||||
#macro(url_for_lens)#{url_for_home}#lens#end
|
||||
|
||||
#macro(url_for_start $start)#url_for_home#lens&start=$start#end
|
||||
|
||||
#macro(url_for_filters $p)#url_for_home?#q#boostPrice#spatial#if($list.size($p) > 0)&#fqs($p)#end#debug#end
|
||||
#macro(url_for_filters $p)#url_for_home?#q#boostPrice#spatial#qOpts#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
|
||||
|
||||
|
@ -166,3 +171,13 @@
|
|||
</ul>
|
||||
#end
|
||||
#end
|
||||
|
||||
#macro(field $f)
|
||||
#if($response.response.highlighting.get($docId).get($f).get(0))
|
||||
$!response.response.highlighting.get($docId).get($f).get(0)
|
||||
#else
|
||||
#foreach($v in $doc.getFieldValues($f))
|
||||
$v
|
||||
#end
|
||||
#end
|
||||
#end
|
|
@ -13,23 +13,33 @@
|
|||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
<span><span class="results-found">$page.results_found</span> results found in ${response.responseHeader.QTime} ms</span>
|
||||
#if($response.response.get('grouped'))
|
||||
<span><span class="results-found">$response.response.get('grouped').size() group(s)</span> found in ${response.responseHeader.QTime} ms</span>
|
||||
#else<span><span class="results-found">$page.results_found</span> results found in ${response.responseHeader.QTime} ms</span>
|
||||
Page <span class="page-num">$page.current_page_number</span> of <span
|
||||
class="page-count">$page.page_count</span>
|
||||
class="page-count">$page.page_count</span>#end
|
||||
</div>
|
||||
|
||||
<div class="results">
|
||||
#if($response.response.get('grouped'))
|
||||
#foreach($grouping in $response.response.get('grouped'))
|
||||
#parse("hitGrouped.vm")
|
||||
#end
|
||||
#else
|
||||
#foreach($doc in $response.results)
|
||||
#parse("hit.vm")
|
||||
#end
|
||||
#end
|
||||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
#if($response.response.get('grouped'))
|
||||
#else
|
||||
#link_to_previous_page("previous")
|
||||
<span class="results-found">$page.results_found</span> results found.
|
||||
Page <span class="page-num">$page.current_page_number</span> of <span
|
||||
class="page-count">$page.page_count</span>
|
||||
#link_to_next_page("next")
|
||||
|
||||
#end
|
||||
<br/>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<div class="result-title"><b>#field('name')</b><span class="mlt">#if($params.getBool('mlt', false) == false)<a href="#lensNoQ&q=id:$docId&mlt=true">More Like This</a>#end</span></div>
|
||||
##do we have a physical store for this product
|
||||
#set($store = $doc.getFieldValue('store'))
|
||||
#if($store)<div class="map"><img src="http://maps.google.com/maps/api/staticmap?&zoom=12&size=150x80&maptype=roadmap&markers=$doc.getFieldValue('store')&sensor=false" /><div><small><a target="_map" href="http://maps.google.com/?q=$store&source=embed">Larger Map</a></small></div></div>#end
|
||||
<div>Price: $!number.currency($doc.getFieldValue('price'))</div>
|
||||
<div>Features: #field('features')</div>
|
||||
<div>In Stock: #field('inStock')</div>
|
||||
<div class="mlt">
|
||||
#set($mlt = $mltResults.get($docId))
|
||||
#set($mltOn = $params.getBool('mlt'))
|
||||
#if($mltOn == true)<div class="field-name">Similar Items</div>#end
|
||||
#if ($mltOn && $mlt && $mlt.size() > 0)
|
||||
<ul>
|
||||
#foreach($mltHit in $mlt)
|
||||
#set($mltId = $mltHit.getFieldValue('id'))
|
||||
<li><div><a href="#url_for_home?q=id:$mltId">$mltId</a></div><div><span class="field-name">Name:</span> $mltHit.getFieldValue('name')</div>
|
||||
<div><span class="field-name">Price:</span> $!number.currency($mltHit.getFieldValue('price')) <span class="field-name">In Stock:</span> $mltHit.getFieldValue('inStock')</div>
|
||||
|
||||
</li>
|
||||
#end
|
||||
</ul>
|
||||
#elseif($mltOn && $mlt.size() == 0)
|
||||
<div>No Similar Items Found</div>
|
||||
#end
|
||||
</div>
|
||||
#if($params.getBool("debugQuery",false))
|
||||
<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle explain</a>
|
||||
<pre style="display:none">$response.getExplainMap().get($doc.getFirstValue('id'))</pre>
|
||||
#end
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
## An example of using an arbitrary request parameter
|
||||
<title>#param('title')</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||
|
||||
<script type="text/javascript" src="#{url_for_solr}/admin/jquery-1.2.3.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="#{url_for_solr}/admin/file?file=/velocity/main.css&contentType=text/css"/>
|
||||
<link rel="stylesheet" href="#{url_for_solr}/admin/file?file=/velocity/jquery.autocomplete.css&contentType=text/css" type="text/css" />
|
||||
<script type="text/javascript" src="#{url_for_solr}/admin/file?file=/velocity/jquery.autocomplete.js&contentType=text/javascript"></script>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("\#q").autocomplete('#{url_for_solr}/terms', { ## backslash escaped #q as that is a macro defined in VM_global_library.vm
|
||||
extraParams:{
|
||||
'terms.prefix': function() { return $("\#q").val();},
|
||||
'terms.sort': 'count',
|
||||
'terms.fl': 'name',
|
||||
'wt': 'velocity',
|
||||
'v.template': 'suggest'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// http://localhost:8983/solr/terms?terms.fl=name&terms.prefix=i&terms.sort=count
|
||||
});
|
||||
|
||||
</script>
|
|
@ -1,41 +1,5 @@
|
|||
#set($docId = $doc.getFieldValue('id'))
|
||||
#macro(field $f)
|
||||
#if($response.response.highlighting.get($docId).get($f).get(0))
|
||||
$!response.response.highlighting.get($docId).get($f).get(0)
|
||||
#else
|
||||
#foreach($v in $doc.getFieldValues($f))
|
||||
$v
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
<div class="result-document">
|
||||
<div class="result-title"><b>#field('name')</b><span class="mlt">#if($params.getBool('mlt', false) == false)<a href="#lensNoQ&q=id:$docId&mlt=true">More Like This</a>#end</span></div>
|
||||
##do we have a physical store for this product
|
||||
#set($store = $doc.getFieldValue('store'))
|
||||
#if($store)<div class="map"><img src="http://maps.google.com/maps/api/staticmap?&zoom=12&size=150x80&maptype=roadmap&markers=$doc.getFieldValue('store')&sensor=false" /><div><small><a target="_map" href="http://maps.google.com/?q=$store&source=embed">Larger Map</a></small></div></div>#end
|
||||
<div>Price: $!number.currency($doc.getFieldValue('price'))</div>
|
||||
<div>Features: #field('features')</div>
|
||||
<div>In Stock: #field('inStock')</div>
|
||||
<div class="mlt">
|
||||
#set($mlt = $mltResults.get($docId))
|
||||
#set($mltOn = $params.getBool('mlt'))
|
||||
#if($mltOn == true)<div class="field-name">Similar Items</div>#end
|
||||
#if ($mltOn && $mlt && $mlt.size() > 0)
|
||||
<ul>
|
||||
#foreach($mltHit in $mlt)
|
||||
#set($mltId = $mltHit.getFieldValue('id'))
|
||||
<li><div><a href="#url_for_home?q=id:$mltId">$mltId</a></div><div><span class="field-name">Name:</span> $mltHit.getFieldValue('name')</div>
|
||||
<div><span class="field-name">Price:</span> $!number.currency($mltHit.getFieldValue('price')) <span class="field-name">In Stock:</span> $mltHit.getFieldValue('inStock')</div>
|
||||
|
||||
</li>
|
||||
#end
|
||||
</ul>
|
||||
#elseif($mltOn && $mlt.size() == 0)
|
||||
<div>No Similar Items Found</div>
|
||||
#end
|
||||
</div>
|
||||
#if($params.getBool("debugQuery",false))
|
||||
<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle explain</a>
|
||||
<pre style="display:none">$response.getExplainMap().get($doc.getFirstValue('id'))</pre>
|
||||
#end
|
||||
<div class="result-document">
|
||||
#parse("doc.vm")
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<div class="result-document">
|
||||
<div class="result-title"><b>$grouping.key</b></div>
|
||||
<div>Total Matches in Group: $grouping.value.matches</div>
|
||||
<div>#foreach ($group in $grouping.value.groups)
|
||||
<div class="group-value">$group.groupValue <span #annTitle("The count of the number of documents in this group")>($group.doclist.numFound)</span></div>
|
||||
<div class="group-doclist" #annTitle("Contains the top scoring documents in the group")>
|
||||
#foreach ($doc in $group.doclist)
|
||||
#set($docId = $doc.getFieldValue('id'))
|
||||
#parse("doc.vm")
|
||||
#end
|
||||
</div>
|
||||
#end</div>
|
||||
</div>
|
||||
#if($params.getBool("debugQuery",false))
|
||||
<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle explain</a>
|
||||
<pre style="display:none">$response.getExplainMap().get($doc.getFirstValue('id'))</pre>
|
||||
#end
|
||||
</div>
|
|
@ -1,47 +1,20 @@
|
|||
<html>
|
||||
<head>
|
||||
## An example of using an arbitrary request parameter
|
||||
<title>#param('title')</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||
|
||||
<script type="text/javascript" src="#{url_for_solr}/admin/jquery-1.2.3.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="#{url_for_solr}/admin/file?file=/velocity/main.css&contentType=text/css"/>
|
||||
<link rel="stylesheet" href="#{url_for_solr}/admin/file?file=/velocity/jquery.autocomplete.css&contentType=text/css" type="text/css" />
|
||||
<script type="text/javascript" src="#{url_for_solr}/admin/file?file=/velocity/jquery.autocomplete.js&contentType=text/javascript"></script>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("\#q").autocomplete('#{url_for_solr}/terms', { ## backslash escaped #q as that is a macro defined in VM_global_library.vm
|
||||
extraParams:{
|
||||
'terms.prefix': function() { return $("\#q").val();},
|
||||
'terms.sort': 'count',
|
||||
'terms.fl': 'name',
|
||||
'wt': 'velocity',
|
||||
'v.template': 'suggest'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// http://localhost:8983/solr/terms?terms.fl=name&terms.prefix=i&terms.sort=count
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
#parse("head.vm")
|
||||
</head>
|
||||
<body>
|
||||
<div id="admin"><a href="#url_for_solr/admin">Solr Admin</a></div>
|
||||
<div id="header">
|
||||
#parse("header.vm")
|
||||
</div>
|
||||
|
||||
<div id="tabs">
|
||||
#parse("tabs.vm")
|
||||
</div>
|
||||
<div id="content">
|
||||
$content
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
#parse("footer.vm")
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -122,7 +122,6 @@ a {
|
|||
|
||||
.query-box .inputs{
|
||||
left: 180px;
|
||||
top: -20px;
|
||||
position: relative;
|
||||
|
||||
}
|
||||
|
@ -179,3 +178,7 @@ a {
|
|||
li.show {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
.group-value{
|
||||
font-weight: bold;
|
||||
}
|
|
@ -3,21 +3,8 @@
|
|||
<div class="inputs">
|
||||
<span #annTitle("Add the query using the &q= parameter")>Find: <input type="text" id="q" name="q" value="$!esc.html($params.get('q'))"/> <input type="submit" id="querySubmit"/> <input type="reset"/></span>
|
||||
<div class="query-boost"><span #annTitle("Add the boost function &bf=price to the query")><input type="checkbox" name="bf" value="price" #if($request.params.get('bf') == 'price')checked="true"#end>Boost by Price</input></span>
|
||||
<span >
|
||||
#set($loc = $request.params.get('pt'))
|
||||
#set($dist = $request.params.get('d', "10"))
|
||||
<label #annTitle("Add the &pt parameter")>Location Filter:
|
||||
<select id="pt" name="pt">
|
||||
<option value="none" #if($loc == '')selected="true"#end>No Filter</option>
|
||||
<option value="45.17614,-93.87341" #if($loc == '45.17614,-93.87341')selected="true"#end>Buffalo, MN</option>
|
||||
<option value="37.7752,-100.0232" #if($loc == '37.7752,-100.0232')selected="true"#end>Dodge City, KS</option>
|
||||
<option value="35.0752,-97.032" #if($loc == '35.0752,-97.032')selected="true"#end>Oklahoma City, OK</option>
|
||||
<option value="37.7752,-122.4232" #if($loc == '37.7752,-122.4232')selected="true"#end>San Francisco CA</option>
|
||||
</select>
|
||||
</label>
|
||||
<span #annTitle("Add the &d parameter")>Distance (KM): <input id="d" name="d" type="text" size="6" value="#if($dist != '')${dist}#{else}10#end"/></span>
|
||||
<input type="hidden" name="sfield" value="store"/>
|
||||
<input type="hidden" id="spatialFQ" name="fq" value=""/>
|
||||
#parse("querySpatial.vm")
|
||||
#parse("queryGroup.vm")
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -44,23 +31,10 @@
|
|||
<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle parsed query</a>
|
||||
<pre style="display:none">$response.response.debug.parsedquery</pre>
|
||||
#end
|
||||
#set($queryOpts = $request.params.get("queryOpts"))
|
||||
#if($queryOpts && $queryOpts != "")
|
||||
<input type="hidden" name="queryOpts" value="$queryOpts"/>
|
||||
#end
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
$('#query-form').submit(function() {
|
||||
if ($("#pt").val() != "none") {
|
||||
$("#spatialFQ").val("{!bbox}");
|
||||
//return false;
|
||||
}
|
||||
$fqs = $("#allFQs").val();
|
||||
$fqs = $fqs.replace("{!bbox}", "");
|
||||
if ($fqs == ''){
|
||||
$("#allFQs").remove();
|
||||
}
|
||||
$("#allFQs").val($fqs);
|
||||
//$("#spatialFQ").remove();
|
||||
alert($fqs);
|
||||
//alert("false");
|
||||
return true;
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#set($queryOpts = $params.get("queryOpts"))
|
||||
#if($queryOpts == "group")
|
||||
<div>
|
||||
#set($groupF = $request.params.get('group.field'))
|
||||
<label #annTitle("Add the &group.field parameter. Multiselect is supported")>Group By:
|
||||
<select id="group" name="group.field" multiple="true">
|
||||
##TODO: Handle multiple selects correctly
|
||||
<option value="none"
|
||||
#if($groupF == '')selected="true"#end>No Group</option>
|
||||
<option value="manu_exact"
|
||||
#if($groupF == 'manu_exact')selected="true"#end>Manufacturer</option>
|
||||
<option value="popularity"
|
||||
#if($groupF == 'popularity')selected="true"#end>Popularity</option>
|
||||
</select>
|
||||
</label>
|
||||
<input type="hidden" name="group" value="true"/>
|
||||
</div>
|
||||
|
||||
#end
|
|
@ -0,0 +1,40 @@
|
|||
#set($queryOpts = $params.get("queryOpts"))
|
||||
#if($queryOpts == "spatial")
|
||||
<div>
|
||||
#set($loc = $request.params.get('pt'))
|
||||
#set($dist = $request.params.get('d', "10"))
|
||||
<label #annTitle("Add the &pt parameter")>Location Filter:
|
||||
<select id="pt" name="pt">
|
||||
<option value="none"
|
||||
#if($loc == '')selected="true"#end>No Filter</option>
|
||||
<option value="45.17614,-93.87341"
|
||||
#if($loc == '45.17614,-93.87341')selected="true"#end>Buffalo, MN</option>
|
||||
<option value="37.7752,-100.0232"
|
||||
#if($loc == '37.7752,-100.0232')selected="true"#end>Dodge City, KS</option>
|
||||
<option value="35.0752,-97.032"
|
||||
#if($loc == '35.0752,-97.032')selected="true"#end>Oklahoma City, OK</option>
|
||||
<option value="37.7752,-122.4232"
|
||||
#if($loc == '37.7752,-122.4232')selected="true"#end>San Francisco CA</option>
|
||||
</select>
|
||||
</label>
|
||||
<span #annTitle("Add the &d parameter")>Distance (KM): <input id="d" name="d" type="text" size="6"
|
||||
value="#if($dist != '')${dist}#{else}10#end"/></span>
|
||||
<input type="hidden" name="sfield" value="store"/>
|
||||
<input type="hidden" id="spatialFQ" name="fq" value=""/>
|
||||
<input type="hidden" name="queryOpts" value="spatial"/>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$('#query-form').submit(function() {
|
||||
if ($("#pt").val() != "none") {
|
||||
$("#spatialFQ").val("{!bbox}");
|
||||
}
|
||||
$fqs = $("#allFQs").val();
|
||||
$fqs = $fqs.replace("{!bbox}", "");
|
||||
if ($fqs == ''){
|
||||
$("#allFQs").remove();
|
||||
}
|
||||
$("#allFQs").val($fqs);
|
||||
return true;
|
||||
});
|
||||
</script>
|
||||
#end
|
|
@ -0,0 +1,6 @@
|
|||
##TODO: Make some nice tabs here
|
||||
#set($queryOpts = $params.get("queryOpts"))
|
||||
<span #annTitle("Click the link to demonstrate various Solr capabilities")><span>Examples: </span><span class="tab">#if($queryOpts && $queryOpts != "")<a href="#url_for_home">Simple</a>#{else}Simple#end</span>
|
||||
<span class="tab">#if($queryOpts == "spatial")Spatial#else<a href="#url_for_home?&queryOpts=spatial">Spatial</a>#end</span>
|
||||
<span class="tab">#if($queryOpts == "group")Group By#else<a href="#url_for_home?&queryOpts=group&group=true&group.field=manu_exact">Group By</a>#end</span></span>
|
||||
<hr/>
|
|
@ -35,7 +35,7 @@ public class PageTool {
|
|||
if (rows != null) {
|
||||
results_per_page = new Integer(rows);
|
||||
}
|
||||
|
||||
//TODO: Handle group by results
|
||||
Object docs = response.getValues().get("response");
|
||||
if (docs != null) {
|
||||
if (docs instanceof DocSlice) {
|
||||
|
|
Loading…
Reference in New Issue