<?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>Der Gleisarbeiter &#187; Ferret</title>
	<atom:link href="http://www.gleisarbeiter.de/category/ferret/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gleisarbeiter.de</link>
	<description></description>
	<lastBuildDate>Wed, 16 Dec 2009 08:52:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Stemming mit ActsAsFerret</title>
		<link>http://www.gleisarbeiter.de/2008/01/17/stemming-mit-actsasferret/</link>
		<comments>http://www.gleisarbeiter.de/2008/01/17/stemming-mit-actsasferret/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 14:53:49 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Ferret]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[ActsAsFerret]]></category>
		<category><![CDATA[acts_as_ferret]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Stemming]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=14</guid>
		<description><![CDATA[Stemming ist ein Verfahren, um &#8211; mit Hilfe von Algorithmen &#8211; den Wortstamm von Wörtern zu ermitteln. Dies wird z.B. bei Suchmaschinen angewendet, damit die Suche nicht an einem eingebenen Wort scheitert, dass zwar nicht in der Datenbank als solches zu finden ist, wohl aber dessen Wortstamm, z.B. Gitarren =&#62; Gitarre.Ferret und ActsAsFerret bietet eine [...]]]></description>
			<content:encoded><![CDATA[<p>Stemming ist ein Verfahren, um &#8211; mit Hilfe von Algorithmen &#8211; den Wortstamm von Wörtern zu ermitteln. Dies wird z.B. bei Suchmaschinen angewendet, damit die Suche nicht an einem eingebenen Wort scheitert, dass zwar nicht in der Datenbank als solches zu finden ist, wohl aber dessen Wortstamm, z.B. Gitarren =&gt; Gitarre.Ferret und ActsAsFerret bietet eine einfach zu konfigurierende Unterstützung für dieses Stemming:Eine Datei</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">stemming_analyzer.<span style="color:#9900CC;">rb</span></pre></div></div>

<p>im lib/-Verzeichnis anlegen:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'ferret'</span>
<span style="color:#9966CC; font-weight:bold;">class</span> StemmingAnalyzer <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Ferret::Analysis::Analyzer</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Ferret::Analysis</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>stop_words = FULL_GERMAN_STOP_WORDS<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@stop_words</span> = stop_words
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">def</span> token_stream<span style="color:#006600; font-weight:bold;">&#40;</span>field, str<span style="color:#006600; font-weight:bold;">&#41;</span>
  StemFilter.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>StopFilter.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>LowerCaseFilter.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>StandardTokenizer.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,@stop_words<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'de'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Im zu durchsuchenden Model dann folgendes:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">acts_as_ferret <span style="color:#ff3333; font-weight:bold;">:fields</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt;
  <span style="color:#006600; font-weight:bold;">&#123;</span>  <span style="color:#ff3333; font-weight:bold;">:bandname</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:firstName_if_public</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>,  <span style="color:#ff3333; font-weight:bold;">:tag_list</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:comment_list</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span>,
  <span style="color:#ff3333; font-weight:bold;">:ferret</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#123;</span>    <span style="color:#ff3333; font-weight:bold;">:analyzer</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; StemmingAnalyzer.<span style="color:#9900CC;">new</span>, <span style="color:#ff3333; font-weight:bold;">:remote</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p><strike>Dabei ist darauf zu achten, dass, wenn ihr den DrB-Server verwenden wollt, :remote =&gt; true innerhalb des :ferret-Attributs sein muss. Bei uns war dieses ausserhalb, woraufhin bei einem Aufruf von XYZ.rebuild_index nur nil zurückgeliefert wurde und Stemming nicht funktionierte.</strike> <strong>Siehe unten unter UPDATE</strong>. Über script/console kann dann schön getestet werden. Wenn man nebenbei noch die log/ferret_server.log anschaut, kann man sehen, dass jetzt automatisch Suchwörter wie &#8220;und&#8221; in XYZ.find_by_contents(&#8221;Gitarren und Geigen&#8221;) entfernt werden. Ausserdem kann man sehen, dass z.B. &#8220;Geigen&#8221; auf &#8220;Geig&#8221; reduziert wird, womit sich dann auch Wörter wir Geige finden lassen.</p>
<p><b>UPDATE</b></p>
<p>Nach einigen Problemen mit Ferret in unserem Projekt ist klar geworden, dass der Drb-Server mit meiner Konfiguration nicht verwendet wurde. Interessanterweise nur auf unserem Development-Server. Hier eine acts_as_ferret Konfig die funktioniert:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">acts_as_ferret <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:fields <span style="color:#006600; font-weight:bold;">=&gt;</span>
      <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:bandname</span>, <span style="color:#ff3333; font-weight:bold;">:shortname</span>, <span style="color:#ff3333; font-weight:bold;">:tag_list</span>, <span style="color:#ff3333; font-weight:bold;">:comment_list</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
       <span style="color:#ff3333; font-weight:bold;">:remote</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:analyzer <span style="color:#006600; font-weight:bold;">=&gt;</span> StemmingAnalyzer.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2008/01/17/stemming-mit-actsasferret/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
