View Javadoc
1   /*
2    * Copyright 2012-2021 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.job;
17  
18  import org.apache.logging.log4j.LogManager;
19  import org.apache.logging.log4j.Logger;
20  import org.codelibs.fesen.index.query.QueryBuilder;
21  import org.codelibs.fesen.index.query.QueryBuilders;
22  import org.codelibs.fess.es.client.SearchEngineClient;
23  import org.codelibs.fess.mylasta.direction.FessConfig;
24  import org.codelibs.fess.util.ComponentUtil;
25  
26  public class PurgeDocJob {
27  
28      private static final Logger logger = LogManager.getLogger(PurgeDocJob.class);
29  
30      public String execute() {
31          final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
32          final FessConfig fessConfig = ComponentUtil.getFessConfig();
33  
34          final StringBuilder resultBuf = new StringBuilder();
35  
36          // clean up
37          final QueryBuilder queryBuilder = QueryBuilders.rangeQuery(fessConfig.getIndexFieldExpires()).to("now");
38          try {
39              searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), queryBuilder);
40  
41          } catch (final Exception e) {
42              logger.error("Could not delete expired documents: {}", queryBuilder.toString(), e);
43              resultBuf.append(e.getMessage()).append("\n");
44          }
45  
46          return resultBuf.toString();
47      }
48  
49  }