SOLR-2178: Added in spatial support, including maps, More Like This, etc.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1026129 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2010-10-21 20:28:11 +00:00
parent c684042025
commit 2629d2cbbc
12 changed files with 151 additions and 57 deletions

View File

@ -28,7 +28,8 @@
<field name="popularity">6</field>
<field name="inStock">true</field>
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
<field name="store">45.17614,-93.87341</field>
<!-- Near Oklahoma city -->
<field name="store">35.0752,-97.032</field>
</doc>
<doc>

View File

@ -32,7 +32,7 @@
<field name="price">399.00</field>
<field name="popularity">10</field>
<field name="inStock">true</field>
<!-- San Francisco store -->
<field name="store">37.7752,-122.4232</field>
<!-- Dodge City store -->
<field name="store">37.7752,-100.0232</field>
<field name="manufacturedate_dt">2005-10-12T08:00:00Z</field>
</doc></add>

View File

@ -43,8 +43,8 @@
<field name="price">74.99</field>
<field name="popularity">7</field>
<field name="inStock">true</field>
<!-- San Francisco store -->
<field name="store">37.7752,-122.4232</field>
<!-- Dodge City store -->
<field name="store">37.7752,-100.0232</field>
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
<field name="payloads">electronics|4.0 memory|2.0</field>

View File

@ -28,6 +28,6 @@
<field name="popularity">6</field>
<field name="inStock">true</field>
<!-- Buffalo store -->
<field name="store">45.17614,-93.87341</field>
<field name="store">43.17614,-90.57341</field>
</doc></add>

View File

@ -513,13 +513,18 @@
<str name="title">Solritas</str>
<!-- Query settings -->
<str name="defType">dismax</str>
<str name="defType">edismax</str>
<str name="qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
</str>
<str name="q.alt">*:*</str>
<str name="rows">10</str>
<str name="fl">*,score</str>
<str name="mlt.qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
</str>
<str name="mlt.fl">text,features,name,sku,id,manu,cat</str>
<int name="mlt.count">3</int>
<!-- Faceting defaults -->
<str name="facet">on</str>

View File

@ -4,7 +4,7 @@
#macro(url_for_solr)/solr#if($request.core.name != "")/$request.core.name#end#end
#macro(url_for_home)#url_for_solr/browse#end
#macro(q)q=$!{esc.url($params.get('q'))}#end
#macro(q)&q=$!{esc.url($params.get('q'))}#end
#macro(fqs $p)#foreach($fq in $p)#if($velocityCount>1)&#{end}fq=$esc.url($fq)#end#end
@ -14,15 +14,18 @@
#macro(annotate)#if($request.params.get('annotateBrowse'))&annotateBrowse=true#end#end
#macro(annTitle $msg)#if($annotate == true)title="$msg"#end#end
#macro(annTitle $msg)#if($annotate == true)title="$msg"#end#end
#macro(lens)?#q#if($request.params.getParams('fq') and $list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#debug#if($request.params.get('bf') == 'price')&bf=price#end#annotate#end
#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(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#if($list.size($p) > 0)&#fqs($p)#end#debug#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_nested_facet_query $field)#url_for_home#lens&fq=$esc.url($field)#end

View File

@ -1,33 +1,9 @@
#set($searcher=$request.searcher)
#set($params=$request.params)
#set($clusters = $response.response.clusters)
#set($annotate = $request.params.get("annotateBrowse"))
<div class="query-box">
<form id="query-form" action="#{url_for_home}" method="GET">
<div class="inputs"><span>Find: <input type="text" id="q" name="q" value="$!esc.html($params.get('q'))"/> <input type="submit"/> <input type="reset"/></span>
<div class="query-boost"><input type="checkbox" name="bf" #annTitle("Add the boost function &bf=price to the query") value="price" #if($request.params.get('bf') == 'price')checked="true"#end>Boost by Price</input> </div></div>
#if($request.params.get('debugQuery'))
<input type="hidden" name="debugQuery" value="true"/>
#end
#if($annotate == true)
<input type="hidden" name="annotateBrowse" value="true"/>
#end
#foreach($fq in $request.params.getParams('fq'))
<input type="hidden" name="fq" value="$esc.html($fq)"/>
#end
<div class="constraints">
#foreach($fq in $params.getParams('fq'))
#set($previous_fq_count=$velocityCount - 1)
&gt; <a style="{text-decoration: line-through;}" href="#url_for_filters($request.params.getParams('fq').subList(0,$previous_fq_count))">$fq</a>
#end
</div>
#if($request.params.get('debugQuery'))
<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle parsed query</a>
<pre style="display:none">$response.response.debug.parsedquery</pre>
#end
</form>
</div>
#set($mltResults = $response.response.get("moreLikeThis"))
#set($annotate = $params.get("annotateBrowse"))
#parse('query.vm')
#if($response.response.spellcheck.suggestions and $response.response.spellcheck.suggestions.size() > 0)
Did you mean <a href="#url_for_home?q=$esc.url($response.response.spellcheck.suggestions.collation)#if($list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#debug">$response.response.spellcheck.suggestions.collation</a>?
#end

View File

@ -1,16 +1,17 @@
<hr/>
Generated by <a href="http://wiki.apache.org/solr/VelocityResponseWriter">VelocityResponseWriter</a>
#if($request.params.get('debugQuery'))
<div>
<span>Options:</span>
#if($request.params.get('debugQuery'))
<a href="#url_for_home?#q#if($list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end">disable debug</a>
#else
#else
<a href="#url_for_lens&debugQuery=true">enable debug</a>
#end
#if($annotate)
#end
#if($annotate)
<a href="#url_for_home?#q#if($list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#boostPrice">disable annotation</a>
#else
#else
<a href="#url_for_lens&annotateBrowse=true">enable annotation</a>
#end
<a href="#url_for_lens&wt=xml#if($request.params.get('debugQuery'))&debugQuery=true#end">XML</a>
#end
<a #annTitle("Click to switch to an XML response: &wt=xml") href="#url_for_lens&wt=xml#if($request.params.get('debugQuery'))&debugQuery=true#end">XML</a></div>
<div>Generated by <a href="http://wiki.apache.org/solr/VelocityResponseWriter">VelocityResponseWriter</a></div>
<div><span>Documentation: </span> <a href="http://lucene.apache.org/solr">Solr Home Page</a>, <a href="http://wiki.apache.org/solr">Solr Wiki</a></div>
<div>Disclaimer: The locations displayed in this demonstration are purely fictional. It is more than likely that no store with the items listed actually exists at that location!</div>

View File

@ -1,6 +1,7 @@
#set($docId = $doc.getFieldValue('id'))
#macro(field $f)
#if($response.response.highlighting.get($doc.getFieldValue('id')).get($f).get(0))
$!response.response.highlighting.get($doc.getFieldValue('id')).get($f).get(0)
#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
@ -8,11 +9,31 @@
#end
#end
<div class="result-document">
<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>
<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&amp;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>

View File

@ -25,6 +25,7 @@
// http://localhost:8983/solr/terms?terms.fl=name&terms.prefix=i&terms.sort=count
});
</script>
</head>

View File

@ -89,6 +89,8 @@ a {
width: 80%;
}
.query-box, .constraints {
padding: 5px;
margin: 5px;
@ -111,7 +113,7 @@ a {
}
.query-boost {
width: 20%;
top: 10px;
left: 50px;
position: relative;
@ -147,6 +149,24 @@ a {
margin-bottom: 15px;
}
.result-document div{
padding: 5px;
}
.result-title{
width:60%;
}
.mlt{
}
.map{
float: right;
position: relative;
top: -25px;
}
.result-document:nth-child(2n+1) {
background-color: #eee;
}

View File

@ -0,0 +1,66 @@
<div class="query-box">
<form id="query-form" action="#{url_for_home}" method="GET">
<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'))
<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=""/>
</div>
</div>
#if($request.params.get('debugQuery'))
<input type="hidden" name="debugQuery" value="true"/>
#end
#if($annotate == true)
<input type="hidden" name="annotateBrowse" value="true"/>
#end
#foreach($fq in $request.params.getParams('fq'))
#if ($fq != "{!bbox}")
<input type="hidden" name="fq" id="allFQs" value="$esc.html($fq)"/>
#end
#end
<div class="constraints" #annTitle("Lists out the &fq filters. Click to remove.")>
#foreach($fq in $params.getParams('fq'))
#set($previous_fq_count=$velocityCount - 1)
#if($fq != '')
&gt; <a style="{text-decoration: line-through;}" href="#url_for_filters($request.params.getParams('fq').subList(0,$previous_fq_count))">$fq</a>
#end
#end
</div>
#if($request.params.get('debugQuery'))
<a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle parsed query</a>
<pre style="display:none">$response.response.debug.parsedquery</pre>
#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>