<?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>function sorting &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/function-sorting-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl/en/</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Wed, 11 Nov 2020 08:18:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Sorting by function value in Solr (SOLR-1297)</title>
		<link>https://solr.pl/en/2011/02/28/sorting-by-function-value-in-solr-solr-1297/</link>
					<comments>https://solr.pl/en/2011/02/28/sorting-by-function-value-in-solr-solr-1297/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 28 Feb 2011 08:17:46 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[function sorting]]></category>
		<category><![CDATA[function value]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[SOLR-1297]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[sorting by function value]]></category>
		<category><![CDATA[value]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=217</guid>

					<description><![CDATA[In Solr 3.1 and later we have a very interesting functionality, which enables us to sort by function value. What that gives us ? Actually a few interesting possibilities. Let&#8217;s start The first example that comes to mind, perhaps because]]></description>
										<content:encoded><![CDATA[<p>In Solr 3.1 and later we have a very interesting functionality, which enables us to sort by function value. What that gives us ? Actually a few interesting possibilities.</p>
<p><span id="more-217"></span></p>
<h3>Let&#8217;s start</h3>
<p>The  first example that comes to mind, perhaps because of the project on  which I worked some time ago, it&#8217;s sorting on the  basis of distance  between two geographical points. So far, to implement such functionality was needed changes in Solr (for example,  <em>LocalSolr </em>or&nbsp;<em>LocalLucene</em>). Using Solr 3.1 and later, you can sort your search results using the value returned by the defined functions. For example, is Solr, we have the dist function calculating the distance between two points. One variation of the function is a function accepting five parameters: algorithm and two pairs of points. If,  using this feature, we would like to sort your search results in  ascending order from the point of latitude and longitude 0.0, we should  add the following sort parameter to the Solr query:
</p>
<pre class="brush:xml">...sort=dist(2, geo_x, geo_y, 0, 0) asc</pre>
<p>I suspect that the most commonly used values of the first parameter will be:</p>
<ul>
<li><em>1</em> &#8211; calculation based on the Manhattan metrics</li>
<li><em>2</em> &#8211; calculation of Euclidean distance</li>
</ul>
<h3>A few words about performance</h3>
<p>Everything is fine till now, but how it looks like in terms of performance ? I&#8217;ve made a two simple tests.</p>
<p>During  the first test, I indexed 200 000 documents, every one of them  consisted of four fields: identifier (numeric field), description (a<em> text</em> field) and location (two numeric fields). In  order not to obscure the test results for sorting, I used one of the  simplest functions currently available in the Solr &#8211; the <em>sum </em>function which sums two  given arguments. I compared the query time of the default sorting (by <em>score</em>) with the ones which used the value of the function. The following table shows the results of the test:</p>
[table “13” not found /]<br />

<p>Another test was based on a comparison of sorting by a string field to sort using function. The  test was almost identical to the first test. I&#8217;ve indexed 200,000  documents indexed (with additional field: <em>name_sort</em> &#8211; type <em>string</em>) and  used the <em>sum</em> function. The following table shows the results of the test:</p>
[table “15” not found /]<br />

<p>Above test shows that sorting using the sort function is much slower than the default sort order (which you&#8217;d expect). Sorting  on the basis of function value is also slower than sorting with the use  of <em>string </em>based field, but the difference is not as significant as in  the previous case.</p>
<h3>A few words at the end</h3>
<p>Of  course, the above test just glides through the topic of sorting  efficiency using Solr functions, however, shows a direct relationship. Given  that, in most cases, this will not be the default sort method and  giving us a really powerful tool it seems to me that this is a feature  worth remembering. It  will definitely be worth using when the requirements says that we have  to sort on the value that depends on the query and index values &#8211; as in  the case of sorting by distance from the point specified by the user.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2011/02/28/sorting-by-function-value-in-solr-solr-1297/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
