My Indexing Code
-------------------------------
public void index(File indexDir, File dataDir) throws IOException
{
if (!dataDir.exists() || !dataDir.isDirectory()) {
throw new IOException(dataDir + " does not exist or is not a
directory");
}
IndexWriter writer = new IndexWriter(indexDir, new
StandardAnalyzer(), true);
indexDirectory(writer, dataDir);
writer.close();
}
public void indexDirectory(IndexWriter writer, File dir) throws
IOException {
File[] files = dir.listFiles();
System.out.println("TOTAL NUMBER OF FILES :"+files.length);
for (int i=0; i < files.length; i++)
{
File f = files[i];
if (f.isDirectory()) {
indexDirectory(writer, f); // recurse
} else if (f.getName().endsWith(".txt") ||
f.getName().endsWith(".doc"))
{
indexFile(writer, f);
}
}
}
public void indexFile(IndexWriter writer, File f) throws IOException
{
System.out.println("Indexing " + f.getName()); /*Print the Indexed
File Names*/
Document doc = new Document();
doc.add(Field.Text("contents", new FileReader(f)));
doc.add(Field.Keyword("filename", f.getCanonicalPath()));
writer.addDocument(doc);
}
--------------------------------------------------------------------
My Searching code...public Vector search(File indexDir, String q) throws
Exception
{
Vector vecname=new Vector();
Directory fsDir = FSDirectory.getDirectory(indexDir, false);
IndexSearcher is = new IndexSearcher(fsDir);
Query query = QueryParser.parse(q, "contents", new StandardAnalyzer());
Hits hits = is.search(query);
System.out.println("Found " + hits.length() + " document(s) that matched
query '" + q + "':");
for (int i = 0; i < hits.length(); i++)
{
Document doc = hits.doc(i);
vecname.add(doc.get("filename"));
//System.out.println(doc.get("filename"));
//System.out.println(hits.length());
}
/** Creates a new instance of ContentSearcher */
return vecname;
}
------------------------------------------------------------------
On Jan 25, 2008 1:35 PM, anjana m <[EMAIL PROTECTED]> wrote:
> I want to retain the older index.
> I dont want to delete the older index.
> Please help me.
> Does the recent release has the option to update the indexes without
> deleting it.
> I am ruuning the indexer on my sun application server.
> and its thorwing exceptions like cannot delete indexex.
> now every time i add new docs..i need to create a new index directory
> andmake my program point to thenew index directory.
> Please provide me..info about how can i handle the same..
> And also i would like to know abt the latest version..where it has fetures
> to update indexes without deleting it..
>
>
> Thanks and regards
> anjana
>