lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scott cote <scottcc...@gmail.com>
Subject update of a numerical field in a lucene document
Date Fri, 08 Apr 2016 19:21:26 GMT
All,

I’m missing a not so secret "secret sauce" somewhere in my simple code (say that 5 times
real fast - no not “that”).  Am trying to show the efficiency increase of delete/create
a document in lucene (the old way of updating a document) versus the newly supported mode
of being able to update a specific field.  Unfortunately, despite my best efforts, I can’t
seem to get the field to update.

Below are the simplified portions of relevant code:

Setup of my index:

        final Path path = FileSystems.getDefault().getPath(indexDirectoryPath);
        final Directory indexDirectory = new SimpleFSDirectory(path);
        final IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());
        writer = new IndexWriter(indexDirectory, conf);


Creating the document in my lucene index:

        accumulator += 1l;
        final Document document = new Document();
        final Field contentField = new TextField(LuceneConstants.CONTENTS, new FileReader(file));
        final Field fileNameField = new StringField(LuceneConstants.FILE_NAME, file.getName(),
Field.Store.YES);
        final Field filePathField = new StringField(LuceneConstants.FILE_PATH, file.getCanonicalPath(),
Field.Store.YES);
        final Field fileEntryOrderField = new LongField(LuceneConstants.ENTRY_ORDER, accumulator,
Field.Store.YES);
        final Field fileEntryOrderNumericDocValuesField = new NumericDocValuesField(LuceneConstants.ENTRY_ORDER,
accumulator);
        document.add(contentField);
        document.add(fileNameField);
        document.add(filePathField);
        document.add(fileEntryOrderField);
        document.add(fileEntryOrderNumericDocValuesField);
        writer.addDocument(document);
        
        writer.commit();
        writer.close();




Updating the document in my lucene index

String searchTermString = "record2.txt”;
String field = LuceneConstants.ENTRY_ORDER;
long value = 100l;
final Term term = new Term(LuceneConstants.FILE_NAME,searchTermString);
writer.updateNumericDocValue(term, field, value);
writer.commit();
writer.close();




I expect the value of the numeric field to increase to zero, but I’m not seeing it when
i retrieve the document at a later step.  

From what I have observed in my debugger, the updateNumericDocValue method in IndexWriter
(lines 1509 through 1521 accepts the fields as pre-existing (passes the if statement that
ensures that the document has the field), but then is not gated into “processEvents(true,false);”
step as the line 1515 docWriter.updateDocValues(….) returns false.  can’t seem to pin
down why that is happening.

What am I missing?

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