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 MM...@LEVI.com on 2003/05/20 21:09:19 UTC
Lucene i like it!!!
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
Re: Lucene i like it!!!
Posted by Otis Gospodnetic <ot...@yahoo.com>.
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