<?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>a work on process &#187; search terms</title>
	<atom:link href="http://jystewart.net/process/tag/search-terms/feed/" rel="self" type="application/rss+xml" />
	<link>http://jystewart.net/process</link>
	<description>notes from another web developer</description>
	<lastBuildDate>Sat, 21 Aug 2010 13:09:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Splitting search terms</title>
		<link>http://jystewart.net/process/2006/10/splitting-search-terms/</link>
		<comments>http://jystewart.net/process/2006/10/splitting-search-terms/#comments</comments>
		<pubDate>Mon, 30 Oct 2006 21:37:40 +0000</pubDate>
		<dc:creator>James Stewart</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[search code]]></category>
		<category><![CDATA[search terms]]></category>

		<guid isPermaLink="false">http://jystewart.net/process/archives/2006/10/splitting-search-terms/</guid>
		<description><![CDATA[The other day I wanted to break up a search string into its constituent parts. We&#8217;re not supporting any fancy operators, but we did want to allow phrases to be specified in double quotes. It&#8217;s an easy enough operation, but I googled to see if anyone was offering a particularly efficient way to do that <a href="http://jystewart.net/process/2006/10/splitting-search-terms/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>The other day I wanted to break up a search string into its constituent parts. We&#8217;re not supporting any fancy operators, but we did want to allow phrases to be specified in double quotes. It&#8217;s an easy enough operation, but I googled to see if anyone was offering a particularly efficient way to do that in ruby.</p>
<p>Nothing came up and since I&#8217;ve not posted in a while I thought I&#8217;d offer it for anyone else in that situation.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> split_params<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Find all phrases enclosed in quotes and pull </span>
  <span style="color:#008000; font-style:italic;"># them into a flat array of phrases</span>
  phrases = params.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;(.*?)&quot;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">flatten</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Remove those phrases from the original string</span>
  left_over = params.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;(.*?)&quot;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">squeeze</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Break up the remaining keywords on whitespace</span>
  keywords = left_over.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Return one single array of key phrases</span>
  keywords <span style="color:#006600; font-weight:bold;">+</span> phrases
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jystewart.net/process/2006/10/splitting-search-terms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
