You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Liaqat Ali <li...@gmail.com> on 2007/11/29 09:42:40 UTC

Deprecated API

i m studying LIA. but there is a problem with code. When i run the code 
i get errorsThe errors are related with the use of deprecated 
APIs.Kindly suggest me the right APIs and also instructions how to 
handle this situation with other code..


package lia.indexing;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;

import junit.framework.TestCase;
import java.io.IOException;

/**
 *
 */
public abstract class BaseIndexingTestCase extends TestCase {
  protected String[] keywords = {"1", "2"};
  protected String[] unindexed = {"Netherlands", "Italy"};
  protected String[] unstored = {"Amsterdam has lots of bridges",
                                 "Venice has lots of canals"};
  protected String[] text = {"Amsterdam", "Venice"};
  protected Directory dir;

  protected void setUp() throws IOException {
    String indexDir =
      System.getProperty("java.io.tmpdir", "tmp") +
      System.getProperty("file.separator") + "index-dir";
    dir = FSDirectory.getDirectory(indexDir, true);
    addDocuments(dir);
  }

  protected void addDocuments(Directory dir)
    throws IOException {
    IndexWriter writer = new IndexWriter(dir, getAnalyzer(),
      true);
    writer.setUseCompoundFile(isCompound());
    for (int i = 0; i < keywords.length; i++) {
      Document doc = new Document();
      doc.add(Field.Keyword("id", keywords[i]));
      doc.add(Field.UnIndexed("country", unindexed[i]));
      doc.add(Field.UnStored("contents", unstored[i]));
      doc.add(Field.Text("city", text[i]));
      writer.addDocument(doc);
    }
    writer.optimize();
    writer.close();
  }

  protected Analyzer getAnalyzer() {
    return new SimpleAnalyzer();
  }

  protected boolean isCompound() {
    return true;
  }

  public void testIndexWriter() throws IOException {
    IndexWriter writer = new IndexWriter(dir, getAnalyzer(),
      false);
    assertEquals(keywords.length, writer.docCount());
    writer.close();
  }

  public void testIndexReader() throws IOException {
    IndexReader reader = IndexReader.open(dir);
    assertEquals(keywords.length, reader.maxDoc());
    assertEquals(keywords.length, reader.numDocs());
    reader.close();
  }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Deprecated API

Posted by Grant Ingersoll <gs...@apache.org>.
Have a look at the Field.java class and it's constructors.  The other  
option is to look at what was deprecated on Lucene 1.9 and then look  
at Lucene 2.x.

Also, I have some up to date example files of indexing, etc. at http://www.lucenebootcamp.com 
  (follow the link to the SVN repository) which you can check out and  
compare.

Cheers,
Grant

On Nov 29, 2007, at 3:42 AM, Liaqat Ali wrote:

> i m studying LIA. but there is a problem with code. When i run the  
> code i get errorsThe errors are related with the use of deprecated  
> APIs.Kindly suggest me the right APIs and also instructions how to  
> handle this situation with other code..
>
>
> package lia.indexing;
>
> import org.apache.lucene.store.Directory;
> import org.apache.lucene.store.FSDirectory;
> import org.apache.lucene.document.Document;
> import org.apache.lucene.document.Field;
> import org.apache.lucene.index.IndexWriter;
> import org.apache.lucene.index.IndexReader;
> import org.apache.lucene.analysis.Analyzer;
> import org.apache.lucene.analysis.SimpleAnalyzer;
>
> import junit.framework.TestCase;
> import java.io.IOException;
>
> /**
> *
> */
> public abstract class BaseIndexingTestCase extends TestCase {
> protected String[] keywords = {"1", "2"};
> protected String[] unindexed = {"Netherlands", "Italy"};
> protected String[] unstored = {"Amsterdam has lots of bridges",
>                                "Venice has lots of canals"};
> protected String[] text = {"Amsterdam", "Venice"};
> protected Directory dir;
>
> protected void setUp() throws IOException {
>   String indexDir =
>     System.getProperty("java.io.tmpdir", "tmp") +
>     System.getProperty("file.separator") + "index-dir";
>   dir = FSDirectory.getDirectory(indexDir, true);
>   addDocuments(dir);
> }
>
> protected void addDocuments(Directory dir)
>   throws IOException {
>   IndexWriter writer = new IndexWriter(dir, getAnalyzer(),
>     true);
>   writer.setUseCompoundFile(isCompound());
>   for (int i = 0; i < keywords.length; i++) {
>     Document doc = new Document();
>     doc.add(Field.Keyword("id", keywords[i]));
>     doc.add(Field.UnIndexed("country", unindexed[i]));
>     doc.add(Field.UnStored("contents", unstored[i]));
>     doc.add(Field.Text("city", text[i]));
>     writer.addDocument(doc);
>   }
>   writer.optimize();
>   writer.close();
> }
>
> protected Analyzer getAnalyzer() {
>   return new SimpleAnalyzer();
> }
>
> protected boolean isCompound() {
>   return true;
> }
>
> public void testIndexWriter() throws IOException {
>   IndexWriter writer = new IndexWriter(dir, getAnalyzer(),
>     false);
>   assertEquals(keywords.length, writer.docCount());
>   writer.close();
> }
>
> public void testIndexReader() throws IOException {
>   IndexReader reader = IndexReader.open(dir);
>   assertEquals(keywords.length, reader.maxDoc());
>   assertEquals(keywords.length, reader.numDocs());
>   reader.close();
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

--------------------------
Grant Ingersoll
http://lucene.grantingersoll.com

Lucene Helpful Hints:
http://wiki.apache.org/lucene-java/BasicsOfPerformance
http://wiki.apache.org/lucene-java/LuceneFAQ




---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org