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