lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <erickerick...@gmail.com>
Subject Re: Indexwriter()
Date Mon, 29 Aug 2011 13:54:35 GMT
OK, this sounds like a basic classpath issue, see:
http://download.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html

And you still haven't said what your problem is.
ClassNotFound? Compilation issues? Exceptions
thrown?

But you've really got to back up and spend some time
understanding how Java works before progressing on to
lucene. There are a ton of "beginning Java" sites
on the web that'll help you through basic Java issues,
and we can certainly answer the lucene/Solr specific ones

Best
Erick

On Mon, Aug 29, 2011 at 8:32 AM, Josh Am <josh22.am@gmail.com> wrote:
> oh, I'm so sorry. you are right, I'm a newcommer! here I explained all
> things I did!
>
> I want to index some txt files in Lucene, for this means I copied a Index
> Sourcecode, here is the code:
>
>
> *
>
> import* java.io.File;
> *
>
> import* java.io.FileReader;
> *
>
> import* java.io.IOException;
> *
>
> import* *org.apache.lucene.analysis.SimpleAnalyzer*;
> *
>
> import* org.apache.lucene.analysis.standard.StandardAnalyzer;
> *
>
> import* org.apache.lucene.document.Document;
> *
>
> import* org.apache.lucene.document.Field;
> *
>
> import* org.apache.lucene.index.IndexWriter;
> *
>
> import* *org.apache.lucene.store.Directory*;
> *
>
> import* org.apache.lucene.store.FSDirectory;
> *
>
> import* org.apache.lucene.store.RAMDirectory;
> *
>
> import* org.apache.lucene.util.Version;
>
> *
>
> public* *class* SimpleFileIndexer {
>
> *public* *static* *void* main(String[] args) *throws* Exception {
>
> File indexDir = *new* File("C:/Users/josh/documents");
>
> File dataDir = *new* File("C:/Users/josh/index");
>
> String suffix = "txt";
>
> SimpleFileIndexer indexer = *new* SimpleFileIndexer();
>
> *int* numIndex = indexer.index(indexDir, dataDir, suffix);
>
> System.*out*.println("Total files indexed " + numIndex);
>
> }
>
> *private* *int* index(File indexDir, File dataDir, String suffix)
> *throws*Exception {
>
> RAMDirectory ramDir = *new* RAMDirectory();
>
> IndexWriter indexWriter = *new* *IndexWriter(ramDir,
> newStandardAnalyzer(Version.
> LUCENE_33), true,
>
> IndexWriter.MaxFieldLength.UNLIMITED)*;
>
> indexWriter.*setUseCompoundFile(false)*;
>
> indexDirectory(indexWriter, dataDir, suffix);
>
> *int* numIndexed = indexWriter.maxDoc();
>
> indexWriter.optimize();
>
> indexWriter.close();
>
>  IndexWriter index = *new* *IndexWriter(FSDirectory.open(indexDir),
>
> new StandardAnalyzer(Version.LUCENE_33), false,
>
> IndexWriter.MaxFieldLength.UNLIMITED)*;
>
> index.*addIndexesNoOptimize(ramDir)*;
>
> index.optimize();
>
> index.close();
>
> *return* numIndexed;
>
> }
>
>  *private* *void* indexDirectory(IndexWriter indexWriter, File dataDir,
> String suffix) *throws* IOException {
>
> File[] files = dataDir.listFiles();
>
> *for* (*int* i = 0; i < files.length; i++) {
>
> File f = files[i];
>
> *if* (f.isDirectory()) {
>
> indexDirectory(indexWriter, f, suffix);
>
> }
>
> *else* {
>
> indexFileWithIndexWriter(indexWriter, f, suffix);
>
> }
>
> }
>
> }
>
> *private* *void* indexFileWithIndexWriter(IndexWriter indexWriter, File f,
> String suffix) *throws* IOException {
>
> *if* (f.isHidden() || f.isDirectory() || !f.canRead() || !f.exists()) {
>
> *return*;
>
> }
>
> *if* (suffix!=*null* && !f.getName().endsWith(suffix)) {
>
> *return*;
>
> }
>
> System.*out*.println("Indexing file " + f.getCanonicalPath());
>
> Document doc = *new* Document();
>
> doc.add(*new* Field("contents", *new* FileReader(f)));
>
> doc.add(*new* Field("filename", f.getCanonicalPath(), Field.Store.*YES*,
> Field.Index.*ANALYZED*));
>
> indexWriter.addDocument(doc);
>
> } }
>
>  then I added Lucene-core3.0.2 jar file but some functions and classes have
> problem! (some parts with line in the code!!)
>
> I have never worked with java before and all these are new for me, just I
> want to run this code. I really need it, please help me and tell me which
> steps I should do.
>
> Thanks alot, and sorry for bad guidence once more.
> On Mon, Aug 29, 2011 at 3:50 PM, Erick Erickson <erickerickson@gmail.com>wrote:
>
>> First, please review:
>> http://wiki.apache.org/solr/UsingMailingLists
>>
>> There is nothing here at all that will allow anyone to
>> help you with your problem, you have to tell us what
>> you've done, what you expect, and what actually
>> happened.
>>
>> Best
>> Erick
>>
>> On Mon, Aug 29, 2011 at 1:58 AM, Josh Am <josh22.am@gmail.com> wrote:
>> > Dear friends Hi!!
>> > I used Lucene to index some documents but unfortunetly I am a begginer
>> and
>> > there is a bug!!
>> > it is here!
>> >
>> > what should I do?
>> >
>> > thanyou all.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> > For additional commands, e-mail: java-user-help@lucene.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>

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


Mime
View raw message