Jelajahi Sumber

Search by DocID instead of ID when deleting old documents (#2787)

The method IndexingHelper#deleteOldDocuments() is responsible for removing
old search entries, and it seems that it can find these old entries correctly
(the docIdList correctly contains old entries).

But the deleteByQuery() call seems to be searching the wrong column (with the
default settings, it is searching by "_id" column instead of "doc_id").

This patch changes the QueryBuilder (used by deleteByQuery) from querying
by "_id" column to "doc_id" instead.
Hoang Trung Hieu 1 tahun lalu
induk
melakukan
642d96a1a6

+ 2 - 3
src/main/java/org/codelibs/fess/helper/IndexingHelper.java

@@ -121,8 +121,7 @@ public class IndexingHelper {
         }
         if (!docIdList.isEmpty()) {
             searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(),
-                    QueryBuilders.idsQuery().addIds(docIdList.stream().toArray(n -> new String[n])));
-
+                    QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIdList.stream().toArray(n -> new String[n])));
         }
     }
 
@@ -145,7 +144,7 @@ public class IndexingHelper {
     public long deleteDocumentsByDocId(final SearchEngineClient searchEngineClient, final List<String> docIdList) {
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
         return searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(),
-                QueryBuilders.idsQuery().addIds(docIdList.stream().toArray(n -> new String[n])));
+                QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIdList.stream().toArray(n -> new String[n])));
     }
 
     public long deleteDocumentByQuery(final SearchEngineClient searchEngineClient, final QueryBuilder queryBuilder) {