<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
>

<channel>
	<title>Solution Hacker &#187; lucene</title>
	<atom:link href="http://www.solutionhacker.com/tag/lucene/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.solutionhacker.com</link>
	<description>This blog provides solutions for enterpreneurs!</description>
	<lastBuildDate>Mon, 06 Feb 2012 07:19:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=339</generator>
<!-- podcast_generator="Blubrry PowerPress/2.0.4" -->
	<itunes:summary>This blog provides solutions for enterpreneurs!</itunes:summary>
	<itunes:author>Solution Hacker</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.solutionhacker.com/wp-content/plugins/powerpress/itunes_default.jpg" />
	<itunes:subtitle>This blog provides solutions for enterpreneurs!</itunes:subtitle>
	<image>
		<title>Solution Hacker &#187; lucene</title>
		<url>http://www.solutionhacker.com/wp-content/plugins/powerpress/rss_default.jpg</url>
		<link>http://www.solutionhacker.com</link>
	</image>
		<item>
		<title>Powerful Full Text Search &#8211; Part 3 Solr</title>
		<link>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-part-3-solr/</link>
		<comments>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-part-3-solr/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 06:45:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scale]]></category>
		<category><![CDATA[Site Building]]></category>
		<category><![CDATA[indexing]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=165</guid>
		<description><![CDATA[<h2>Introduction of Solr</h2>
<p><strong>Solr </strong>is a standalone enterprise search server with a web-services like API. You put documents in it (called &#34;indexing&#34;) via XML over HTTP (RESTful). You query it via HTTP GET and receive XML results.</p>
<ul>
    <li>Advanced Full-Text Search Capabilities</li>
    <li><strong> Optimized</strong> for High Volume Web Traffic</li>
    <li>Standards Based Open Interfaces - XML and HTTP</li>
    <li>Comprehensive HTML <strong>Administration Interfaces</strong></li>
    <li>Scalability - Efficient <strong>Replication </strong>to other Solr Search Servers</li>
    <li>Flexible and Adaptable with XML configuration</li>
    <li>Extensible Plugin Architecture</li>
</ul>
<p><!--more--></p>
<h2><!--more-->Set up Solr</h2>
<p>&#160;To set up Solr, you should follow this <a href="http://lucene.apache.org/solr/tutorial.html">guideline.</a> After the set up Solr, you practically have a indexing service up.</p>
<p>The HTTP/XML interface of the indexer has two main access points: the <em>update URL</em>, which maintains the index,  and the <em>select URL</em>, which is used for queries. In the default configuration, they are found at:</p>
<ul>
    <li><code>http://[hostname:port]/solr/update</code></li>
    <li><code>http://</code><code>[hostname:port]</code><code>/solr/select</code></li>
</ul>
<p>To add a document to the index, we POST an XML representation of the fields to index to the update URL. In addition, you can delete, update (ie. re-post on unique). All change operations need to commit to flush to file system. On the other hand,&#160; once we have indexed some data, an HTTP GET on the <em>select URL</em> does the querying.&#160;<em><br />
</em></p>
<h2>Powerful features Behind Solr</h2>
<p>If you follow the guideline above, you already get yourself familiar with <strong>indexing</strong>, <strong>searching </strong>and facet browsing. Now lets get down to how to make Solr a <strong>scalable </strong>solution with great <strong>performance</strong>.</p>
<p><u><strong>Caching<br />
</strong></u></p>
<p>TBA</p>
<p><u><strong>Distribution and Replication</strong></u></p>
<p>For applications that receive large volumes of queries, a single Solr server may not be enough to meet performance requirements.  Therefore, Solr provides mechanisms for <strong>replicating the Lucene index across multiple servers</strong> that are part of a load-balanced suite of query servers.  The replication process is handled through a combination of event listeners enabled through the solrconfig.xml file and several shell scripts (located in solr/bin of the example application).</p>
<p>In a replicating architecture, one Solr server acts as the <strong>master </strong>server, providing copies of the index (called <code>snapshots</code>) to one or more <strong>slave </strong>servers that handle query requests.  Indexing commands are sent to the master server and queries are sent to the slave servers. The master server can create snapshots manually or by configuring the <code>&#60;updateHandler&#62;</code> section of solrconfig.xml to trigger snapshot creation when <code>commit</code> and/or <code>optimize</code> events are received.  In either the manual or the event-driven process, the <code>snapshooter</code> script is invoked on the master server, creating a directory on the server named <code>snapshot.yyyymmddHHMMSS</code> where <code>yyyymmddHHMMSS</code> is the actual time the snapshot was created. The slave servers then use <strong><i>rsync</i> </strong>to copy only those files in the Lucene index that have been changed.</p>
<pre class="xml" name="code">
&#60;listener event=&#34;postCommit&#34; class=&#34;solr.RunExecutableListener&#34;&#62;
    &#60;str name=&#34;exe&#34;&#62;snapshooter&#60;/str&#62;
    &#60;str name=&#34;dir&#34;&#62;solr/bin&#60;/str&#62;
    &#60;bool name=&#34;wait&#34;&#62;true&#60;/bool&#62;
    &#60;arr name=&#34;args&#34;&#62; &#60;str&#62;arg1&#60;/str&#62; &#60;str&#62;arg2&#60;/str&#62; &#60;/arr&#62;
    &#60;arr name=&#34;env&#34;&#62; &#60;str&#62;MYVAR=val1&#60;/str&#62; &#60;/arr&#62;
&#60;/listener&#62;</pre>
<h2>Reference</h2>
<p>Below are some cool references I found:</p>
<ol>
    <li><span style="color: rgb(153, 153, 153);"><a href="http://www.ibm.com/developerworks/java/library/j-solr1/">Search smarter with Apache Solr, Part 1:</a> </span>Essential features and the Solr schema</li>
    <li><span style="color: rgb(153, 153, 153);"><a href="http://www.ibm.com/developerworks/java/library/j-solr2/">Search smarter with Apache Solr, Part 2:</a> </span>Solr for the enterprise</li>
    <li><a href="http://www.cnlp.org/presentations/slides/AdvancedLuceneEU.pdf">Advanced Lucene</a></li>
</ol>
<p>&#160;</p>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Introduction of Solr</h2>
<p><strong>Solr </strong>is a standalone enterprise search server with a web-services like API. You put documents in it (called &quot;indexing&quot;) via XML over HTTP (RESTful). You query it via HTTP GET and receive XML results.</p>
<ul>
<li>Advanced Full-Text Search Capabilities</li>
<li><strong> Optimized</strong> for High Volume Web Traffic</li>
<li>Standards Based Open Interfaces &#8211; XML and HTTP</li>
<li>Comprehensive HTML <strong>Administration Interfaces</strong></li>
<li>Scalability &#8211; Efficient <strong>Replication </strong>to other Solr Search Servers</li>
<li>Flexible and Adaptable with XML configuration</li>
<li>Extensible Plugin Architecture</li>
</ul>
<p><span id="more-165"></span></p>
<h2><!--more-->Set up Solr</h2>
<p>&nbsp;To set up Solr, you should follow this <a href="http://lucene.apache.org/solr/tutorial.html">guideline.</a> After the set up Solr, you practically have a indexing service up.</p>
<p>The HTTP/XML interface of the indexer has two main access points: the <em>update URL</em>, which maintains the index,  and the <em>select URL</em>, which is used for queries. In the default configuration, they are found at:</p>
<ul>
<li>[code]]czozNDpcImh0dHA6Ly9baG9zdG5hbWU6cG9ydF0vc29sci91cGRhdGVcIjt7WyYqJl19[[/code]</li>
<li>[code]]czo3OlwiaHR0cDovL1wiO3tbJiomXX0=[[/code][code]]czoxNTpcIltob3N0bmFtZTpwb3J0XVwiO3tbJiomXX0=[[/code][code]]czoxMjpcIi9zb2xyL3NlbGVjdFwiO3tbJiomXX0=[[/code]</li>
</ul>
<p>To add a document to the index, we POST an XML representation of the fields to index to the update URL. In addition, you can delete, update (ie. re-post on unique). All change operations need to commit to flush to file system. On the other hand,&nbsp; once we have indexed some data, an HTTP GET on the <em>select URL</em> does the querying.&nbsp;<em><br />
</em></p>
<h2>Powerful features Behind Solr</h2>
<p>If you follow the guideline above, you already get yourself familiar with <strong>indexing</strong>, <strong>searching </strong>and facet browsing. Now lets get down to how to make Solr a <strong>scalable </strong>solution with great <strong>performance</strong>.</p>
<p><u><strong>Caching<br />
</strong></u></p>
<p>TBA</p>
<p><u><strong>Distribution and Replication</strong></u></p>
<p>For applications that receive large volumes of queries, a single Solr server may not be enough to meet performance requirements.  Therefore, Solr provides mechanisms for <strong>replicating the Lucene index across multiple servers</strong> that are part of a load-balanced suite of query servers.  The replication process is handled through a combination of event listeners enabled through the solrconfig.xml file and several shell scripts (located in solr/bin of the example application).</p>
<p>In a replicating architecture, one Solr server acts as the <strong>master </strong>server, providing copies of the index (called [code]]czo5Olwic25hcHNob3RzXCI7e1smKiZdfQ==[[/code]) to one or more <strong>slave </strong>servers that handle query requests.  Indexing commands are sent to the master server and queries are sent to the slave servers. The master server can create snapshots manually or by configuring the [code]]czoyMTpcIiZsdDt1cGRhdGVIYW5kbGVyJmd0O1wiO3tbJiomXX0=[[/code] section of solrconfig.xml to trigger snapshot creation when [code]]czo2OlwiY29tbWl0XCI7e1smKiZdfQ==[[/code] and/or [code]]czo4Olwib3B0aW1pemVcIjt7WyYqJl19[[/code] events are received.  In either the manual or the event-driven process, the [code]]czoxMTpcInNuYXBzaG9vdGVyXCI7e1smKiZdfQ==[[/code] script is invoked on the master server, creating a directory on the server named [code]]czoyMzpcInNuYXBzaG90Lnl5eXltbWRkSEhNTVNTXCI7e1smKiZdfQ==[[/code] where [code]]czoxNDpcInl5eXltbWRkSEhNTVNTXCI7e1smKiZdfQ==[[/code] is the actual time the snapshot was created. The slave servers then use <strong><i>rsync</i> </strong>to copy only those files in the Lucene index that have been changed.</p>
<p><pre><pre class="xml" name="code">
&amp;lt;listener event=&amp;quot;postCommit&amp;quot; class=&amp;quot;solr.RunExecutableListener&amp;quot;&amp;gt;
&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;str name=&amp;quot;exe&amp;quot;&amp;gt;snapshooter&amp;lt;/str&amp;gt;
&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;str name=&amp;quot;dir&amp;quot;&amp;gt;solr/bin&amp;lt;/str&amp;gt;
&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;bool name=&amp;quot;wait&amp;quot;&amp;gt;true&amp;lt;/bool&amp;gt;
&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;arr name=&amp;quot;args&amp;quot;&amp;gt; &amp;lt;str&amp;gt;arg1&amp;lt;/str&amp;gt; &amp;lt;str&amp;gt;arg2&amp;lt;/str&amp;gt; &amp;lt;/arr&amp;gt;
&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;arr name=&amp;quot;env&amp;quot;&amp;gt; &amp;lt;str&amp;gt;MYVAR=val1&amp;lt;/str&amp;gt; &amp;lt;/arr&amp;gt;
&amp;lt;/listener&amp;gt;</pre></pre></p>
<h2>Reference</h2>
<p>Below are some cool references I found:</p>
<ol>
<li><span style="color: rgb(153, 153, 153);"><a href="http://www.ibm.com/developerworks/java/library/j-solr1/">Search smarter with Apache Solr, Part 1:</a> </span>Essential features and the Solr schema</li>
<li><span style="color: rgb(153, 153, 153);"><a href="http://www.ibm.com/developerworks/java/library/j-solr2/">Search smarter with Apache Solr, Part 2:</a> </span>Solr for the enterprise</li>
<li><a href="http://www.cnlp.org/presentations/slides/AdvancedLuceneEU.pdf">Advanced Lucene</a></li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-part-3-solr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powerful Full Text Search &#8211; Part 2 Nutch</title>
		<link>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-part-2-nutch/</link>
		<comments>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-part-2-nutch/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 11:22:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Site Building]]></category>
		<category><![CDATA[crawler]]></category>
		<category><![CDATA[hadoop]]></category>
		<category><![CDATA[HDFS]]></category>
		<category><![CDATA[indexing service]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[nutch]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=164</guid>
		<description><![CDATA[<h2>Introduction of Nutch &#38; Hadoop</h2>
<p>After Lucene, the author created another powerful tool. Its name is <strong>Nutch</strong>. Nutch is a powerful crawler built on top of the Lucene. With Nutch, you can launch a multi-threaded crawler to obtain information from the Net. At this point of writing, Nutch is in its 0.9 version. Nutch comes with a list of cool features, including <strong>whole Web crawling</strong>, <strong>local file crawling </strong>for the<br />
intranet, <strong>indexing</strong> all the while.</p>
<p><strong>Hadoop </strong>was designed to handle the petabytes of data that Nutch could potentially store and process. In fact, Hadoop has its own file system: the <strong>Hadoop Distributed File System</strong> (HDFS), which can run on any old run-of-the-mill, low-cost hardware.<br />
Hadoop works by storing part of the file system's data across all the servers in the cluster. As new queries come in, HDFS follows the &#34;moving computation is cheaper than moving data&#34; rule &#8212; meaning that moving the processing of the query to as<br />
close as possible to the data will be faster than placing the query at random within the cluster and moving data long distances across the network.</p>
<p>I have searched around to see if anyone can give me some tips on this tool. Surprisingly, I don't see much. But don't worry, I have found some that can at least get you start playing with it.</p>
<p><!--more--></p>
<p><!--{12153432153430}--></p>
<h2>Set up Nutch</h2>
<p>Here is the <a href="http://peterpuwang.googlepages.com/NutchGuideForDummies.htm">guideline written by Peter Wang</a> that I followed to bring my Nutch up. Follow it and bring your Nutch before go further. By the way, if you want to run Nutch with Solr, this is a good <a href="http://wiki.apache.org/nutch/RunningNutchAndSolr">tutorial</a>.</p>
<h2>Nutch Architectural Review</h2>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Introduction of Nutch &amp; Hadoop</h2>
<p>After Lucene, the author created another powerful tool. Its name is <strong>Nutch</strong>. Nutch is a powerful crawler built on top of the Lucene. With Nutch, you can launch a multi-threaded crawler to obtain information from the Net. At this point of writing, Nutch is in its 0.9 version. Nutch comes with a list of cool features, including <strong>whole Web crawling</strong>, <strong>local file crawling </strong>for the<br />
intranet, <strong>indexing</strong> all the while.</p>
<p><strong>Hadoop </strong>was designed to handle the petabytes of data that Nutch could potentially store and process. In fact, Hadoop has its own file system: the <strong>Hadoop Distributed File System</strong> (HDFS), which can run on any old run-of-the-mill, low-cost hardware.<br />
Hadoop works by storing part of the file system&#8217;s data across all the servers in the cluster. As new queries come in, HDFS follows the &quot;moving computation is cheaper than moving data&quot; rule &mdash; meaning that moving the processing of the query to as<br />
close as possible to the data will be faster than placing the query at random within the cluster and moving data long distances across the network.</p>
<p>I have searched around to see if anyone can give me some tips on this tool. Surprisingly, I don&#8217;t see much. But don&#8217;t worry, I have found some that can at least get you start playing with it.</p>
<p><span id="more-164"></span></p>
<p><!--{12153432153430}--></p>
<h2>Set up Nutch</h2>
<p>Here is the <a href="http://peterpuwang.googlepages.com/NutchGuideForDummies.htm">guideline written by Peter Wang</a> that I followed to bring my Nutch up. Follow it and bring your Nutch before go further. By the way, if you want to run Nutch with Solr, this is a good <a href="http://wiki.apache.org/nutch/RunningNutchAndSolr">tutorial</a>.</p>
<h2>Nutch Architectural Review</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-part-2-nutch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powerful Full Text Search Engine &#8211; Part 1 Lucene Introduction</title>
		<link>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-engine-lucene-part-1/</link>
		<comments>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-engine-lucene-part-1/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 08:38:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Site Building]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[digester]]></category>
		<category><![CDATA[full-text search]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=160</guid>
		<description><![CDATA[<h2>Introduction of Lucene</h2>
<p>I have heard of Lucene and its powerful full text search capability many times. Today, I decide to take a look at it. Before I dive into the user guide, I went to Google Tech Talk to find a video related to Lucene first. Here is what I found:&#160;</p>
<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=3675183678687996842&#38;hl=en&#38;fs=true" allowfullscreen="true" style="width: 400px; height: 326px;" id="VideoPlayback"></embed>
<p>After I finished this video, I found Lucene a really great tool for me. So, I decided to have a deeper look at it. After a quick search,&#160; I found a great <a href="http://immike.net/blog/2007/07/03/full-text-search-with-apache-lucene/">blog </a>that showed me how to use Lucene with Digg. With Solr on top of Lucene, you can make Lucene available as RESTful Web Service. It is so awesome, isn't it? In this article, I will list you all the information I found during my little research on Lucene and I hope you will feel it useful.</p>
<p><!--more--></p>
<h3><!--more-->Architecture Overview</h3>
<p>Before we dig into the code or set up guidelines, I would like to have a high level picture of Lucene first. I borrow a diagram from this article that helps me to grasp the key components in search.</p>
<p><img src="http://www.solutionhacker.com/wp-content/uploads/lucene1.gif" alt="" /></p>
<p>This high level picture shows you that your <strong>search keywords</strong> you entered (normally using a form) will become a HTTP <strong>search request </strong>and later been translated into a form that search engine understands by <strong>Query parser. </strong>Search engine will perform the search operation against the indexed files that was previously prepared by <strong>Indexer</strong>. After that, the result will be <strong>ranked based on predefined ranking algorithm </strong>and returned to the user. The <strong>source </strong>of the data can be from Web Service, database or documents in your file system. In this diagram, it shows you that you can launch <strong>spider </strong>or <strong>crawler </strong>like Google to obtain the data from web pages on the Internet and feed it to Indexer as your source.</p>
<h2>Get one step deeper</h2>
<p style="text-align: left;"><strong>Now you know the high level flow of how search works. Lets get one step into the detail.</strong></p>
<ol>
    <li>What search interface to use?</li>
    <li>How search interface communicates with your search engine?</li>
    <li>What kind of search the search engine provides?</li>
    <li>How search engine indexes the documents?</li>
    <li>How result be ranked and what kind of ranking algorithms we normally use?</li>
</ol>
<p><strong>Below is the answers of the questions above:</strong></p>
<ol>
    <li>Up to you. I would use Flex as I want to provide a rich search interface to my users.</li>
    <li>Flex can talk HTTP, Web Service or RemoteObject AMF. If you put web service layer on Lucene (ie. Solr), you can use REST call (ie. HTTP) to obtain the result.</li>
    <li>Lucene supports several kinds of advanced searches like: <br />
    <ul>
        <li><u>Boolean operators</u> - users can compose query using AND, OR, NOT</li>
        <li><u>Field Search</u> - what fields the search operates on? like title, author or content?</li>
        <li><u>Wildcard Search </u>- supports * and ?.</li>
        <li><u>Fuzzy Search </u>- Lucene provides a fuzzy search that's based on an edit distance algorithm. You can use the tilde character (~) at the end of a single search word to do a fuzzy search. For example, the query &#34;think~&#34; searches for the terms <strong>similar </strong>in spelling to the term &#34;think.&#34; The key here is the word &#34;similar&#34;. Do we consider horse and donkey are related? Or you have hose and horse be related somehow in spelling?</li>
        <li><u>Range Search </u>- age, date and etc</li>
    </ul>
    </li>
    <li>Large topic. I will go back to it later.</li>
    <li>Up to you. If you want to look at the popular ranking algorithm in the world, check out <strong>Google Page Rank. </strong>It is one of the algorithms that many of us interested to know. Before I want to have my <a href="http://www.justproposed.com">wedding website - Justproposed.com </a>be shown on at the top of the result when users type &#34;wedding website&#34; as search keywords, I have looked into <strong>SEO</strong>. It is a fun area to explore. Generally speaking, if the query keywords shown in the title, it weights more, If the keyword frequency is higher, it ranks higher..blah blah. However, I know Google has weighted a lot on the links. It is not just purely based on the document that you have. How to obtain the additional information during the crawling is beyond the scope of this article.</li>
</ol>
<h2>Get your hand dirty</h2>
<p>Look into this great <a href="http://www-128.ibm.com/developerworks/java/library/wa-lucene2/index.html?ca=drs-">article</a>.</p>
<p><em>The thing this article doesn't mention is that you need to create you <strong>dataDir </strong>and <strong>indexDir </strong>folders under C and drag a list of html files into the dataDir before you start the web server. If you drag new htmls into it, you need to clean up your indexDir and restart your web server in order to rebuild the indexes.</em></p>
<p>I have got the application up and running. It is nice trial. My next step is to enhance this example. I will do the following:</p>
<ol>
    <li>Use Flex as search interface</li>
    <li>Use Solr to expose the Lucene search engine as Web Service.</li>
    <li>Have Flex calls my search engine via REST.</li>
    <li>Display the result on Flex.</li>
</ol>
<p>After I have my new enhancements working, I would do the following:</p>
<ol>
    <li>Look into how Lucene do the indexing</li>
    <li>Look into Nutch,. So I can have it crawled some sites and put the htmls in dataDir for me automatically.</li>
</ol>
<h2>How Lucene Indexes the documents?</h2>
<p>Yes. I haven't forgot to answer the question 4. Here is the <a href="http://www.ibm.com/developerworks/library/wa-lucene/">article </a>that answers your question. To summarize, here are several key points I extracted from this article.</p>
<ol>
    <li><u>Content Extraction</u> - Lucene only takes <strong>text </strong>for index. So, it provides different types of parsers to extract content from different types of document like word, html, doc, pdf and etc. If you have other type of document that you cannot find a parser, you take the responsibility to extract the content out for Lucene. This <a href="http://www.ibm.com/developerworks/web/library/j-lucene/">article </a>shows you how to use <strong>Digester </strong>to extract content out from XML and feed Lucene. If you have a large pool of XML for content extraction, you need to pay attention on the parsing time. There is someone who has done <a href="http://grep.codeconsult.ch/2005/02/16/lucene-rocks/">this </a>and obtain some performance number as reference. However, the article was a bit outdated.</li>
    <li><u>Content Preprocessing</u><strong> - Analyzer </strong>is used to extract the <strong>token </strong>from your text content to be indexed.  Before text is indexed, it is passed through an <code>Analyzer</code>. <code>Analyzer</code>s are in charge of extracting indexable tokens out of text to be indexed, and eliminating the rest.  Lucene comes with a few different <code>Analyzer</code> implementations.  Some of them deal with skipping stop words (frequently-used words that don't help distinguish one document from the other, such as &#34;a,&#34; &#34;an,&#34; &#34;the,&#34; &#34;in,&#34; &#34;on,&#34; etc.), some deal with converting all tokens to lowercase letters, so that searches are not case-sensitive, and so on.</li>
    <li><u>Indexing</u><strong> - IndexWriter </strong>is the key component in the indexing process. This class will use Analyzer that you passed in as parameter to create a new index or open an existing index and add documents to it. You need to set up <strong>fields </strong>and <strong>documents </strong>and feed them to the IndexWriter to do the job. Like the code below, you fetches a list of .txt files and its metadata like path from a directory and feed them for IndexWriter. IndexWriter will index them one after one.</li>
    <li><u>Configuration </u>- You can <strong>configure </strong>IndexWriter to achieve better performance via increasing the buffer size because the bottleneck normally happen during the IO of the index files.</li>
    <li>Lucene uses <strong>inverted index </strong>concept. An inverted index is an inside-out arrangement of documents in which terms take center stage. Each term points to a list of documents that contain it. On the contrary, in a <i>forwarding index</i>, documents take the center stage, and each document refers to a list of terms it contains. You can use an inverted index to easily find which documents contain certain terms. Lucene uses an inverted index as its index structure.</li>
</ol>
<pre name="code" class="java">
 
for(int i = 0; i &#60; textFiles.length; i++){
      if(textFiles[i].isFile() &#62;&#62; textFiles[i].getName().endsWith(&#34;.txt&#34;)){
        Reader textReader = new FileReader(textFiles[i]);
        Document document = new Document();
        document.add(Field.Text(&#34;content&#34;,textReader));
        document.add(Field.Keyword(&#34;path&#34;,textFiles[i].getPath()));
        indexWriter.addDocument(document);
      }
}
</pre>
<p>Lucene offers four different types of fields from which a developer can choose: Keyword,UnIndexed,UnStored,and Text.</p>
<blockquote>
<p><strong>Keyword </strong>fields are not tokenized, but are indexed and stored in the index verbatim.  This field is suitable for fields whose original value should be preserved in its entirety, such as URLs, dates, personal names, Social Security numbers, telephone numbers, etc.</p>
<p><strong>UnIndexed </strong>fields are neither tokenized nor indexed, but their value is stored in the index word for word.  This field is suitable for fields that you need to display with search results, but whose values you will never search directly.  Because this type of field is not indexed, searches against it are slow. Since the original value of a field of this type is stored in the index, this type is not suitable for storing fields with very large values, if index size is an issue.</p>
<p><strong>UnStored </strong>fields are the opposite of UnIndexed fields. Fields of this type are tokenized and indexed, but are not stored in the index. This field is suitable for indexing large amounts of text that does not need to be retrieved in its original form, such as the bodies of Web pages, or any other type of text document.</p>
<p><strong>Text </strong>fields are tokenized, indexed, and stored in the index. This implies that fields of this type can be searched, but be cautious about the size of the field stored as Text field.</p>
</blockquote>
<h2>Conclusion</h2>
<p>To use Lucene, there are 3 main concepts you need to grasp. There are:</p>
<ol>
    <li>Indexer - create search engine indexes</li>
    <li>Analyzer - Split text into tokens that make sense for the search engine. The structure is like document -&#62; a sequence of fields and each field is name/value pair -&#62; tokens. <span style="font-weight: bold;">Field </span>values may be <span style="font-style: italic;">stored</span>, <span style="font-style: italic;">indexed </span>or <span style="font-style: italic;">analyzed/ tokenize, </span>(and, now, <span style="font-style: italic;">vectored</span>). The <a href="http://lucene.sourceforge.net/talks/pisa/">lecture note</a> from Doug Cutting will give you more detail. <strong><span style="font-weight: bold;"><br />
    </span></strong></li>
    <li>Searcher</li>
</ol>
<p>You may think of using <strong>grep </strong>to achieve or <strong>database </strong>to achieve what Lucene does. <strong>Grep </strong>is powerful Linux tool, however, if you want it to search on files with several MB in size, you will see that the tool is inefficient. The reason is grep doesn't prepare the indexes of your files ahead of the time you do the search. Database can do indexing but not so sophisticated as Lucene in your varchar field. Oracle may provide one but I am not familiar with it. One key thing to remember: Lucene is open source, free and does the job extremely well. Why bother to dig into Oracle costly solution?</p>
<p>Lucene has given us a rich search engine capability on our web application. It has many features that I haven't got a chance to discuss them all in this article. I will continue to write more articles on this topic as my research moves forward. Have a nice day! <img onclick="grin(':lol:');" alt=":lol:" src="../../../../../wp-includes/images/smilies/icon_lol.gif" /></p>
<h2>Reference</h2>
<p>The <a href="http://blog.lucene.com/">blog </a>of the Lucene and Solr creator - Doug Cutting</p>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Introduction of Lucene</h2>
<p>I have heard of Lucene and its powerful full text search capability many times. Today, I decide to take a look at it. Before I dive into the user guide, I went to Google Tech Talk to find a video related to Lucene first. Here is what I found:&nbsp;</p>
<p><embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=3675183678687996842&amp;hl=en&amp;fs=true" allowfullscreen="true" style="width: 400px; height: 326px;" id="VideoPlayback"></embed></p>
<p>After I finished this video, I found Lucene a really great tool for me. So, I decided to have a deeper look at it. After a quick search,&nbsp; I found a great <a href="http://immike.net/blog/2007/07/03/full-text-search-with-apache-lucene/">blog </a>that showed me how to use Lucene with Digg. With Solr on top of Lucene, you can make Lucene available as RESTful Web Service. It is so awesome, isn&#8217;t it? In this article, I will list you all the information I found during my little research on Lucene and I hope you will feel it useful.</p>
<p><span id="more-160"></span></p>
<h3><!--more-->Architecture Overview</h3>
<p>Before we dig into the code or set up guidelines, I would like to have a high level picture of Lucene first. I borrow a diagram from this article that helps me to grasp the key components in search.</p>
<p><img src="http://www.solutionhacker.com/wp-content/uploads/lucene1.gif" alt="" /></p>
<p>This high level picture shows you that your <strong>search keywords</strong> you entered (normally using a form) will become a HTTP <strong>search request </strong>and later been translated into a form that search engine understands by <strong>Query parser. </strong>Search engine will perform the search operation against the indexed files that was previously prepared by <strong>Indexer</strong>. After that, the result will be <strong>ranked based on predefined ranking algorithm </strong>and returned to the user. The <strong>source </strong>of the data can be from Web Service, database or documents in your file system. In this diagram, it shows you that you can launch <strong>spider </strong>or <strong>crawler </strong>like Google to obtain the data from web pages on the Internet and feed it to Indexer as your source.</p>
<h2>Get one step deeper</h2>
<p style="text-align: left;"><strong>Now you know the high level flow of how search works. Lets get one step into the detail.</strong></p>
<ol>
<li>What search interface to use?</li>
<li>How search interface communicates with your search engine?</li>
<li>What kind of search the search engine provides?</li>
<li>How search engine indexes the documents?</li>
<li>How result be ranked and what kind of ranking algorithms we normally use?</li>
</ol>
<p><strong>Below is the answers of the questions above:</strong></p>
<ol>
<li>Up to you. I would use Flex as I want to provide a rich search interface to my users.</li>
<li>Flex can talk HTTP, Web Service or RemoteObject AMF. If you put web service layer on Lucene (ie. Solr), you can use REST call (ie. HTTP) to obtain the result.</li>
<li>Lucene supports several kinds of advanced searches like: 
<ul>
<li><u>Boolean operators</u> &#8211; users can compose query using AND, OR, NOT</li>
<li><u>Field Search</u> &#8211; what fields the search operates on? like title, author or content?</li>
<li><u>Wildcard Search </u>- supports * and ?.</li>
<li><u>Fuzzy Search </u>- Lucene provides a fuzzy search that&#8217;s based on an edit distance algorithm. You can use the tilde character (~) at the end of a single search word to do a fuzzy search. For example, the query &quot;think~&quot; searches for the terms <strong>similar </strong>in spelling to the term &quot;think.&quot; The key here is the word &quot;similar&quot;. Do we consider horse and donkey are related? Or you have hose and horse be related somehow in spelling?</li>
<li><u>Range Search </u>- age, date and etc</li>
</ul>
</li>
<li>Large topic. I will go back to it later.</li>
<li>Up to you. If you want to look at the popular ranking algorithm in the world, check out <strong>Google Page Rank. </strong>It is one of the algorithms that many of us interested to know. Before I want to have my <a href="http://www.justproposed.com">wedding website &#8211; Justproposed.com </a>be shown on at the top of the result when users type &quot;wedding website&quot; as search keywords, I have looked into <strong>SEO</strong>. It is a fun area to explore. Generally speaking, if the query keywords shown in the title, it weights more, If the keyword frequency is higher, it ranks higher..blah blah. However, I know Google has weighted a lot on the links. It is not just purely based on the document that you have. How to obtain the additional information during the crawling is beyond the scope of this article.</li>
</ol>
<h2>Get your hand dirty</h2>
<p>Look into this great <a href="http://www-128.ibm.com/developerworks/java/library/wa-lucene2/index.html?ca=drs-">article</a>.</p>
<p><em>The thing this article doesn&#8217;t mention is that you need to create you <strong>dataDir </strong>and <strong>indexDir </strong>folders under C and drag a list of html files into the dataDir before you start the web server. If you drag new htmls into it, you need to clean up your indexDir and restart your web server in order to rebuild the indexes.</em></p>
<p>I have got the application up and running. It is nice trial. My next step is to enhance this example. I will do the following:</p>
<ol>
<li>Use Flex as search interface</li>
<li>Use Solr to expose the Lucene search engine as Web Service.</li>
<li>Have Flex calls my search engine via REST.</li>
<li>Display the result on Flex.</li>
</ol>
<p>After I have my new enhancements working, I would do the following:</p>
<ol>
<li>Look into how Lucene do the indexing</li>
<li>Look into Nutch,. So I can have it crawled some sites and put the htmls in dataDir for me automatically.</li>
</ol>
<h2>How Lucene Indexes the documents?</h2>
<p>Yes. I haven&#8217;t forgot to answer the question 4. Here is the <a href="http://www.ibm.com/developerworks/library/wa-lucene/">article </a>that answers your question. To summarize, here are several key points I extracted from this article.</p>
<ol>
<li><u>Content Extraction</u> &#8211; Lucene only takes <strong>text </strong>for index. So, it provides different types of parsers to extract content from different types of document like word, html, doc, pdf and etc. If you have other type of document that you cannot find a parser, you take the responsibility to extract the content out for Lucene. This <a href="http://www.ibm.com/developerworks/web/library/j-lucene/">article </a>shows you how to use <strong>Digester </strong>to extract content out from XML and feed Lucene. If you have a large pool of XML for content extraction, you need to pay attention on the parsing time. There is someone who has done <a href="http://grep.codeconsult.ch/2005/02/16/lucene-rocks/">this </a>and obtain some performance number as reference. However, the article was a bit outdated.</li>
<li><u>Content Preprocessing</u><strong> &#8211; Analyzer </strong>is used to extract the <strong>token </strong>from your text content to be indexed.  Before text is indexed, it is passed through an [code]]czo4OlwiQW5hbHl6ZXJcIjt7WyYqJl19[[/code]. [code]]czo4OlwiQW5hbHl6ZXJcIjt7WyYqJl19[[/code]s are in charge of extracting indexable tokens out of text to be indexed, and eliminating the rest.  Lucene comes with a few different [code]]czo4OlwiQW5hbHl6ZXJcIjt7WyYqJl19[[/code] implementations.  Some of them deal with skipping stop words (frequently-used words that don't help distinguish one document from the other, such as &quot;a,&quot; &quot;an,&quot; &quot;the,&quot; &quot;in,&quot; &quot;on,&quot; etc.), some deal with converting all tokens to lowercase letters, so that searches are not case-sensitive, and so on.</li>
<li><u>Indexing</u><strong> - IndexWriter </strong>is the key component in the indexing process. This class will use Analyzer that you passed in as parameter to create a new index or open an existing index and add documents to it. You need to set up <strong>fields </strong>and <strong>documents </strong>and feed them to the IndexWriter to do the job. Like the code below, you fetches a list of .txt files and its metadata like path from a directory and feed them for IndexWriter. IndexWriter will index them one after one.</li>
<li><u>Configuration </u>- You can <strong>configure </strong>IndexWriter to achieve better performance via increasing the buffer size because the bottleneck normally happen during the IO of the index files.</li>
<li>Lucene uses <strong>inverted index </strong>concept. An inverted index is an inside-out arrangement of documents in which terms take center stage. Each term points to a list of documents that contain it. On the contrary, in a <i>forwarding index</i>, documents take the center stage, and each document refers to a list of terms it contains. You can use an inverted index to easily find which documents contain certain terms. Lucene uses an inverted index as its index structure.</li>
</ol>
<p><pre><pre name="code" class="java">
 
for(int i = 0; i &amp;lt; textFiles.length; i++){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(textFiles[i].isFile() &amp;gt;&amp;gt; textFiles[i].getName().endsWith(&amp;quot;.txt&amp;quot;)){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reader textReader = new FileReader(textFiles[i]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Document document = new Document();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.add(Field.Text(&amp;quot;content&amp;quot;,textReader));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.add(Field.Keyword(&amp;quot;path&amp;quot;,textFiles[i].getPath()));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;indexWriter.addDocument(document);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
}
</pre></pre></p>
<p>Lucene offers four different types of fields from which a developer can choose: Keyword,UnIndexed,UnStored,and Text.</p>
<blockquote>
<p><strong>Keyword </strong>fields are not tokenized, but are indexed and stored in the index verbatim.  This field is suitable for fields whose original value should be preserved in its entirety, such as URLs, dates, personal names, Social Security numbers, telephone numbers, etc.</p>
<p><strong>UnIndexed </strong>fields are neither tokenized nor indexed, but their value is stored in the index word for word.  This field is suitable for fields that you need to display with search results, but whose values you will never search directly.  Because this type of field is not indexed, searches against it are slow. Since the original value of a field of this type is stored in the index, this type is not suitable for storing fields with very large values, if index size is an issue.</p>
<p><strong>UnStored </strong>fields are the opposite of UnIndexed fields. Fields of this type are tokenized and indexed, but are not stored in the index. This field is suitable for indexing large amounts of text that does not need to be retrieved in its original form, such as the bodies of Web pages, or any other type of text document.</p>
<p><strong>Text </strong>fields are tokenized, indexed, and stored in the index. This implies that fields of this type can be searched, but be cautious about the size of the field stored as Text field.</p>
</blockquote>
<h2>Conclusion</h2>
<p>To use Lucene, there are 3 main concepts you need to grasp. There are:</p>
<ol>
<li>Indexer - create search engine indexes</li>
<li>Analyzer - Split text into tokens that make sense for the search engine. The structure is like document -&gt; a sequence of fields and each field is name/value pair -&gt; tokens. <span style="font-weight: bold;">Field </span>values may be <span style="font-style: italic;">stored</span>, <span style="font-style: italic;">indexed </span>or <span style="font-style: italic;">analyzed/ tokenize, </span>(and, now, <span style="font-style: italic;">vectored</span>). The <a href="http://lucene.sourceforge.net/talks/pisa/">lecture note</a> from Doug Cutting will give you more detail. <strong><span style="font-weight: bold;"><br />
    </span></strong></li>
<li>Searcher</li>
</ol>
<p>You may think of using <strong>grep </strong>to achieve or <strong>database </strong>to achieve what Lucene does. <strong>Grep </strong>is powerful Linux tool, however, if you want it to search on files with several MB in size, you will see that the tool is inefficient. The reason is grep doesn't prepare the indexes of your files ahead of the time you do the search. Database can do indexing but not so sophisticated as Lucene in your varchar field. Oracle may provide one but I am not familiar with it. One key thing to remember: Lucene is open source, free and does the job extremely well. Why bother to dig into Oracle costly solution?</p>
<p>Lucene has given us a rich search engine capability on our web application. It has many features that I haven't got a chance to discuss them all in this article. I will continue to write more articles on this topic as my research moves forward. Have a nice day! <img onclick="grin(':lol:');" alt=":lol:" src="../../../../../wp-includes/images/smilies/icon_lol.gif" /></p>
<h2>Reference</h2>
<p>The <a href="http://blog.lucene.com/">blog </a>of the Lucene and Solr creator - Doug Cutting</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/implement-your-idea/build-your-website/powerful-full-text-search-engine-lucene-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

