<?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>Ian Winter &#187; sphinx</title>
	<atom:link href="http://ianwinter.co.uk/tag/sphinx/feed/" rel="self" type="application/rss+xml" />
	<link>http://ianwinter.co.uk</link>
	<description>Have you found the instructions yet?</description>
	<lastBuildDate>Thu, 13 May 2010 21:03:18 +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>Sphinx Multi-Value Attributes</title>
		<link>http://ianwinter.co.uk/2009/07/06/sphinx-multi-value-attributes/</link>
		<comments>http://ianwinter.co.uk/2009/07/06/sphinx-multi-value-attributes/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 10:03:18 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mva]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://ianwinter.co.uk/?p=1054</guid>
		<description><![CDATA[Sphinx allows you to create a multi-value attribute index which is great for document tags or categories. By default if you search across these the search is an OR match. If you want to run an AND match you must specify multiple filters rather than passing an array of values. In ColdFusion using the Java [...]]]></description>
			<content:encoded><![CDATA[<p>Sphinx allows you to create a multi-value attribute index which is great for document tags or categories. By default if you search across these the search is an OR match. If you want to run an AND match you must specify multiple filters rather than passing an array of values.</p>
<p>In ColdFusion using the Java API requires a little tweak as you can&#8217;t pass a normal ColdFusion array to sphinx, you have to use a basic java type array. Tim Blair has a <a href="http://tim.bla.ir/tech/articles/cf-and-arrays-of-basic-java-types" target="_blank">good article</a> on how to create them but here&#8217;s an example of calling the API.</p>
<p>This example will search for document tagged with either 100 or 200. Note the array creation method.</p>
<p><code>&lt;cfset variables.sphinx = createobject("java", "org.sphx.api.SphinxClient").init()&gt;<br />
&lt;cfset variables.sphinx.SetLimits(0, 10)&gt;<br />
&lt;cfset variables.arrObj = createobject("java", "java.lang.reflect.Array")&gt;<br />
&lt;cfset variables.jClass = createobject("java", "java.lang.Integer").TYPE&gt;<br />
&lt;cfset variables.jArr = variables.arrObj.newInstance(variables.jClass, 2)&gt;<br />
&lt;cfset variables.arrObj.setInt(variables.jArr, 0, 100)&gt;<br />
&lt;cfset variables.arrObj.setInt(variables.jArr, 1, 200)&gt;<br />
&lt;cfset variables.sphinx.SetFilter("tag", variables.jArr, FALSE)&gt;</code></p>
<p>If you want to search for 100 AND 200 you&#8217;d do it like this:</p>
<p><code>&lt;cfset variables.sphinx = createobject("java", "org.sphx.api.SphinxClient").init()&gt;<br />
&lt;cfset variables.sphinx.SetLimits(0, 10)&gt;<br />
&lt;cfset variables.sphinx.SetFilter("tag", 100, FALSE)&gt;<br />
&lt;cfset variables.sphinx.SetFilter("tag", 200, FALSE)&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ianwinter.co.uk/2009/07/06/sphinx-multi-value-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sphinx, ColdFusion and geodist</title>
		<link>http://ianwinter.co.uk/2009/06/30/sphinx-coldfusion-and-geodist/</link>
		<comments>http://ianwinter.co.uk/2009/06/30/sphinx-coldfusion-and-geodist/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 22:16:26 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[geodist]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://ianwinter.co.uk/?p=1034</guid>
		<description><![CDATA[Over the past few days I&#8217;ve been looking into a new search engine for an application. The chosen search daemon is sphinx and it&#8217;ll be called via the Java API (that comes with sphinx) from ColdFusion. Getting the basic searching going was pretty easy, creating an index, do a basic search, set some filters, done. [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past few days I&#8217;ve been looking into a new search engine for an application. The chosen search daemon is <a href="http://www.sphinxsearch.com/" target="_blank">sphinx</a> and it&#8217;ll be called via the Java API (that comes with sphinx) from ColdFusion. Getting the basic searching going was pretty easy, creating an index, do a basic search, set some filters, done. The next step was to look into geodist matching, calcuating how far apart two latitude / longitude&#8217;s are, slightly more tricky. In CF you can do it with some crazy curvature of the earth calculations but in sphinx it&#8217;s real easy &#8211; when you know what it wants. The key there is radians.</p>
<p>You&#8217;ll find plenty of tidbits on the web about this but no real end to end examples so hopefully this will help!</p>
<p>If you need to geocode some postcode or zip values I can highly recommend <a href="http://tinygeocoder.com/" target="_blank">tinygeocoder.com</a>. It&#8217;s basic and gives you a straight lat / long value which is perfect. If you want something with a bit more information you&#8217;ll need to check out the Yahoo! YDN <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html" target="_blank">geocode</a> API or Google&#8217;s HTTP API. I&#8217;ve got the YDN working with ColdFusion (I&#8217;ll post about that later).</p>
<p>First up you&#8217;ll need some data, I&#8217;ve created a basic DB table called <a href="http://ianwinter.co.uk/wp-content/uploads/2009/06/sphinx_test.sql" target="_blank">sphinx_test.sql</a> which you can download. It&#8217;s been written for MySQL. Quick note on the float values, if you don&#8217;t specific float 10,6 (or something similar) your lat/longs will automatically be chopped to only 4 decimal places.</p>
<p>The SQL contains 3 locations in England. The British Airways London Eye (51.502893,-0.118811), Millennium Dome (51.501984,0.004764) and Windsor Castle (51.481971,-0.600686).</p>
<p>Once you&#8217;ve created your table you&#8217;re ready to create an index. I&#8217;m going to assume you&#8217;ve already installed sphinx in /opt/sphinx (this is on a CentOS platform). To get the Java API part for ColdFusion is easy as well.</p>
<p><code>[root@hosting ~]# cd /root/sphinx-0.9.9-rc2/api/java<br />
[root@hosting ~]# make<br />
[root@hosting ~]# cp sphinxapi.jar /opt/coldfusion8/runtime/servers/lib<br />
[root@hosting ~]# /opt/coldfusion8/bin/coldfusion restart</code></p>
<p>This is the <a href="http://ianwinter.co.uk/wp-content/uploads/2009/06/sphinx.conf" target="_blank">sphinx.conf</a> you&#8217;ll need to get this running. Now there&#8217;s a whole load of stuff you could do in the configure file but I&#8217;ll just give you a basic one which should be enough.</p>
<p>Note you have two options when it comes to getting the lat/long from MySQL, you can either use RADIANS(val) or use a pre-stored the radian value of the lat / long In this case we&#8217;re going to use the latter but I&#8217;ve included a commented line for the former.</p>
<p>Now for the actual code that does the work. I&#8217;ve created a file called <a href="http://ianwinter.co.uk/wp-content/uploads/2009/06/sphinx.cfm" target="_blank">sphinx.cfm</a> (view <a href="../wp-content/uploads/2009/06/sphinx.txt" target="_blank">as text</a> or click it to actually see it working) with comments inline. The interesting parts are:</p>
<p><code>&lt;!--- sort order must be @geodist to allow distance matching ---&gt;<br />
&lt;cfset variables.sphinx.SetSortMode(variables.sphinx.SPH_SORT_EXTENDED, '@geodist desc')&gt;</code></p>
<p><code>&lt;!--- where are we starting, this will be the london eye latlong converted to radians ---&gt;<br />
&lt;cfset variables.sphinx.SetGeoAnchor('latitude', 'longitude', degreesToRadians(51.502893), degreesToRadians(-0.118811))&gt;<br />
</code></p>
<p>All of the API calls are the same as the documented PHP functions so you can refer to the <a href="http://www.sphinxsearch.com/wiki/doku.php?id=php_api_docs" target="_blank">documentation</a> for more information.</p>
<p>Thanks go out to various bloggers and <a href="http://tim.bla.ir" target="_blank">Tim</a> to get this running.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianwinter.co.uk/2009/06/30/sphinx-coldfusion-and-geodist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
