示例#1
0
 // We never actually reindex posts currently, implement just for completeness
 @Override
 protected void doDelete(IndexReader reader, List<Object> ids) throws IOException {
   for (Object o : ids) {
     Guid guid = (Guid) o;
     Term term = new Term("id", guid.toString());
     reader.deleteDocuments(term);
   }
 }
示例#2
0
  /** 具体执行删除索引的方法,将被工作流中DeleteTask类的workrun()方法调用。 */
  public void deleteIndex() throws IOException {

    Directory fsDir = FSDirectory.getDirectory(indexFile);
    Term t = new Term("ID", String.valueOf(this.id));
    IndexReader reader = IndexReader.open(fsDir);
    reader.deleteDocuments(t);
    reader.close();
    fsDir.close();
  }
示例#3
0
 public void delete02() {
   try {
     reader.deleteDocuments(new Term("id", "1"));
   } catch (CorruptIndexException e) {
     e.printStackTrace();
   } catch (LockObtainFailedException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  private void processDeletes(
      SearchIndexBuilderWorker worker, Connection connection, List<SearchBuilderItem> runtimeToDo)
      throws SQLException, IOException {

    if (indexStorage.indexExists()) {
      IndexReader indexReader = null;
      try {
        indexReader = indexStorage.getIndexReader();

        // Open the index
        for (Iterator<SearchBuilderItem> tditer = runtimeToDo.iterator();
            worker.isRunning() && tditer.hasNext(); ) {
          SearchBuilderItem sbi = (SearchBuilderItem) tditer.next();
          if (!SearchBuilderItem.STATE_LOCKED.equals(sbi.getSearchstate())) {
            // should only be getting pending
            // items
            log.warn(
                " Found Item that was not pending " //$NON-NLS-1$
                    + sbi.getName());
            continue;
          }
          if (SearchBuilderItem.ACTION_UNKNOWN.equals(sbi.getSearchaction())) {
            sbi.setSearchstate(SearchBuilderItem.STATE_COMPLETED);
            updateOrSave(connection, sbi);

            continue;
          }
          // remove document
          // if this is mult segment it might not work.
          try {
            indexReader.deleteDocuments(new Term(SearchService.FIELD_REFERENCE, sbi.getName()));
            if (SearchBuilderItem.ACTION_DELETE.equals(sbi.getSearchaction())) {
              sbi.setSearchstate(SearchBuilderItem.STATE_COMPLETED);
              updateOrSave(connection, sbi);

            } else {
              sbi.setSearchstate(SearchBuilderItem.STATE_PENDING_2);
            }

          } catch (IOException ex) {
            log.warn("Failed to delete Page ", ex); // $NON-NLS-1$
          }
        }
      } finally {
        if (indexReader != null) {
          indexStorage.closeIndexReader(indexReader);
          indexReader = null;
        }
      }
    }
  }
 /** @see LuceneIndexReader#deleteDocuments(Term) */
 public int deleteDocuments(Term term) throws IOException {
   return indexReader.deleteDocuments(term);
 }