I had to comment out the "search" lines.

But then when I run this I don't hit any exception. Tested on Linux & Windows XP.

Mike

Allahbaksh Mohammedali Asadullah wrote:


Hi,
I am using lucene 2.3. The exception is properly handled when I run the program by lucene but when I debug it it hit the exception at addDocuement.
Regards,
Allahbaksh



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.FSDirectory;

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.StopAnalyzer;

import org.apache.lucene.analysis.standard.StandardAnalyzer;



public class InMemoryExample {



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

// Construct a RAMDirectory to hold the in-memory representation

        // of the index.

        RAMDirectory idx = new RAMDirectory();

        FSDirectory fs =FSDirectory.getDirectory("Z:\\lucene_index");

        //idx.createOutput("d:/idx");

        try {

            // Make an writer to create the index

            IndexWriter writer =

                new IndexWriter(fs,  true,new StandardAnalyzer());



            // Add some Document objects containing quotes

            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.addDocument(createDocument("Friedrich Hayek",

// "The case for individual freedom rests largely on the " +





//"recognition of the inevitable and universal ignorance " +

//"of all of us concerning a great many of the factors on " +

"which the achievements of our ends and welfare depend."),new StandardAnalyzer());

            writer.addDocument(createDocument("Ayn Rand",

//"There is nothing to take a man's freedom away from " +

//"him, save other men. To be free, a man must be free " +

                "of his brothers."));

            writer.addDocument(createDocument("Mohandas Gandhi",

//"Freedom is not worth having if it does not connote " +

                "freedom to err."));



// Optimize and close the writer to finish building the index

           // writer.optimize();

            writer.close();



            // Build an IndexSearcher using the in-memory index

            Searcher searcher = new IndexSearcher(fs);



            // Run some queries

            search(searcher, "freedom");

            search(searcher, "free");

            search(searcher, "progress or achievements");



            searcher.close();

        }

        catch(IOException ioe) {

            // In this example we aren't really doing an I/O, so this

            // exception should never actually be thrown.

            ioe.printStackTrace();

        }

        catch(ParseException pe) {

            pe.printStackTrace();

        }

} private static Document createDocument(String title, String content) {

        Document doc = new Document();



        // Add the title as an unindexed field...

Field f1 = new Field("title",title, Field.Store.YES,Field.Index.TOKENIZED);

        float temp = (float)Math.random();



System.out.print("Title of document is "+title +" Field 1 Boost value "+temp);

        f1.setBoost(temp);

        doc.add(f1);



        // ...and the content as an indexed field. Note that indexed

        // Text fields are constructed using a Reader. Lucene can read

        // and index very large chunks of text, without storing the

        // entire content verbatim in the index. In this example we

        // can just wrap the content string in a StringReader.



        temp =(float)Math.random();

Field f2 =new Field ("content",content,Field.Store.YES,Field.Index.TOKENIZED);

        f2.setBoost(temp);

        doc.add(f2);

        System.out.println(" Field 2 Boost value is " +temp);

        return doc;

    }

}


Allahbaksh Mohammedali Asadullah,
Software Engineering & Technology Labs,
Infosys Technolgies Limited, Electronics City,
Hosur Road, Bangalore 560 100, India.
*Board: +91-80-28520261 | Extn: 53915 | Direct: 41173915.
Fax: +91-80-28520362 | Mobile: +91-9845505322.
http://setlabs/slim/
http://allahbaksh.blogspot.com

-----Original Message-----
From: Michael McCandless [mailto:[EMAIL PROTECTED]
Sent: Friday, February 15, 2008 9:57 PM
To: java-user@lucene.apache.org
Subject: Re: Boost value corrupted "read eof exception"


Which version of Lucene are you using?

Can you post the full stack trace for the exception you're hitting?

Mike

Allahbaksh Mohammedali Asadullah wrote:


Hi,
I am getting read past eof  exception when I am adding Document.
The things works fine but while I read the Boost value I get it as
default value i.e 1.0. I tried using RAMDirectory then also I am
getting the same error.
Can someone throw some light on this.

Warm Regards,
Allahbaksh





**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION
intended solely for the use of the addressee(s). If you are not the
intended recipient, please notify the sender by e-mail and delete
the original message. Further, you are not to copy, disclose, or
distribute this e-mail or its contents to any other person and any
such actions are unlawful. This e-mail may contain viruses. Infosys
has taken every reasonable precaution to minimize this risk, but is
not liable for any damage you may sustain as a result of any virus
in this e-mail. You should carry out your own virus checks before
opening the e-mail or attachment. Infosys reserves the right to
monitor and review the content of all messages sent to or from this
e-mail address. Messages sent to or from this e-mail address may be
stored on the Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to