Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-6983

IndexWriter.updateDocument on FSDirectory does not work Ver.5.4.0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 5.4
    • None
    • core/index
    • None
    • Windows 8, Java 1.8.0_60

    • New

    Description

      I try to create a simple index and then update documents (with IndexWriter.updateDocuments). When I use RAMDirectory it works fine (IndexWriter.numDocs returns correct value, IndexSearcher.search returns correct hits). However, when I use FSDirectory it creates duplicate documents, and IndexSearcher returns multiple documents with same key field values. Here is the code excerpt:
      //This code is in a thread and it updates documents with regular intervals, say 1 min.
      Analyzer analyzer = new StandardAnalyzer();
      try

      { Path path = Paths.get(indexDirectory); Directory directory = FSDirectory.open(path); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter iwriter = new IndexWriter(directory, config); System.out.println("Document count=" + iwriter.numDocs()); for (Company newCompany : newCompanies) { Document doc = new Document(); doc.add(new Field("entityid", "Company" + newCompany.getId().toString(), TextField.TYPE_STORED)); doc.add(new Field("companyname", newCompany.getName(), TextField.TYPE_NOT_STORED)); Term term = new Term("entityid", "Company" + newCompany.getId().toString()); iwriter.updateDocument(term, doc); }

      iwriter.flush();
      iwriter.commit();
      System.out.println("Document count2=" + iwriter.numDocs());
      iwriter.close();
      } catch (IOException e1)

      { e1.printStackTrace(); }

      Attachments

        Activity

          People

            Unassigned Unassigned
            uygaryuzsuren uygar yuzsuren
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: