<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>[ ultramagnus ]</title>
	<atom:link href="http://www.ultramagnus.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.ultramagnus.org</link>
	<description></description>
	<lastBuildDate>Mon, 21 Dec 2009 23:08:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Solr Payloads</title>
		<link>http://www.ultramagnus.org/?p=1</link>
		<comments>http://www.ultramagnus.org/?p=1#comments</comments>
		<pubDate>Mon, 21 Dec 2009 02:47:39 +0000</pubDate>
		<dc:creator>emargee</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[payloads]]></category>
		<category><![CDATA[solr 1.4]]></category>

		<guid isPermaLink="false">http://www.ultramagnus.org/?p=1</guid>
		<description><![CDATA[Payloads are a new feature in Solr 1.4 .. There seems to be a lack of direct instructions about getting them working. This article explains why use them and how to get them up and running. ]]></description>
			<content:encoded><![CDATA[<p>On my current project we have a large central store of articles, each article is tagged with terms from a thesaurus and indexed in a Solr collection. There are a couple of issues with getting the expected results from the search..</p>
<h3>Scoring</h3>
<p>If we have a super simple schema:</p>
<ul>
<li>Id</li>
<li>Title</li>
<li>Summary</li>
<li>Tags</li>
</ul>
<p>.. and add two documents to the store .. </p>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>FELINE-ARTICLE-1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>The biggest feline in the world<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;summary&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Today a moggy of enormous proportions was found.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tags&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>cat dog monkey<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CANINE-ARTICLE-1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>The biggest canine in the world<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;summary&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Today a mutt of enormous proportions was found.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tags&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>dog monkey cat<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>.. obviously we have one document that is more about cats than dogs and visa versa, but when we search the tags field for &#8216;cat&#8217; the results we get back have an equal scoring according to Solr. THis is due to the fact that they contain the same terms, even if they are in a different order, and so score equally. Meaning that the dog article could appear before the cat article.</p>
<p>The ideal situation would be to weight tags so that we are able to say that one tag is more relevant than the others, luckily in Solr 1.4 we now have the option of a new field type called <strong>payloads</strong>.</p>
<p>Payloads work by using pairs of terms and numerical weightings .. e.g. <strong>cat | 1.5 | dog | 6.0 | monkey | 0.1</strong>. This would mean that the <strong>dog</strong> tag is more relevant in this article than the others. We should therefore change our field type in the solrschema.xml to use the <strong>payloads</strong> type and update our documents accordingly.</p>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>FELINE-ARTICLE-1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>The biggest feline in the world<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;summary&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Today a moggy of enormous proportions was found.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tags&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>cat|2.4 dog|1.2 monkey|0.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CANINE-ARTICLE-1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>The biggest canine in the world<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;summary&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Today a mutt of enormous proportions was found.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tags&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>dog|3.4 monkey|1.2 cat|0.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/doc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h3>Interlude &#8211; Code Section</h3>
<p>Unfortunately this is only half the battle, getting this to work in Solr takes a bit of work, while payloads are supported in the underlying Lucene engine and have a field type defined in the example schema some Java code is needed to get it to all hang together. I found this rather hard to find and in lots of little pieces and some of the syntax had chnaged between versions. I&#8217;ll repeat the code here just in case it can help anyone get up and running any quicker.</p>
<p>The first part is to add a similarity analyser to your schema.xml so that the values get indexed correctly.. </p>
<div class="codecolorer-container java twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">uk.org.company.solr</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.analysis.payloads.PayloadHelper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.search.DefaultSimilarity</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PayloadSimilarity <span style="color: #000000; font-weight: bold;">extends</span> DefaultSimilarity<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">float</span> scorePayload<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> docId, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> fieldName, <span style="color: #000066; font-weight: bold;">int</span> start, <span style="color: #000066; font-weight: bold;">int</span> end, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> payload, <span style="color: #000066; font-weight: bold;">int</span> offset, <span style="color: #000066; font-weight: bold;">int</span> length<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// can ignore length here, because we know it is encoded as 4 bytes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> PayloadHelper.<span style="color: #006633;">decodeFloat</span><span style="color: #009900;">&#40;</span>payload, offset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- schema.xml --&gt;</span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;similarity</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;uk.org.company.solr.PayloadSimilarity&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p>The next step is to add a payload query analyser &#8211; this is taken directly from <a href="https://issues.apache.org/jira/browse/SOLR-1485">https://issues.apache.org/jira/browse/SOLR-1485</a>.<br />
You must also update your solrconfig.xml</p>
<div class="codecolorer-container java twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">uk.org.company.solr</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.index.Term</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.queryParser.ParseException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.search.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.search.payloads.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.common.SolrException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.common.params.SolrParams</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.common.util.NamedList</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.request.SolrQueryRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.search.QParser</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.search.QParserPlugin</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.solr.search.QueryParsing</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PayloadTermQueryPlugin <span style="color: #000000; font-weight: bold;">extends</span> QParserPlugin <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>NamedList args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> QParser createParser<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> QParser<span style="color: #009900;">&#40;</span>qstr, localParams, params, req<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Query parse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> PayloadTermQuery<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> Term<span style="color: #009900;">&#40;</span>localParams.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>QueryParsing.<span style="color: #006633;">F</span><span style="color: #009900;">&#41;</span>, localParams.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>QueryParsing.<span style="color: #006633;">V</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createPayloadFunction<span style="color: #009900;">&#40;</span>localParams.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;func&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> PayloadFunction createPayloadFunction<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> func<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// TODO: refactor so that payload functions are registered as plugins and loaded</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// &nbsp; &nbsp; &nbsp; through SolrResourceLoader.</span><br />
<br />
&nbsp; &nbsp; PayloadFunction payloadFunction <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; payloadFunction <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MinPayloadFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;avg&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; payloadFunction <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AveragePayloadFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; payloadFunction <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaxPayloadFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>payloadFunction <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> SolrException<span style="color: #009900;">&#40;</span> SolrException.<span style="color: #006633;">ErrorCode</span>.<span style="color: #006633;">BAD_REQUEST</span>, <span style="color: #0000ff;">&quot;unknown PayloadFunction: &quot;</span> <span style="color: #339933;">+</span> func<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> payloadFunction<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- solrconfig.xml --&gt;</span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;queryParser</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;payload&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;uk.org.company.solr.PayloadTermQueryPlugin&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<h3> Querying </h3>
<p>We can now use this new query parser to search our documents and should get the results we expect .. i.e. that if we search for &#8216;cat&#8217; it should appear higher in the search results due to its weighting given in the payload field.</p>
<p>The query parser allows us to specify 3 modes for ordering the weighting Max, Average and Minimum.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://localhost:8983/solr/select?q={!payload%20f=tags%20func=max}cat&amp;debugQuery=true&amp;indent=on .. (MAX)<br />
http://localhost:8983/solr/select?q={!payload%20f=tags%20func=avg}cat&amp;debugQuery=true&amp;indent=on .. (AVG)<br />
http://localhost:8983/solr/select?q={!payload%20f=tags%20func=min}cat&amp;debugQuery=true&amp;indent=on .. (MIN)</div></div>
<p>.. with <strong>debugQuery</strong> on we can see how the new scoring is in effect.</p>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FELINE-ARTICLE-1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> <br />
0.5044795 = (MATCH) weight(payloads:cat in 0), product of:<br />
&nbsp; 0.99999994 = queryWeight(payloads:cat), product of:<br />
&nbsp; &nbsp; 0.5945349 = idf(payloads: &nbsp;cat=2)<br />
&nbsp; &nbsp; 1.681987 = queryNorm<br />
&nbsp; 0.5044796 = (MATCH) fieldWeight(payloads:cat in 0), product of:<br />
&nbsp; &nbsp; 1.6970563 = (MATCH) btq, product of:<br />
&nbsp; &nbsp; &nbsp; 0.70710677 = tf(phraseFreq=0.5)<br />
&nbsp; &nbsp; &nbsp; 2.4 = scorePayload(...)<br />
&nbsp; &nbsp; 0.5945349 = idf(payloads: &nbsp;cat=2)<br />
&nbsp; &nbsp; 0.5 = fieldNorm(field=payloads, doc=0)<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CANINE-ARTICLE-1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> <br />
0.02101998 = (MATCH) weight(payloads:cat in 1), product of:<br />
&nbsp; 0.99999994 = queryWeight(payloads:cat), product of:<br />
&nbsp; &nbsp; 0.5945349 = idf(payloads: &nbsp;cat=2)<br />
&nbsp; &nbsp; 1.681987 = queryNorm<br />
&nbsp; 0.021019982 = (MATCH) fieldWeight(payloads:cat in 1), product of:<br />
&nbsp; &nbsp; 0.07071068 = (MATCH) btq, product of:<br />
&nbsp; &nbsp; &nbsp; 0.70710677 = tf(phraseFreq=0.5)<br />
&nbsp; &nbsp; &nbsp; 0.1 = scorePayload(...)<br />
&nbsp; &nbsp; 0.5945349 = idf(payloads: &nbsp;cat=2)<br />
&nbsp; &nbsp; 0.5 = fieldNorm(field=payloads, doc=1)<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>While the project develops I will try to post some more on the techniques and technologies we are using to achieve certain our goals, hopefully using payloads can give us the flexibility and results we need for this part of our project. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ultramagnus.org/?feed=rss2&amp;p=1</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
