Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene 4.0 Index writer - creating single index
    primarykey
    data
    text
    <p>I am trying to implement simplest lucene search. I followed <a href="http://www.informit.com/articles/article.aspx?p=461633&amp;seqNum=2" rel="nofollow">this</a> as my starting point.</p> <p>I can understand the sample code :</p> <pre><code>public static void indexHotel(Hotel hotel) throws IOException { IndexWriter writer = (IndexWriter) getIndexWriter(false); Document doc = new Document(); doc.add(new Field("id", hotel.getId(), Field.Store.YES, Field.Index.NO)); doc.add(new Field("name", hotel.getName(), Field.Store.YES, Field.Index.TOKENIZED)); doc.add(new Field("city", hotel.getCity(), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.add(new Field("description", hotel.getDescription(), Field.Store.YES, Field.Index.TOKENIZED)); String fullSearchableText = hotel.getName() + " " + hotel.getCity() + " " + hotel.getDescription(); doc.add(new Field("content", fullSearchableText, Field.Store.NO, Field.Index.TOKENIZED)); writer.addDocument(doc); } </code></pre> <p>the thing i can't get in this code is what does <code>getIndexWriter(false)</code> do . this method is nowhere mentioned in the post i followed. moreover in another code block :</p> <pre><code>public void rebuildIndexes() throws IOException { // // Erase existing index // getIndexWriter(true); // // Index all hotel entries // Hotel[] hotels = HotelDatabase.getHotels(); for(Hotel hotel: hotels) { indexHotel(hotel); } // // Don’t forget to close the index writer when done // closeIndexWriter(); } </code></pre> <p>some undefined methods are used. </p> <p>A bit confusing for beginner like me.</p> <p>I want to create only one index . i think <code>getIndexWriter(true);</code> and <code>closeIndexWriter()</code> are some utility methods just to get <code>IndexWriter</code> but i can't make any assumption for what does that <code>true</code> in <code>getIndexWriter(true);</code> is used for.</p> <p>By following some other post's iv'e got more confused regarding the creation of IndexWriter.</p> <p>Can somebody please put me on the right path if i am doing anything wrong ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload