View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.index;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.lucene.search.Query;
25  import org.apache.maven.index.context.IndexingContext;
26  
27  public class AbstractSearchRequest {
28      /**
29       * Constant for denoting undefined value for result count.
30       */
31      public static final int UNDEFINED = -1;
32  
33      private Query query;
34  
35      private List<IndexingContext> contexts;
36  
37      /**
38       * The maximum count of results expected to have delivered, actually count of items (AIs). More precisely, with this
39       * setting we LIMIT the number of Lucene Documents for total set of hits to be processed. If set to anything other
40       * than {@link #UNDEFINED}, search will stop upon processing this count of AIs (that correspond to Lucene Document).
41       */
42      private int count;
43  
44      /**
45       * The filter to be used while executing the search request.
46       */
47      private ArtifactInfoFilter artifactInfoFilter;
48  
49      /**
50       * The postprocessor to apply to hits while returning the,
51       */
52      private ArtifactInfoPostprocessor artifactInfoPostprocessor;
53  
54      /**
55       * The highlighting requests, if any.
56       */
57      private List<MatchHighlightRequest> matchHighlightRequests;
58  
59      /**
60       * Should Lucene Explanations be added to resulting ArtifactInfo's attributes (keyed as
61       * org.apache.lucene.search.Explanation.class.getName())? Warning: calculating these are costly operation, and
62       * should not be used in production systems (maybe on some "debug" like UI or so).
63       */
64      private boolean luceneExplain = false;
65  
66      public AbstractSearchRequest(Query query) {
67          this(query, null);
68      }
69  
70      public AbstractSearchRequest(Query query, List<IndexingContext> contexts) {
71          this.query = query;
72  
73          if (contexts != null) {
74              getContexts().addAll(contexts);
75          }
76  
77          this.count = UNDEFINED;
78      }
79  
80      public Query getQuery() {
81          return query;
82      }
83  
84      public void setQuery(Query query) {
85          this.query = query;
86      }
87  
88      public List<IndexingContext> getContexts() {
89          if (contexts == null) {
90              contexts = new ArrayList<>();
91          }
92  
93          return contexts;
94      }
95  
96      public void setContexts(List<IndexingContext> contexts) {
97          this.contexts = contexts;
98      }
99  
100     /**
101      * Returns the "count" of wanted results. See {@link #UNDEFINED} and {@link #count}.
102      *
103      * @return
104      */
105     public int getCount() {
106         return count;
107     }
108 
109     /**
110      * Sets the "count" of wanted results. See {@link #UNDEFINED} and {@link #count}.
111      *
112      * @param count
113      */
114     public void setCount(int count) {
115         if (UNDEFINED != count && count < 1) {
116             throw new IllegalArgumentException("Count cannot be less than 1!");
117         }
118 
119         this.count = count;
120     }
121 
122     /**
123      * Returns true if hits are limited.
124      *
125      * @return
126      * @deprecated always returns false, since 4.1.0 there is no notion of hit limit
127      * @see http://jira.codehaus.org/browse/MINDEXER-14
128      */
129     @Deprecated
130     public boolean isHitLimited() {
131         return false;
132     }
133 
134     /**
135      * Gets the hit limit. Since 4.1.0 does nothing, always returns -1 (was "no hit limit").
136      *
137      * @return
138      * @deprecated always returns -1 (no hit limit), since 4.1.0 there is no notion of hit limit
139      * @see http://jira.codehaus.org/browse/MINDEXER-14
140      */
141     @Deprecated
142     public int getResultHitLimit() {
143         return -1;
144     }
145 
146     /**
147      * Sets the hit limit. Since 4.1.0 does nothing.
148      *
149      * @param resultHitLimit
150      * @deprecated does nothing, since 4.1.0 there is no notion of hit limit
151      * @see http://jira.codehaus.org/browse/MINDEXER-14
152      */
153     @Deprecated
154     public void setResultHitLimit(int resultHitLimit) {
155         // noop
156     }
157 
158     public ArtifactInfoFilter getArtifactInfoFilter() {
159         return artifactInfoFilter;
160     }
161 
162     public void setArtifactInfoFilter(ArtifactInfoFilter artifactInfoFilter) {
163         this.artifactInfoFilter = artifactInfoFilter;
164     }
165 
166     public ArtifactInfoPostprocessor getArtifactInfoPostprocessor() {
167         return artifactInfoPostprocessor;
168     }
169 
170     public void setArtifactInfoPostprocessor(ArtifactInfoPostprocessor artifactInfoPostprocessor) {
171         this.artifactInfoPostprocessor = artifactInfoPostprocessor;
172     }
173 
174     public List<MatchHighlightRequest> getMatchHighlightRequests() {
175         if (matchHighlightRequests == null) {
176             matchHighlightRequests = new ArrayList<>();
177         }
178 
179         return matchHighlightRequests;
180     }
181 
182     public void setMatchHighlightRequests(List<MatchHighlightRequest> matchHighlightRequests) {
183         this.matchHighlightRequests = matchHighlightRequests;
184     }
185 
186     public boolean isLuceneExplain() {
187         return luceneExplain;
188     }
189 
190     public void setLuceneExplain(boolean luceneExplain) {
191         this.luceneExplain = luceneExplain;
192     }
193 }