lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pranav goyal <pranavgoyal40...@gmail.com>
Subject Lucene Indexing
Date Mon, 06 Jun 2011 06:29:05 GMT
Hi all,

I am a newbie to lucene.
I have successfully created my lucene index. But I am not getting how to
invalidate previous indexes whenever I add/delete/update any field in my
lucene index.
Please help me out.

for better understanding I have wrote my indexing function :

StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
                IndexWriter writer = null;
                File indexDir = new File("./indexDir");
                try {
                        writer = new IndexWriter(FSDirectory.open(indexDir),
analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
                }
                catch (IOException e1) {
                        e1.printStackTrace();
                }


                //Adding New fields to the document
                Document d = new Document();
                d.add(new Field("key", key , Field.Store.YES ,
Field.Index.ANALYZED));


                // d.add(Field.Text("obj", attribute.toString()));
                // index in Lucene here
                if (attribute instanceof String) {
                        System.out.println("IN CMnString ");
                        d.add(new Field("attribute",attribute.toString(),
Field.Store.YES, Field.Index.NO));
                        System.out.println("key is ->"+key+"...Attribute is
"+attribute);
                }
                else if (attribute instanceof CMnMoney) {
                        System.out.println("IN CMnMoney ");
                        d.add(new Field("attribute",attribute.toString(),
Field.Store.YES, Field.Index.NO));
                        System.out.println("key is ->"+key+"...Value is
"+attribute);
                }
                else if (attribute instanceof CMnQuantity) {
                        System.out.println("IN CMnQuantity ");
                        d.add(new Field("attribute",attribute.toString(),
Field.Store.YES, Field.Index.NO));
                        System.out.println("key is ->"+key+"...Attribute is
"+attribute);
                }
                else if (attribute instanceof CMnEnum) {
                        System.out.println("IN CMnEnum ");
                        d.add(new Field("attribute",attribute.toString(),
Field.Store.YES, Field.Index.NO));
                        System.out.println("key is ->"+key+"...Attribute is
"+attribute);
                }
                else {
                        // see what else is there....
                }
                try {
                        writer.addDocument(d);
                        writer.optimize() ;
                        writer.close();
                }
                catch (IOException e1) {
                        e1.printStackTrace();
                }
        }



Please guide me further as I got stuck at this point.

I have searched a lot about this and all I got is I have to first delete
that document and then add that document again to my index.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message