<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">AIT</journal-id><journal-title-group><journal-title>Advances in Internet of Things</journal-title></journal-title-group><issn pub-type="epub">2161-6817</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/ait.2012.24013</article-id><article-id pub-id-type="publisher-id">AIT-23718</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Computer Science&amp;Communications</subject></subj-group></article-categories><title-group><article-title>
 
 
  Application of Full Text Search Engine Based on Lucene
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>ujia</surname><given-names>Gao</given-names></name><xref ref-type="aff" rid="aff1"><sup>1</sup></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Danying</surname><given-names>Li</given-names></name><xref ref-type="aff" rid="aff2"><sup>2</sup></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Wanlong</surname><given-names>Li</given-names></name><xref ref-type="aff" rid="aff1"><sup>1</sup></xref><xref ref-type="aff" rid="aff3"><sup>3</sup></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Yaze</surname><given-names>Dong</given-names></name><xref ref-type="aff" rid="aff4"><sup>4</sup></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib></contrib-group><aff id="aff1"><addr-line>Computer Science and Technology, Changchun University of Technology</addr-line></aff><aff id="aff3"><addr-line>Computer Science and Technology, Changchun University of Technology, Changchun, China</addr-line></aff><aff id="aff2"><addr-line>Changchun Rural Commercial Bank, Changchun, China</addr-line></aff><aff id="aff4"><addr-line>Software Vocational and Technical College, Changchun University of Technology, Changchun, China</addr-line></aff><author-notes><corresp id="cor1">* E-mail:<email>gaorujia723@126.com(UG)</email>;<email>Shadow_519@126.com(DL)</email>;<email>lwl@mail.ccut.edu.cn(WL)</email>;<email>DongYaze@mail.edu.cn(YD)</email>;</corresp></author-notes><pub-date pub-type="epub"><day>30</day><month>10</month><year>2012</year></pub-date><volume>02</volume><issue>04</issue><fpage>106</fpage><lpage>109</lpage><history><date date-type="received"><day>August</day>	<month>12,</month>	<year>2012</year></date><date date-type="rev-recd"><day>September</day>	<month>28,</month>	<year>2012</year>	</date><date date-type="accepted"><day>October</day>	<month>10,</month>	<year>2012</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  This paper introduces us the full-text search engine based on Lucene and full-text retrieval technology, including indexing and system architecture, compares the full-text search of Lucene with the String search retrieval’s response time, the experimental results show that the full text search of Lucene has faster retrieval speed.
 
</p></abstract><kwd-group><kwd>Full Text Search Engine; System Architecture; Lucene</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>With the rapid development of Internet and with the explosive growth of Web information, Internet users how to remove the impurities and retained the essence quickly and easily to gain the information they need in the vast ocean of information to become a hot research topic in this field.</p><p>The core of information search is the full-text retrieval technology. Full-text search technology provided us with the information retrieval tool according to the content of data rather than the external features based on a variety of computer data such text, sound, image as processing object [<xref ref-type="bibr" rid="scirp.23718-ref1">1</xref>]. Create all the possible terms in the index which are searched by network users as well as help people to manage and order extensive information and enable network users to quickly and easily retrieve any information they need. Lucene is a pure Java software project which is mature, free and open source. In recent years, Lucene has become one of the most highly praise and most popular information retrieval library.</p></sec><sec id="s2"><title>2. The Process of Full Text Search</title><sec id="s2_1"><title>2.1. Build a Text Database</title><p>Firstly, we should build a text database which is used to store all information retrieved by the user, then determine text model of retrieval system. The model has an identifiable and low degree of redundancy [<xref ref-type="bibr" rid="scirp.23718-ref2">2</xref>]. Once the model is confirmed, we should not make further more changes any longer.</p></sec><sec id="s2_2"><title>2.2. Create Indexing</title><p>Create index with the model according to the text of database. Indexing can greatly improve the speed of information retrieval. Which way do you use depends on the scale of information retrieval system. Large-scale information retrieval systems such as Google, Baidu take advantage of the approach of inverted index.</p></sec><sec id="s2_3"><title>2.3. Search</title><p>After indexing the documents, you can start to search information you need. Search requests are submitted by the users and information retrieval systems to preprocess and search the information eventually return user the information.</p></sec><sec id="s2_4"><title>2.4. Filter and Sort the Results</title><p>After the information retrieval system search the information that the users need and it will filter or sort the information by making a certain rule and then return the user related information [<xref ref-type="bibr" rid="scirp.23718-ref3">3</xref>].</p></sec></sec><sec id="s3"><title>3. Full Text Search Engine of Lucene</title><p>Lucene is one of the Jakarta projects of Apache Software Foundation which is an open source full text search engine toolkit, it’s not a full text search engine [<xref ref-type="bibr" rid="scirp.23718-ref4">4</xref>], but a full-text search engine framework that can provide users complete query engine, text indexing engine and part of the analysis engine, it can also provide a simple but powerful API interface so that people can conveniently and quickly develop the search engine.</p><sec id="s3_1"><title>3.1. Systematic Systematic Structure of Lucene</title><p>Lucene is an excellent full text search engine, its structure has a strong object-oriented features. Lucene source package has seven modules, the five main modules are as follows [<xref ref-type="bibr" rid="scirp.23718-ref5">5</xref>]:</p><p>1) Org.apache.lucene.analysis Analyzer, Its primary role is to segment the document and remove the stop words which are no help for retrieve but occurrence frequency is very high such as “and” “ah” further separate semantic search words such as Chinese phrase, English words and E-mail address. Lucene can also provide us with two parsers such as SimpleAnalyzer and StandardAnalyzer.</p><p>2) Org.apache.lucene.document Document Management, Document is similar to a record in relational database, it mainly responsible for the management of fields, and it divided into text field and date field.</p><p>3) Org.apache.lucene.index Indexing Management, including the establishment of index, inserts records and deletes records. Indexing package is the core of information retrieval system, the purpose of full text search is to adopt the terms which are separated to create index so user can search the information only to those have indexed but not the full text search further greatly improve the efficiency of information retrieval.</p><p>4) Org.apache.lucene.search Search Management, according to the query to obtain the results of retrieval.</p><p>5) Org.apache.lucene.queryParser queryParser, parsing the user query and then pass the searcher.</p></sec><sec id="s3_2"><title>3.2. The Indexing of Lucene</title><p>In Lucene, an index is composed of segments, a segment is made up of documents, a document is composed of fields, and many terms consist of a field. The index process of Lucene is started from the add Document method of IndexWriter, as shown in <xref ref-type="fig" rid="fig1">Figure 1</xref> [<xref ref-type="bibr" rid="scirp.23718-ref6">6</xref>].</p><p>In <xref ref-type="fig" rid="fig1">Figure 1</xref>, introduce a new class is DocumentWriter. In the API of Lucene, the main role of IndexWriter is to add documents to the indexing which provides us with the main interface for indexing. But writing process of indexing is completed by DocumentWriter. Separating data source and calculating the frequency and location of keywords as well as writing process of indexing is the most complicated thing in Lucene, which are actually occurred in the class of DocumentWriter.</p><p>Except for adding documents to indexing, Lucene will go further judge some cases about indexing and then merge indexing [<xref ref-type="bibr" rid="scirp.23718-ref7">7</xref>].</p></sec></sec><sec id="s4"><title>4. Examples of Lucene Retrieval Application</title><p>Lucene full text search is mainly composed of analysis, indexing and searching three modules. Analysis module is responsible for preprocessing document information; the principal role of indexing module is to enhance the speed of retrieval; searching module is mainly used for interacting to users [<xref ref-type="bibr" rid="scirp.23718-ref8">8</xref>].</p><sec id="s4_1"><title>4.1. System Implementation</title><p>This paper employed the toolkits of Lucene to simulate two documents retrieval in the Eclipse development environment [<xref ref-type="bibr" rid="scirp.23718-ref9">9</xref>]. Lucene Development Kit version is LUCENE-CORE-2.0.0. JAR and its word tool is JEANALYSIS-1.4.0.JAR, it can also require java runtime environment above JDK1.6 version and need to import JAR package into Eclipse [<xref ref-type="bibr" rid="scirp.23718-ref10">10</xref>].</p><p>1) Preprocessing Module: Before using Lucene we need to preprocess the prepared text documents. The mainly role of preprocessing is to convert full-width characters into half-width characters. In order to better display the use of Lucene, this paper will divide the large documents into small documents and assign a unique ID number for each document. Main codes are as follows:</p><p>public class FilePreprocess {</p><p>public static void preprocess (File file1, String outputDir)</p><p>splitToSmall (characterProcess (file,outputDir + “output.all”), outputDir)</p><p>public static File character Process (File file1, String destFile)</p><p>private static String replace (String line)</p><p>public static void splitToSmall (File file1, String outputpath)</p><p>}</p><p>The replace method is used for storing full-width characters and half-width characters by creating a HashMap and then traverse HashMap, if full-width characters are found we can replace it and finally return replaced characters. The characterProcess method is to convert full-width characters into half-width characters and return new files. The splitToSmall method is to call characterProcess to complete the replacement of full-width characters and half-width characters and finally return new file as splitToSmall method’s first parameter, new files named for “output.all” and stored it into outputDir.</p><p>Then the splitToSmall method is to divide new files into several small files and stored it into the directory of outputDir.</p><p>2) Indexing Module: After processing the document, you can use Lucene to process relevant information. Firstly, create indexing for processing documents. Secondly, build query object; Lastly, search in index. At first create a new IndexProcessor class for the document, the main code are as follows [<xref ref-type="bibr" rid="scirp.23718-ref11">11</xref>]:</p><p>public class IndexProcesser{</p><p>private String INDEX_STORE_PATH = “e:\\index1”</p><p>public void createIndex (String inputDir)</p><p>Directory dir = new SimpleFSDirectory (new File (INDEX_ STORE_PATH))</p><p>IndexWriter writer = new IndexWriter (dir, new Standard-Analyzer(), true,IndexWriter.MaxFieldLength.UNLIMITED)</p><p>Document doc = new Document ()</p><p>doc.add (new Field (“filename”, files [i]. getCanonicalPath()Field.Store.YES,Field.Index.NO_NORMS,Field.TermVector.YES))</p><p>doc.add(new Field (“content”, new FileReader (files [i])))</p><p>writer.addDocument (doc)</p><p>writer. close()</p><p>}</p><p>First of all, creating IndexWriter object which used StandardAnalyzer as an analysis tool, in order to generate indexing and store it into directory. IndexWriter. MaxField-Length. UNLIMITED shows that IndexWriter creates indexing for fields in the Document and the length of field has no limitations; secondly, creating Documents as well as Fields and adding fields like file name, file contents to Documents; Field.Store.YES indicates that it will store the field of file name; Field. Index. NO_ NORMS shows that it can indexing but not analyze file name; Field.TermVector.YES will store terms of field; FileReader (files [i]) stands for adding values to Fields by using the approach of FileReader; Finally join the document into indexing and use close method to close indexing and write all the data in the cache memory to the disk, close all the data flow. If not closed, the experimental results show that only one segment file in indexing directory.</p><p>3) Searching Module: After indexing, system will establish a search class, the class will provide us with two approaches, index-Search approach is used to search indexing which are built by Lucene. However, stringSearch approach used java long String to search information. You can also use the delete approach to delete operation on the preprocess text document. Main codes are as follows:</p><p>public class Search {</p><p>//search information with Lucene public void indexSearch(String searchType,String searchKey)</p><p>Directory dir = new SimpleFSDirectory( new File(INDEX _STORE_PATH))</p><p>IndexSearcher is = new IndexSearcher(dir)</p><p>QueryParser parser = new QueryParser(Version.LUCENE_ CURRENT, searchType, new StandardAnalyzer (Version. LUCENE_CURRENT))</p><p>Query query = parser.parse(searchKey)</p><p>Date beginTime = new Date ()</p><p>is.search(query, collector)</p><p>Date endTime = new Date ()</p><p>long timeOfSearch = endTime.getTime()-beginTime. getTime()</p><p>//search information with String public void stringSearch(String keyword, String searchDir){</p><p>Date beginTime=new Date ()</p><p>……</p><p>Date endTime=new Date ()</p><p>Long timeOffSearch=beginTime.getTime()-endTime.getTime()</p><p>public void delete()</p><p>IndexReader reader = IndexReader.open (new SimpleFSDirectory ( new File (INDEX_ STORE_PATH )), false)</p><p>String a1= &quot;E:\\testfolder\\output3.txt&quot;</p><p>Term term=new Term(&quot;title&quot;,a1)</p><p>int a2= reader. deleteDocuments (term)</p><p>System. out.println(a1+a2)</p><p>reader. deleteDocument(2150)</p><p>reader. close()</p><p>}</p><p>First give the search path then parse the string and generate query object to search information. The three main modules are the general process of all information retrieval.</p></sec><sec id="s4_2"><title>4.2. Experimental Results</title><p>Based on searching for two documents’ keywords to obtain retrieval results by comparing Lucene retrieval with String retrieval [<xref ref-type="bibr" rid="scirp.23718-ref12">12</xref>]. The number of the first document is 250,000 words, the former time is 75 ms, and the latter time is 1988ms; when the number of the document increased to 40 million words, the former time is 108ms, and the latter time is 5688ms. So we can see Lucene’s retrieval time-consuming is superior to String retrieval time-consuming. If string retrieval was applied to a largescale information retrieval system, the search speed will be intolerable when the information storage capacity reaches TB level.</p><p>The instance support document indexing and retrieval for the form of txt. If there is a need of practical applicationsyou can use PDFBox to process PDF documents and use POI to process Excel and Word and use Jacob to deal with word documents, as long as put data source into a Document object, you can search the information you need.</p></sec></sec><sec id="s5"><title>5. Conclusion</title><p>Lucene is a full text indexing engine toolkit written in Java, multi-user support access, quickly visit indexing time and can cross-platform use [<xref ref-type="bibr" rid="scirp.23718-ref13">13</xref>]. This paper in detail analyze the analysis of Lucene, indexing and searching three main modules from system architecture and compare the Lucene full text search with the String retrieval’s response time, the experimental results show that the Lucene full text search has faster retrieval speed.</p></sec><sec id="s6"><title>REFERENCES</title></sec></body><back><ref-list><title>References</title><ref id="scirp.23718-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">T. Hong, J. H. Li, P. Zhou and C. S. Gao, “Lucene IN ACTION,” Electronics Industry Press, Beijing, 2007.</mixed-citation></ref><ref id="scirp.23718-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">L. Zhong, H. Wang, R. T. Li and H. Z. Song, “Research and Development of Full Text Search Engine Based on Lucene,” Computer Engineering, Vol. 33, No. 8, 2007, pp. 282-284.</mixed-citation></ref><ref id="scirp.23718-ref3"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">X. Zhang and Y. Zhou, “Improvement of an Algorithm for Ranking Pages Based on Lucene,” Computer System Application, Vol. 18, No. 2, 2009, pp. 155-158.</mixed-citation></ref><ref id="scirp.23718-ref4"><label>4</label><mixed-citation publication-type="other" xlink:type="simple">B. Y. Lin, R. Zhao and L. C. Chen, “Research and Application of Full-Text Search Engine Based on Lucene,” Computer Technology and Development, Vol. 17, No. 5, 2007, pp. 184-187.</mixed-citation></ref><ref id="scirp.23718-ref5"><label>5</label><mixed-citation publication-type="other" xlink:type="simple">W. He, S. J. Xue, M. R. Kong, et al., “Design and Implementation of Full-Text Search Engine Based on Lucene,” Information Science, Vol. 3, No. 9, 2006, pp. 88-89.</mixed-citation></ref><ref id="scirp.23718-ref6"><label>6</label><mixed-citation publication-type="other" xlink:type="simple">Y. C. Li and H. F. Ding, “Research and Application of Full-Text Search Engine Based on Lucene,” Computer Technology and Development, Vol. 20, No. 2, 2010, pp. 4-56.</mixed-citation></ref><ref id="scirp.23718-ref7"><label>7</label><mixed-citation publication-type="other" xlink:type="simple">T. Liu, B. Qin, Y. Zhang and W. X. Che, “Introduction to Information Retrieval System,” China Machine Press, Beijing, 2008.</mixed-citation></ref><ref id="scirp.23718-ref8"><label>8</label><mixed-citation publication-type="other" xlink:type="simple">Q. Zhao, “Information Retrieval,” China Machine Press, Beijing, 2008.</mixed-citation></ref><ref id="scirp.23718-ref9"><label>9</label><mixed-citation publication-type="other" xlink:type="simple">C. Dong, “In the Application to Add Full-Text Search Function-Lucene Full-Text Indexing Engine Based on Java, [EB/OL],” 2012.  
http://www.chedong.com/tech/html</mixed-citation></ref><ref id="scirp.23718-ref10"><label>10</label><mixed-citation publication-type="other" xlink:type="simple">X. W. Lang and S. K. Wang, “Research and Development of Full Text Search Engine Based on Lucene,” Computer Engineering, Vol. 32, No. 4, 2006, pp. 95-99.</mixed-citation></ref><ref id="scirp.23718-ref11"><label>11</label><mixed-citation publication-type="other" xlink:type="simple">J. C. Cai, Y. P. Guo and L. Wang, “Design and Implementation of School Search Engine Based on Lucene Net,” Computer Technology and Development, Vol. 16, No. 11, 2006, pp. 73-75.</mixed-citation></ref><ref id="scirp.23718-ref12"><label>12</label><mixed-citation publication-type="other" xlink:type="simple">Z. Qiu, T. T. Fu, “Develop Its Own Search Engine Lucene2.0 + Heritrix.,” People Post Press, Beijing, 2007</mixed-citation></ref><ref id="scirp.23718-ref13"><label>13</label><mixed-citation publication-type="other" xlink:type="simple">J. Luan and J. F. Li, “Research and Application of Full Text Search Engine Based on Lucene,” Computer &amp; Digital Engineering, Vol. 38, No. 2, 2010, pp. 184-195.</mixed-citation></ref></ref-list></back></article>