View Javadoc
1   /*
2    * Copyright 2012-2025 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.rank.fusion;
17  
18  import java.util.Locale;
19  
20  import org.codelibs.core.lang.StringUtil;
21  import org.codelibs.fess.entity.SearchRequestParams;
22  import org.codelibs.fess.mylasta.action.FessUserBean;
23  import org.dbflute.optional.OptionalThing;
24  
25  /**
26   * Abstract base class for rank fusion searchers in the Fess search system.
27   * Rank fusion searchers are responsible for executing search queries and
28   * can be combined to implement advanced ranking strategies.
29   */
30  public abstract class RankFusionSearcher {
31      /** The name of this searcher, lazily initialized. */
32      protected String name;
33  
34      /**
35       * Default constructor for creating a new rank fusion searcher instance.
36       * This constructor initializes the searcher with default values.
37       * The searcher name will be lazily initialized when first accessed.
38       */
39      public RankFusionSearcher() {
40          // Default constructor - name will be initialized lazily
41      }
42  
43      /**
44       * Returns the name of this searcher.
45       * The name is derived from the class name by converting it to lowercase
46       * and removing the "Searcher" suffix.
47       *
48       * @return the searcher name
49       */
50      public String getName() {
51          if (name == null) {
52              name = StringUtil.decamelize(this.getClass().getSimpleName().replace("Searcher", StringUtil.EMPTY)).toLowerCase(Locale.ENGLISH);
53          }
54          return name;
55      }
56  
57      /**
58       * Executes a search operation with the specified parameters.
59       * This method must be implemented by concrete searcher classes.
60       *
61       * @param query the search query string
62       * @param params the search request parameters including pagination, filters, etc.
63       * @param userBean the optional user bean for access control and personalization
64       * @return the search result containing matched documents and metadata
65       */
66      protected abstract SearchResult search(String query, SearchRequestParams params, OptionalThing<FessUserBean> userBean);
67  
68  }