FAQ
Hi guys,

I am new in Lucene but i like a lot. I am trying to develop a search
engine.
I have two problems:
First
I did a program for indexing files, here the code:

public void indexFile(String filename) throws Exception {
IndexWriter writer;
writer = new IndexWriter(path, new SimpleAnalyzer(), false);

InputStream is = new FileInputStream(filename);


Document doc = new Document();
doc.add(Field.UnIndexed("path", filename));
doc.add(Field.Text("body", (Reader) new
InputStreamReader(is)));

writer.addDocument(doc);
is.close();
writer.close();

}

when I do a search I receive severals links and the first is the link that I
need. The others link appear because the query have some letter or number
that match with the name of content of the file??? I don't know. I need a
help.

Second
I did a program for indexing a directory recursivily (my English is very
poor, I hope that you understand), here the code:

public void indexDirectory(String dir) throws Exception {

File file = new File(dir);

if (file.isDirectory()) {
File[] f = file.listFiles();
for (int x = 0; x < f.length; x++) {
if (f[x].isDirectory()) {
System.out.println("DIRECTORY:" +
f[x].getName());
// search recursive in directory

indexDirectory(f[x].getAbsolutePath());
} else {

System.out.println(" FILE: " +
f[x].getName());
indexFile(f[x].getAbsolutePath());
}
}

} else {
System.out.println(" FILE: " + file.getName());
indexFile(file.getAbsolutePath());
}

}
When I do a search after to do an indexing of a directory with files only I
have the FIRST problem. But when I do a search after to do an indexing of a
directory with subdirectories and this subdirectories with others
subdirectories and this others subdirectories with files, is not possible
to find the file that I want. What happens, there is an error in my code???
Some help I will appreciate.

Regards,
Michel

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

Search Discussions

  • Otis Gospodnetic at May 20, 2003 at 7:13 pm
    I believe Lucene comes with some demos that do just this. I suggest
    you look at those. I think IndexDemo is the name of one of the demo
    classes.

    Otis

    --- MMachado@LEVI.com wrote:
    Hi guys,

    I am new in Lucene but i like a lot. I am trying to develop a search
    engine.
    I have two problems:
    First
    I did a program for indexing files, here the code:

    public void indexFile(String filename) throws Exception {
    IndexWriter writer;
    writer = new IndexWriter(path, new SimpleAnalyzer(), false);

    InputStream is = new FileInputStream(filename);


    Document doc = new Document();
    doc.add(Field.UnIndexed("path", filename));
    doc.add(Field.Text("body", (Reader) new
    InputStreamReader(is)));

    writer.addDocument(doc);
    is.close();
    writer.close();

    }

    when I do a search I receive severals links and the first is the link
    that I
    need. The others link appear because the query have some letter or
    number
    that match with the name of content of the file??? I don't know. I
    need a
    help.

    Second
    I did a program for indexing a directory recursivily (my English is
    very
    poor, I hope that you understand), here the code:

    public void indexDirectory(String dir) throws Exception {

    File file = new File(dir);

    if (file.isDirectory()) {
    File[] f = file.listFiles();
    for (int x = 0; x < f.length; x++) {
    if (f[x].isDirectory()) {
    System.out.println("DIRECTORY:" +
    f[x].getName());
    // search recursive in directory

    indexDirectory(f[x].getAbsolutePath());
    } else {

    System.out.println(" FILE: " +
    f[x].getName());
    indexFile(f[x].getAbsolutePath());
    }
    }

    } else {
    System.out.println(" FILE: " + file.getName());
    indexFile(file.getAbsolutePath());
    }

    }
    When I do a search after to do an indexing of a directory with files
    only I
    have the FIRST problem. But when I do a search after to do an
    indexing of a
    directory with subdirectories and this subdirectories with others
    subdirectories and this others subdirectories with files, is not
    possible
    to find the file that I want. What happens, there is an error in my
    code???
    Some help I will appreciate.

    Regards,
    Michel

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

    __________________________________
    Do you Yahoo!?
    The New Yahoo! Search - Faster. Easier. Bingo.
    http://search.yahoo.com

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedMay 20, '03 at 7:07p
activeMay 20, '03 at 7:13p
posts2
users2
websitelucene.apache.org

2 users in discussion

Mmachado: 1 post Otis Gospodnetic: 1 post

People

Translate

site design / logo © 2022 Grokbase