Searching Indexed Data with Solr, Page 2
Indexing and searching data stored across multiple file formats? Try the powerful combination of the Lucene search library and the Solr search application.
Searching Indexed Data with Solr
Newcomers to Lucene are often confused about its role in the search implementation process. Hopefully, running the Lucene demo is going to help dispel the confusion, because the demo is an application created using the Lucene library. Lucene is not a search application; rather, you'll use its API to write your own search application. You can peruse the demo's index and search source code by downloading the Lucene source code and then navigating to
Presuming your search needs aren't so exotic that you have to write a custom index and search implementation, consider using Solr, a Lucene-based search application, which bundles a great number of useful features including a Web-based interface, support for indexing and searching multiple document types, and even database integration.
Unzip the download and via the terminal navigate to the
example directory. Execute the following command:
$ java -jar start.jar
This will start the Jetty application server bundled with Solr, allowing you to access the Solr administration interface via the URL
http://localhost:8983/solr/admin/. After confirming you are able to access this interface, build the Solr search index using the sample XML files included in the Solr download by executing the following command:
$ java -jar exampledocs/post.jar exampledocs/*.xml SimplePostTool: version 1.3 SimplePostTool: POSTing files to http://localhost:8983/solr/update.. SimplePostTool: POSTing file gb18030-example.xml SimplePostTool: POSTing file hd.xml SimplePostTool: POSTing file ipod_other.xml SimplePostTool: POSTing file ipod_video.xml SimplePostTool: POSTing file mem.xml SimplePostTool: POSTing file monitor2.xml SimplePostTool: POSTing file monitor.xml SimplePostTool: POSTing file mp500.xml SimplePostTool: POSTing file sd500.xml SimplePostTool: POSTing file solr.xml SimplePostTool: POSTing file utf8-example.xml SimplePostTool: POSTing file vidcard.xml SimplePostTool: COMMITting Solr index changes..
Now, return to the browser and within the
Query String textarea form field search for a bit of text found in the XML documents. For instance, try searching for
Dell, which is found in the document
post.jar utility demonstrates just one of several approaches to indexing data using Solr. See the Solr wiki for more information about alternative approaches. Further, if you continue experimenting with the
post.jar file, you'll notice that it is restricted to indexing solely XML files. Of course, you'll probably want to index multiple file types. If so, check out the Apache Tika project, which can be used in conjunction with Solr to index more than 30 different content types, including MP3, PST (Outlook files), and PowerPoint!
Where to From Here?
Lucene, Solr, and related projects such as Nutch offer developers an incredibly powerful solution for searching data contained within a wide variety of document types. Of course, the examples provided in this article barely scratch the surface of what's possible. Be sure to consult the following websites for more information:
- The official Lucene project website: a powerful text search engine library
- The official Solr project website: a search implementation built atop the Lucene library
- The official Nutch project website: an open source Web crawler and search engine built atop the Lucene library
About the Author
Jason Gilmore -- Contributing Editor, PHP -- is the founder of EasyPHPWebsites.com, and author of the popular book, "Easy PHP Websites with the Zend Framework". Jason is a cofounder and speaker chair of CodeMash, a nonprofit organization tasked with hosting an annual namesake developer's conference, and was a member of the 2008 MySQL Conference speaker selection board.