SOLR-1957: Move VelocityResponseWriter from contrib to core

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@955796 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2010-06-18 00:24:41 +00:00
parent 04765f68d1
commit e2b625af45
22 changed files with 295 additions and 12 deletions

View File

@ -27,6 +27,7 @@ Versions of Major Components
Apache Lucene trunk Apache Lucene trunk
Apache Tika 0.6 Apache Tika 0.6
Carrot2 3.1.0 Carrot2 3.1.0
Velocity 1.6.1
Upgrading from Solr 1.4 Upgrading from Solr 1.4
@ -180,6 +181,9 @@ New Features
* SOLR-1932: New relevancy function queries: termfreq, tf, docfreq, idf * SOLR-1932: New relevancy function queries: termfreq, tf, docfreq, idf
norm, maxdoc, numdocs. (yonik) norm, maxdoc, numdocs. (yonik)
* SOLR-1957: The VelocityResponseWriter contrib moved to core.
Example search UI now available at http://localhost:8983/solr/browse
(ehatcher)
Optimizations Optimizations

View File

@ -55,7 +55,6 @@
classpath, this is useful for including all jars in a directory. classpath, this is useful for including all jars in a directory.
--> -->
<lib dir="../../contrib/extraction/lib" /> <lib dir="../../contrib/extraction/lib" />
<lib dir="../../contrib/velocity/src/main/solr/lib" />
<!-- When a regex is specified in addition to a directory, only the files in that <!-- When a regex is specified in addition to a directory, only the files in that
directory which completely match the regex (anchored on both ends) directory which completely match the regex (anchored on both ends)
will be included. will be included.
@ -510,6 +509,37 @@
</lst> </lst>
</requestHandler> </requestHandler>
<!--
-->
<requestHandler name="/browse" class="solr.SearchHandler">
<lst name="defaults">
<str name="wt">velocity</str>
<str name="v.template">browse</str>
<str name="v.layout">layout</str>
<str name="title">Solritas</str>
<str name="defType">dismax</str>
<str name="q.alt">*:*</str>
<str name="rows">10</str>
<str name="fl">*,score</str>
<str name="facet">on</str>
<str name="facet.field">cat</str>
<str name="facet.field">manu_exact</str>
<str name="facet.mincount">1</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="hl">on</str>
<str name="hl.fl">text features name</str>
<str name="f.name.hl.fragsize">0</str>
<str name="f.name.hl.alternateField">name</str>
</lst>
</requestHandler>
<!-- Please refer to http://wiki.apache.org/solr/SolrReplication for details on configuring replication --> <!-- Please refer to http://wiki.apache.org/solr/SolrReplication for details on configuring replication -->
<!-- remove the <lst name="master"> section if this is just a slave --> <!-- remove the <lst name="master"> section if this is just a slave -->
<!-- remove the <lst name="slave"> section if this is just a master --> <!-- remove the <lst name="slave"> section if this is just a master -->
@ -1022,14 +1052,13 @@
<queryResponseWriter name="ruby" class="solr.RubyResponseWriter"/> <queryResponseWriter name="ruby" class="solr.RubyResponseWriter"/>
<queryResponseWriter name="php" class="solr.PHPResponseWriter"/> <queryResponseWriter name="php" class="solr.PHPResponseWriter"/>
<queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/> <queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/>
<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter"/>
Custom response writers can be declared as needed... Custom response writers can be declared as needed...
<queryResponseWriter name="custom" class="com.example.MyResponseWriter"/> <queryResponseWriter name="custom" class="com.example.MyResponseWriter"/>
--> -->
<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter"/>
<!-- XSLT response writer transforms the XML output by any xslt file found <!-- XSLT response writer transforms the XML output by any xslt file found
in Solr's conf/xslt directory. Changes to xslt files are checked for in Solr's conf/xslt directory. Changes to xslt files are checked for
every xsltCacheLifetimeSeconds. every xsltCacheLifetimeSeconds.

View File

@ -1,11 +1,46 @@
#macro(nl2ul $named_list) #macro(param $key)$request.params.get($key)#end
<ul>
#foreach($kv in $named_list) #macro(url_for_solr)/solr#end
<li>$kv.key ($kv.value) #macro(url_for_home)#url_for_solr/browse#end
#nl2ul($kv.value)
</li> #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
#macro(debug)#if($request.params.get('debugQuery'))&debugQuery=true#end#end
#macro(lens)?#q#if($list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#debug#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
## 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(link_to_previous_page $text)
#if($page.current_page_number > 1)
#set($prev_start = $page.start - $page.results_per_page)
<a class="prev-page" href="#url_for_start($prev_start)">$text</a>
#end #end
</ul>
#end #end
#macro(param $key)$request.params.get($key)#end #macro(link_to_next_page $text)
#if($page.current_page_number < $page.page_count)
#set($next_start = $page.start + $page.results_per_page)
<a class="next-page" href="#url_for_start($next_start)">$text</a>
#end
#end
#macro(link_to_page $page_number $text)
#if($page_number == $page.current_page_number)
$text
#else
#if($page_number <= $page.page_count)
#set($page_start = $page_number * $page.results_per_page - $page.results_per_page)
<a class="page" href="#url_for_start($page_start)">$text</a>
#end
#end
#end

View File

@ -0,0 +1,55 @@
#set($searcher=$request.searcher)
#set($params=$request.params)
#set($clusters = $response.response.clusters)
<div class="query-box">
<form id="query-form" action="#{url_for_home}#fqs($request.params.getParams('fq'))" method="GET">
<a href="#url_for_home#if($request.params.get('debugQuery'))?debugQuery=true#end">Find</a>: <input type="text" name="q" value="$!esc.html($params.get('q'))"/>
#if($request.params.get('debugQuery'))
<input type="hidden" name="debugQuery" value="true"/>
#end
<div>
#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>
<script language="text/javascript">
$("input[type=text]").autoSuggest("/solr/suggest", {selectedItemProp: "name", searchObjProps: "name"}});
</script>
</div>
#if($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
<div class="navigators">
#parse("facets.vm")
</div>
<div class="pagination">
<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>
</div>
<div class="results">
#foreach($doc in $response.results)
#parse("hit.vm")
#end
</div>
<div class="pagination">
#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")
<br/>
</div>

View File

@ -0,0 +1,12 @@
#if($response.facetFields)
<h2>Facets</h2>
#foreach($field in $response.facetFields)
<span class="facet-field">$field.name</span>
<ul>
#foreach($facet in $field.values)
<li><a href="#url_for_facet_filter($field.name, $facet.name)">$facet.name</a> ($facet.count)</li>
#end
</ul>
#end
#end

View File

@ -0,0 +1,7 @@
<hr/>
Generated by <a href="http://wiki.apache.org/solr/VelocityResponseWriter">VelocityResponseWriter</a>
#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
<a href="#url_for_lens&debugQuery=true">enable debug</a>
#end

View File

@ -0,0 +1 @@
## empty header, customize as desired

View File

@ -0,0 +1,19 @@
#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)
#else
#foreach($v in $doc.getFieldValues($f))
$v
#end
#end
#end
<div class="result-document">
<p><b>#field('name')</b> $!number.currency($doc.getFieldValue('price'))</p>
<p>#field('features')</p>
#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>

View File

@ -0,0 +1,23 @@
<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="/solr/admin/jquery-1.2.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="/solr/admin/file?file=/velocity/main.css&contentType=text/css"/>
</head>
<body>
<div id="header">
#parse("header.vm")
</div>
<div id="content">
$content
</div>
<div id="footer">
#parse("footer.vm")
</div>
</body>
</html>

View File

@ -0,0 +1,96 @@
.array-field {
border: 2px solid #474747;
background: #FFE9D8;
padding: 5px;
margin: 5px;
}
.array-field-list li {
list-style: circle;
margin-left: 20px;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
.constraints-title {
background: gray;
}
.navigators {
float: left;
margin: 5px;
margin-top: 0px;
background: #FEC293;
border: 2px solid #474747;
width: 185px;
padding: 2px;
}
.facet-field {
font-weight: bold;
}
.highlight {
color: white;
background-color: gray;
border: 1px black solid;
}
.highlight-box {
margin-left: 15px;
}
.field-name {
font-weight: bold;
}
.highlighted-facet-field {
background: white;
}
#logo {
margin: 10px;
}
.query-box, .constraints {
padding: 5px;
margin: 5px;
border: 3px solid #474747;
color: white;
background: #FD9644;
font-weight: bold;
font-size: 16px;
}
.query-box input {
margin-left: 8px;
width: 85%;
}
.pagination {
padding-left: 33%;
font-weight: bold;
background: gray;
color: white;
margin: 5px;
margin-left: 200px;
}
.result-document {
border: 3px solid #474747;
background: #FEC293;
padding: 5px;
margin: 5px;
margin-left: 200px;
}
.selected-facet-field {
font-weight: bold;
}
li.show {
list-style: disc;
}

View File

@ -43,6 +43,7 @@ import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.response.RawResponseWriter; import org.apache.solr.response.RawResponseWriter;
import org.apache.solr.response.RubyResponseWriter; import org.apache.solr.response.RubyResponseWriter;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.response.VelocityResponseWriter;
import org.apache.solr.response.XMLResponseWriter; import org.apache.solr.response.XMLResponseWriter;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.QParserPlugin; import org.apache.solr.search.QParserPlugin;
@ -1406,6 +1407,7 @@ public final class SolrCore implements SolrInfoMBean {
m.put("ruby", new RubyResponseWriter()); m.put("ruby", new RubyResponseWriter());
m.put("raw", new RawResponseWriter()); m.put("raw", new RawResponseWriter());
m.put("javabin", new BinaryResponseWriter()); m.put("javabin", new BinaryResponseWriter());
m.put("velocity", new VelocityResponseWriter());
DEFAULT_RESPONSE_WRITERS = Collections.unmodifiableMap(m); DEFAULT_RESPONSE_WRITERS = Collections.unmodifiableMap(m);
} }