Results 1 to 2 of 2
  1. #1
    annuvinod is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Thumbs up Instalation of lucence

    HI I AM GETTING ERROR WHILE EXECUTING MY PROJECT I SET ANT_HOME=C:\apache-ant-1.7.1;%ANT_HOME%\bin and CLASS PATH=C:\lucene-2.4.1\lucene-core-2.4.1.jar EVEN IT IS GIVING ERRORS AS IMPORT THE




    C:\Java>javac -cp C:\lucene-2.4.1\lucene-core-2.4.1.jar CreateIndex.java
    CreateIndex.java:6: package org.apache.lucence.index does not exist
    import org.apache.lucence.index.*;
    ^
    CreateIndex.java:13: cannot find symbol
    symbol : class IndexWriter
    location: class CreateIndex
    IndexWriter writer;
    ^
    CreateIndex.java:14: cannot find symbol
    symbol : class Directory
    location: class CreateIndex
    Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
    ^
    CreateIndex.java:14: cannot find symbol
    symbol : variable FSDirectory
    location: class CreateIndex
    Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
    ^
    CreateIndex.java:18: cannot find symbol
    symbol : class IndexWriter
    location: class CreateIndex


    import java.lang.*;
    import java.lang.Object;
    import java.io.IOException;
    import org.apache.lucence.index.*;


    public class CreateIndex {

    public static void main(String[] args) throws Exception {

    IndexWriter writer;
    Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);

    // An index is created by opening an IndexWriter with the
    // create argument set to true.
    writer = new IndexWriter(directory , null, true);
    writer.close();
    }
    }







    HOW CAN I SET THE PATH FOR LUCENSE IS THERE ANY WRONG IN MY CODE CODE IS










    import java.io.IOException;
    import java.io.StringReader;

    import org.apache.lucene.search.Hits;
    import org.apache.lucene.search.Query;
    import org.apache.lucene.document.Field;
    import org.apache.lucene.search.Searcher;
    import org.apache.lucene.index.IndexWriter;
    import org.apache.lucene.document.Document;
    import org.apache.lucene.store.RAMDirectory;
    import org.apache.lucene.search.IndexSearcher;
    import org.apache.lucene.queryParser.QueryParser;
    import org.apache.lucene.queryParser.ParseException;
    import org.apache.lucene.analysis.standard.StandardAnalyz er;

    public class InMemoryExample
    {

    public static void main(String[] args)
    {

    RAMDirectory idx = new RAMDirectory();

    try
    {

    IndexWriter writer = new IndexWriter(idx, new StandardAnalyzer(), true);


    writer.addDocument(createDocument("Theodore Roosevelt",
    "It behooves every man to remember that the work of the "
    + "critic, is of altogether secondary importance, and that, "
    + "in the end, progress is accomplished by the man who does "
    + "things."));

    writer.optimize();
    writer.close();


    Searcher searcher = new IndexSearcher(idx);


    search(searcher, "freedom");
    search(searcher, "free");
    search(searcher, "progress or achievements");

    searcher.close();
    }
    catch (IOException ioe)
    {

    ioe.printStackTrace();
    }
    catch (ParseException pe)
    {
    pe.printStackTrace();
    }
    }


    private static Document createDocument(String title, String content)
    {
    Document doc = new Document();


    doc.add(new Field("title", title, Field.Store.YES, Field.Index.NO));


    doc.add(new Field("content", new StringReader(content)));

    return doc;
    }


    private static void search(Searcher searcher, String queryString)
    throws ParseException, IOException
    {


    QueryParser parser = new QueryParser("content", new StandardAnalyzer());
    Query query = parser.parse(queryString);


    Hits hits = searcher.search(query);


    int hitCount = hits.length();
    if (hitCount == 0)
    {
    System.out.println("No matches were found for \"" + queryString + "\"");
    }
    else
    {
    System.out.println("Hits for \"" + queryString
    + "\" were found in quotes by:");


    for (int i = 0; i < hitCount; i++)
    {
    Document doc = hits.doc(i);


    System.out.println(" " + (i + 1) + ". " + doc.get("title"));
    }
    }
    System.out.println();
    }
    }
    Last edited by annuvinod; 07-03-2009 at 10:42 AM.

  2. #2
    kzvi.kzvi.1 is offline Member
    Join Date
    Oct 2008
    Location
    US
    Posts
    58
    Rep Power
    0

    Default

    Have you set the CLASSPATH variable? I see in your post you have mentioned "CLASS PATH" just checking its one word CLASSPATH, no spaces in between

    for windows you can set classpath by following command

    set CLASSPATH=C:\lucene-2.4.1\lucene-core-2.4.1.jar


    Another observation, not sure why you need ANT here if you are doing javac on command line. But if you need it you ANT_HOME needs to be set like this

    set ANT_HOME=C:\apache-ant-1.7.1
    set PATH=%ANT_HOME%\bin



    The value in your post - ANT_HOME=C:\apache-ant-1.7.1;%ANT_HOME%\bin
    is not correct.
    Have fun....
    JAVA FAQs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •