예제 #1
0
  /**
   * Destroy and rebuild index.
   *
   * @param fileList
   */
  public void rebuildIndex(final List<Document> documentList, final List<File> fileList) {
    LuceneUtil.handle(
        new LuceneRunnable() {
          @Override
          public void run(IndexWriter indexWriter) throws Exception {
            // Empty index
            indexWriter.deleteAll();

            // Add all documents
            Map<String, Document> documentMap = new HashMap<>();
            for (Document document : documentList) {
              org.apache.lucene.document.Document luceneDocument =
                  getDocumentFromDocument(document);
              indexWriter.addDocument(luceneDocument);
              documentMap.put(document.getId(), document);
            }

            // Add all files
            for (File file : fileList) {
              org.apache.lucene.document.Document luceneDocument =
                  getDocumentFromFile(file, documentMap.get(file.getDocumentId()));
              indexWriter.addDocument(luceneDocument);
            }
          }
        });
  }
예제 #2
0
 /**
  * Delete document from the index.
  *
  * @param id Document ID to delete
  */
 public void deleteDocument(final String id) {
   LuceneUtil.handle(
       new LuceneRunnable() {
         @Override
         public void run(IndexWriter indexWriter) throws Exception {
           indexWriter.deleteDocuments(new Term("id", id));
         }
       });
 }
예제 #3
0
 /**
  * Add document to the index.
  *
  * @param document Document to add
  */
 public void createDocument(final Document document) {
   LuceneUtil.handle(
       new LuceneRunnable() {
         @Override
         public void run(IndexWriter indexWriter) throws Exception {
           org.apache.lucene.document.Document luceneDocument = getDocumentFromDocument(document);
           indexWriter.addDocument(luceneDocument);
         }
       });
 }
예제 #4
0
 /**
  * Update document index.
  *
  * @param document Updated document
  */
 public void updateDocument(final Document document) {
   LuceneUtil.handle(
       new LuceneRunnable() {
         @Override
         public void run(IndexWriter indexWriter) throws Exception {
           org.apache.lucene.document.Document luceneDocument = getDocumentFromDocument(document);
           indexWriter.updateDocument(new Term("id", document.getId()), luceneDocument);
         }
       });
 }