Commit 09d251e393fe55cf7584731158a13cdb87971580
1 parent
f6c65fd0
fixes
Showing
46 changed files
with
1550 additions
and
1311 deletions
Too many changes to show.
To preserve performance only 41 of 46 files are displayed.
docker/Dockerfile
1 | 1 | # Automatically generated Dockerfile |
2 | -# - Build 2017-05-11 09:39 | |
2 | +# - Build 2017-05-12 20:20 | |
3 | 3 | # - Lucene/Solr version 6.5.1 |
4 | 4 | # - Mtas release 20170505 |
5 | 5 | # |
... | ... | @@ -74,7 +74,7 @@ RUN service apache2 stop && \ |
74 | 74 | chmod -R 755 /var/www/html && \ |
75 | 75 | printf "echo\n" >> /start.sh && \ |
76 | 76 | printf "echo \"================ Mtas -- Multi Tier Annotation Search =================\"\n" >> /start.sh && \ |
77 | - printf "echo \" Timestamp 2017-05-11 09:39\"\n" >> /start.sh && \ | |
77 | + printf "echo \" Timestamp 2017-05-12 20:20\"\n" >> /start.sh && \ | |
78 | 78 | printf "echo \" Lucene/Solr version 6.5.1\"\n" >> /start.sh && \ |
79 | 79 | printf "echo \" Mtas release 20170505\"\n" >> /start.sh && \ |
80 | 80 | printf "echo \" See https://meertensinstituut.github.io/mtas/ for more information\"\n" >> /start.sh && \ |
... | ... |
junit/mtas/parser/MtasCQLParserTestSentence.java
... | ... | @@ -7,6 +7,9 @@ import java.io.StringReader; |
7 | 7 | import java.util.ArrayList; |
8 | 8 | import java.util.List; |
9 | 9 | |
10 | +import org.apache.commons.logging.Log; | |
11 | +import org.apache.commons.logging.LogFactory; | |
12 | + | |
10 | 13 | import mtas.parser.cql.MtasCQLParser; |
11 | 14 | import mtas.parser.cql.ParseException; |
12 | 15 | import mtas.parser.cql.util.MtasCQLParserGroupQuery; |
... | ... | @@ -28,6 +31,8 @@ import mtas.search.spans.util.MtasSpanUniquePositionQuery; |
28 | 31 | |
29 | 32 | public class MtasCQLParserTestSentence { |
30 | 33 | |
34 | + private static Log log = LogFactory.getLog(MtasCQLParserTestSentence.class); | |
35 | + | |
31 | 36 | private void testCQLParse(String field, String defaultPrefix, String cql, MtasSpanQuery q) { |
32 | 37 | MtasCQLParser p = new MtasCQLParser(new BufferedReader(new StringReader(cql))); |
33 | 38 | try { |
... | ... | @@ -36,7 +41,7 @@ public class MtasCQLParserTestSentence { |
36 | 41 | //System.out.print("\n"); |
37 | 42 | } catch (ParseException e) { |
38 | 43 | //System.out.println("Error CQL parsing:\t"+cql); |
39 | - e.printStackTrace(); | |
44 | + log.error(e); | |
40 | 45 | } |
41 | 46 | } |
42 | 47 | |
... | ... | @@ -48,7 +53,7 @@ public class MtasCQLParserTestSentence { |
48 | 53 | assertEquals(p1.parse(field, defaultPrefix, null, null, null) ,p2.parse(field, defaultPrefix, null, null, null)); |
49 | 54 | } catch (ParseException e) { |
50 | 55 | //System.out.println("Error CQL equivalent:\t"+cql1+" and "+cql2); |
51 | - e.printStackTrace(); | |
56 | + log.error(e); | |
52 | 57 | } |
53 | 58 | } |
54 | 59 | |
... | ... | @@ -59,7 +64,7 @@ public class MtasCQLParserTestSentence { |
59 | 64 | String cql = "[pos=\"LID\"] [lemma=\"koe\"]"; |
60 | 65 | MtasSpanQuery q1 = new MtasCQLParserWordQuery(field,"pos","LID", null, null); |
61 | 66 | MtasSpanQuery q2 = new MtasCQLParserWordQuery(field,"lemma","koe", null, null); |
62 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
67 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
63 | 68 | items.add(new MtasSpanSequenceItem(q1, false)); |
64 | 69 | items.add(new MtasSpanSequenceItem(q2, false)); |
65 | 70 | MtasSpanQuery q = new MtasSpanSequenceQuery(items, null, null); |
... | ... | @@ -91,7 +96,7 @@ public class MtasCQLParserTestSentence { |
91 | 96 | MtasSpanQuery q1 = new MtasCQLParserWordQuery(field,"pos","LID", null, null); |
92 | 97 | MtasSpanQuery q2 = new MtasCQLParserWordQuery(field,"lemma","de", null, null); |
93 | 98 | MtasSpanQuery q3 = new MtasCQLParserWordQuery(field,"lemma","koe", null, null); |
94 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
99 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
95 | 100 | items.add(new MtasSpanSequenceItem(q2, false)); |
96 | 101 | items.add(new MtasSpanSequenceItem(q3, false)); |
97 | 102 | MtasSpanQuery q4 = new MtasSpanSequenceQuery(items, null, null); |
... | ... | @@ -131,7 +136,7 @@ public class MtasCQLParserTestSentence { |
131 | 136 | MtasSpanQuery q2 = new MtasCQLParserWordQuery(field,"pos","N", null, null); |
132 | 137 | MtasSpanQuery q3 = new MtasCQLParserWordQuery(field,"pos","ADJ", null, null); |
133 | 138 | MtasSpanQuery q4 = new MtasSpanOrQuery(q2,q3); |
134 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
139 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
135 | 140 | items.add(new MtasSpanSequenceItem(q1, false)); |
136 | 141 | items.add(new MtasSpanSequenceItem(q4, false)); |
137 | 142 | MtasSpanQuery q = new MtasSpanSequenceQuery(items, null, null); |
... | ... | @@ -147,7 +152,7 @@ public class MtasCQLParserTestSentence { |
147 | 152 | MtasSpanQuery q3 = new MtasCQLParserWordQuery(field,"pos","ADJ", null, null); |
148 | 153 | MtasSpanQuery q4 = new MtasCQLParserWordQuery(field,"lemma","paard",null, null); |
149 | 154 | MtasSpanQuery q5 = new MtasSpanOrQuery(new MtasSpanRecurrenceQuery(q2,2,3,null, null),new MtasSpanRecurrenceQuery(q3,2,3,null, null)); |
150 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
155 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
151 | 156 | items.add(new MtasSpanSequenceItem(q1, false)); |
152 | 157 | items.add(new MtasSpanSequenceItem(q5, false)); |
153 | 158 | items.add(new MtasSpanSequenceItem(q4, false)); |
... | ... | @@ -162,7 +167,7 @@ public class MtasCQLParserTestSentence { |
162 | 167 | MtasSpanQuery q1 = new MtasCQLParserWordQuery(field,"pos","LID",null, null); |
163 | 168 | MtasSpanQuery q2 = new MtasCQLParserWordQuery(field,"pos","ADJ",null, null); |
164 | 169 | MtasSpanQuery q3 = new MtasCQLParserWordQuery(field,"lemma","koe",null, null); |
165 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
170 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
166 | 171 | items.add(new MtasSpanSequenceItem(q1, true)); |
167 | 172 | items.add(new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q2,1,3,null, null), false)); |
168 | 173 | items.add(new MtasSpanSequenceItem(q3, false)); |
... | ... | @@ -198,7 +203,7 @@ public class MtasCQLParserTestSentence { |
198 | 203 | MtasSpanQuery q2 = new MtasCQLParserWordQuery(field,"t","de",null, null); |
199 | 204 | MtasSpanQuery q3 = new MtasCQLParserGroupQuery(field,"sentence"); |
200 | 205 | MtasSpanQuery q4 = new MtasSpanWithinQuery(q3, q2); |
201 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
206 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
202 | 207 | items.add(new MtasSpanSequenceItem(q1, false)); |
203 | 208 | items.add(new MtasSpanSequenceItem(q4, false)); |
204 | 209 | MtasSpanQuery q = new MtasSpanSequenceQuery(items, null, null); |
... | ... | @@ -213,7 +218,7 @@ public class MtasCQLParserTestSentence { |
213 | 218 | MtasSpanQuery q2 = new MtasCQLParserGroupQuery(field,"sentence"); |
214 | 219 | MtasSpanQuery q3 = new MtasSpanWithinQuery(q2, q1); |
215 | 220 | MtasSpanQuery q4 = new MtasCQLParserWordQuery(field,"lemma","koe",null, null); |
216 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
221 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
217 | 222 | items.add(new MtasSpanSequenceItem(q3, false)); |
218 | 223 | items.add(new MtasSpanSequenceItem(q4, false)); |
219 | 224 | MtasSpanQuery q = new MtasSpanSequenceQuery(items, null, null); |
... | ... | @@ -230,12 +235,12 @@ public class MtasCQLParserTestSentence { |
230 | 235 | MtasSpanQuery q4 = new MtasSpanContainingQuery(q2, q3); |
231 | 236 | MtasSpanQuery q5 = new MtasCQLParserGroupQuery(field,"sentence"); |
232 | 237 | MtasSpanQuery q6 = new MtasCQLParserWordQuery(field,"lemma","paard",null, null); |
233 | - List<MtasSpanSequenceItem> items1 = new ArrayList<MtasSpanSequenceItem>(); | |
238 | + List<MtasSpanSequenceItem> items1 = new ArrayList<>(); | |
234 | 239 | items1.add(new MtasSpanSequenceItem(q5, false)); |
235 | 240 | items1.add(new MtasSpanSequenceItem(q6, false)); |
236 | 241 | MtasSpanQuery q7 = new MtasSpanSequenceQuery(items1, null, null); |
237 | 242 | MtasSpanQuery q8 = new MtasSpanWithinQuery(q7, q4); |
238 | - List<MtasSpanSequenceItem> items2 = new ArrayList<MtasSpanSequenceItem>(); | |
243 | + List<MtasSpanSequenceItem> items2 = new ArrayList<>(); | |
239 | 244 | items2.add(new MtasSpanSequenceItem(q1, false)); |
240 | 245 | items2.add(new MtasSpanSequenceItem(q8, false)); |
241 | 246 | MtasSpanQuery q = new MtasSpanSequenceQuery(items2, null, null); |
... | ... | @@ -261,7 +266,7 @@ public class MtasCQLParserTestSentence { |
261 | 266 | String cql = "[]<entity=\"loc\"/>{1,2}[]"; |
262 | 267 | MtasSpanQuery q1 = new MtasCQLParserGroupQuery(field,"entity","loc"); |
263 | 268 | MtasSpanQuery q2 = new MtasSpanRecurrenceQuery(q1,1,2,null, null); |
264 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
269 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
265 | 270 | items.add(new MtasSpanSequenceItem(new MtasSpanMatchAllQuery(field), false)); |
266 | 271 | items.add(new MtasSpanSequenceItem(q2, false)); |
267 | 272 | items.add(new MtasSpanSequenceItem(new MtasSpanMatchAllQuery(field), false)); |
... | ... | @@ -275,7 +280,7 @@ public class MtasCQLParserTestSentence { |
275 | 280 | String cql = "\"de\" [pos=\"N\"]"; |
276 | 281 | MtasSpanQuery q1 = new MtasCQLParserWordQuery(field,"t_lc","de",null, null); |
277 | 282 | MtasSpanQuery q2 = new MtasCQLParserWordQuery(field,"pos","N",null, null); |
278 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
283 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
279 | 284 | items.add(new MtasSpanSequenceItem(q1, false)); |
280 | 285 | items.add(new MtasSpanSequenceItem(q2, false)); |
281 | 286 | MtasSpanQuery q = new MtasSpanSequenceQuery(items, null, null); |
... | ... | @@ -288,7 +293,7 @@ public class MtasCQLParserTestSentence { |
288 | 293 | String cql = "([]<entity=\"loc\"/>{1,2}[]){3,4}"; |
289 | 294 | MtasSpanQuery q1 = new MtasCQLParserGroupQuery(field,"entity","loc"); |
290 | 295 | MtasSpanQuery q2 = new MtasSpanRecurrenceQuery(q1,1,2,null, null); |
291 | - List<MtasSpanSequenceItem> items = new ArrayList<MtasSpanSequenceItem>(); | |
296 | + List<MtasSpanSequenceItem> items = new ArrayList<>(); | |
292 | 297 | items.add(new MtasSpanSequenceItem(new MtasSpanMatchAllQuery(field), false)); |
293 | 298 | items.add(new MtasSpanSequenceItem(q2, false)); |
294 | 299 | items.add(new MtasSpanSequenceItem(new MtasSpanMatchAllQuery(field), false)); |
... | ... |
junit/mtas/parser/MtasCQLParserTestWord.java
... | ... | @@ -5,6 +5,9 @@ import static org.junit.Assert.*; |
5 | 5 | import java.io.BufferedReader; |
6 | 6 | import java.io.StringReader; |
7 | 7 | |
8 | +import org.apache.commons.logging.Log; | |
9 | +import org.apache.commons.logging.LogFactory; | |
10 | + | |
8 | 11 | import mtas.parser.cql.MtasCQLParser; |
9 | 12 | import mtas.parser.cql.ParseException; |
10 | 13 | import mtas.parser.cql.util.MtasCQLParserWordPositionQuery; |
... | ... | @@ -17,14 +20,16 @@ import mtas.search.spans.util.MtasSpanUniquePositionQuery; |
17 | 20 | |
18 | 21 | public class MtasCQLParserTestWord { |
19 | 22 | |
20 | - private void testCQLParse(String field, String defaultPrefix, String cql, MtasSpanQuery q) { | |
23 | + private static Log log = LogFactory.getLog(MtasCQLParserTestWord.class); | |
24 | + | |
25 | + private void testCQLParse(String field, String defaultPrefix, String cql, MtasSpanQuery q) { | |
21 | 26 | MtasCQLParser p = new MtasCQLParser(new BufferedReader(new StringReader(cql))); |
22 | 27 | try { |
23 | 28 | assertEquals(p.parse(field, defaultPrefix, null, null, null) ,q); |
24 | 29 | //System.out.println("Tested CQL parsing:\t"+cql); |
25 | 30 | } catch (ParseException e) { |
26 | 31 | //System.out.println("Error CQL parsing:\t"+cql); |
27 | - e.printStackTrace(); | |
32 | + log.error(e); | |
28 | 33 | } |
29 | 34 | } |
30 | 35 | |
... | ... | @@ -36,7 +41,7 @@ public class MtasCQLParserTestWord { |
36 | 41 | //System.out.println("Tested CQL equivalent:\t"+cql1+" and "+cql2); |
37 | 42 | } catch (ParseException e) { |
38 | 43 | //System.out.println("Error CQL equivalent:\t"+cql1+" and "+cql2); |
39 | - e.printStackTrace(); | |
44 | + log.error(e); | |
40 | 45 | } |
41 | 46 | } |
42 | 47 | |
... | ... |
junit/mtas/parser/MtasFunctionParserTest.java
... | ... | @@ -22,7 +22,7 @@ public class MtasFunctionParserTest { |
22 | 22 | private void testFunction(MtasFunctionParserFunction pf, long[] args, int n, |
23 | 23 | MtasFunctionParserFunctionResponse r) { |
24 | 24 | assertEquals(pf + "\tn:" + n + "\targs:" + Arrays.toString(args), |
25 | - pf.getResponse(args, n), r); | |
25 | + pf.getResponse(args, n), r); | |
26 | 26 | } |
27 | 27 | |
28 | 28 | private long[] getArgs(int n, int min, int max) { |
... | ... | @@ -375,10 +375,6 @@ public class MtasFunctionParserTest { |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | - private Double compute(int op, long v1, double v2) throws IOException { | |
379 | - return compute(op, (double) v1, v2); | |
380 | - } | |
381 | - | |
382 | 378 | private Double compute(int op, double v1, long v2) throws IOException { |
383 | 379 | return compute(op, v1, (double) v2); |
384 | 380 | } |
... | ... |
junit/mtas/search/MtasSearchTestConsistency.java
... | ... | @@ -15,7 +15,11 @@ import java.util.HashMap; |
15 | 15 | import java.util.List; |
16 | 16 | import java.util.ListIterator; |
17 | 17 | import java.util.Map; |
18 | +import java.util.Map.Entry; | |
18 | 19 | import java.util.SortedMap; |
20 | + | |
21 | +import org.apache.commons.logging.Log; | |
22 | +import org.apache.commons.logging.LogFactory; | |
19 | 23 | import org.apache.lucene.analysis.Analyzer; |
20 | 24 | import org.apache.lucene.analysis.custom.CustomAnalyzer; |
21 | 25 | import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; |
... | ... | @@ -59,6 +63,8 @@ import mtas.search.spans.util.MtasSpanQuery; |
59 | 63 | |
60 | 64 | public class MtasSearchTestConsistency { |
61 | 65 | |
66 | + private static Log log = LogFactory.getLog(MtasSearchTestConsistency.class); | |
67 | + | |
62 | 68 | private final static String FIELD_ID = "id"; |
63 | 69 | private final static String FIELD_TITLE = "title"; |
64 | 70 | private final static String FIELD_CONTENT = "content"; |
... | ... | @@ -74,14 +80,14 @@ public class MtasSearchTestConsistency { |
74 | 80 | Path path = Paths.get("junit").resolve("data"); |
75 | 81 | // directory = FSDirectory.open(Paths.get("testindexMtas")); |
76 | 82 | directory = new RAMDirectory(); |
77 | - files = new HashMap<String, String>(); | |
83 | + files = new HashMap<>(); | |
78 | 84 | files.put("Een onaangenaam mens in de Haarlemmerhout", path.resolve("resources").resolve("beets1.xml.gz").toAbsolutePath().toString()); |
79 | 85 | files.put("Een oude kennis", path.resolve("resources").resolve("beets2.xml.gz").toAbsolutePath().toString()); |
80 | 86 | files.put("Varen en Rijden", path.resolve("resources").resolve("beets3.xml.gz").toAbsolutePath().toString()); |
81 | 87 | createIndex(path.resolve("conf").resolve("folia.xml").toAbsolutePath().toString(), files); |
82 | 88 | docs = getLiveDocs(DirectoryReader.open(directory)); |
83 | 89 | } catch (IOException e) { |
84 | - e.printStackTrace(); | |
90 | + log.error(e); | |
85 | 91 | } |
86 | 92 | } |
87 | 93 | |
... | ... | @@ -136,7 +142,7 @@ public class MtasSearchTestConsistency { |
136 | 142 | } |
137 | 143 | |
138 | 144 | @org.junit.Test |
139 | - public void basicSearchIgnore() throws IOException, ParseException { | |
145 | + public void basicSearchIgnore() throws IOException { | |
140 | 146 | int ignoreNumber = 10; |
141 | 147 | String cql1 = "[pos=\"LID\"][pos=\"ADJ\"]{0," + ignoreNumber |
142 | 148 | + "}[pos=\"N\"]"; |
... | ... | @@ -146,7 +152,12 @@ public class MtasSearchTestConsistency { |
146 | 152 | IndexReader indexReader = DirectoryReader.open(directory); |
147 | 153 | QueryResult queryResult1 = doQuery(indexReader, FIELD_CONTENT, cql1, null, |
148 | 154 | null, null); |
149 | - MtasSpanQuery ignore = createQuery(FIELD_CONTENT, cql2ignore, null, null); | |
155 | + MtasSpanQuery ignore; | |
156 | + try { | |
157 | + ignore = createQuery(FIELD_CONTENT, cql2ignore, null, null); | |
158 | + } catch (ParseException e) { | |
159 | + throw new IOException("Parse Exception", e); | |
160 | + } | |
150 | 161 | QueryResult queryResult2 = doQuery(indexReader, FIELD_CONTENT, cql2, ignore, |
151 | 162 | ignoreNumber, null); |
152 | 163 | assertEquals("Article followed by Noun ignoring Adjectives", |
... | ... | @@ -155,7 +166,7 @@ public class MtasSearchTestConsistency { |
155 | 166 | } |
156 | 167 | |
157 | 168 | @org.junit.Test |
158 | - public void basicSearchFollowedBy1() throws IOException, ParseException { | |
169 | + public void basicSearchFollowedBy1() throws IOException { | |
159 | 170 | String cql1 = "[pos=\"LID\"] followedby []?[pos=\"ADJ\"]"; |
160 | 171 | String cql2 = "[pos=\"LID\"][]?[pos=\"ADJ\"]"; |
161 | 172 | String cql3 = "[pos=\"LID\"][pos=\"ADJ\"][pos=\"ADJ\"]"; |
... | ... | @@ -168,12 +179,12 @@ public class MtasSearchTestConsistency { |
168 | 179 | QueryResult queryResult3 = doQuery(indexReader, FIELD_CONTENT, cql3, null, |
169 | 180 | null, null); |
170 | 181 | assertEquals("Article followed by Adjective", |
171 | - queryResult1.hits, queryResult2.hits - queryResult3.hits); | |
182 | + queryResult1.hits, (long) queryResult2.hits - queryResult3.hits); | |
172 | 183 | indexReader.close(); |
173 | 184 | } |
174 | 185 | |
175 | 186 | @org.junit.Test |
176 | - public void basicSearchFollowedBy2() throws IOException, ParseException { | |
187 | + public void basicSearchFollowedBy2() throws IOException { | |
177 | 188 | String cql1 = "[pos=\"LID\"] followedby []?[pos=\"ADJ\"]"; |
178 | 189 | String cql2 = "[pos=\"LID\"][]?[pos=\"ADJ\"]"; |
179 | 190 | String cql3 = "[pos=\"LID\"][pos=\"ADJ\"][pos=\"ADJ\"]"; |
... | ... | @@ -186,12 +197,12 @@ public class MtasSearchTestConsistency { |
186 | 197 | QueryResult queryResult3 = doQuery(indexReader, FIELD_CONTENT, cql3, null, |
187 | 198 | null, null); |
188 | 199 | assertEquals("Article followed by Adjective", |
189 | - queryResult1.hits, queryResult2.hits - queryResult3.hits); | |
200 | + queryResult1.hits, (long) queryResult2.hits - queryResult3.hits); | |
190 | 201 | indexReader.close(); |
191 | 202 | } |
192 | 203 | |
193 | 204 | @org.junit.Test |
194 | - public void basicSearchPrecededBy1() throws IOException, ParseException { | |
205 | + public void basicSearchPrecededBy1() throws IOException { | |
195 | 206 | String cql1 = "[pos=\"ADJ\"] precededby [pos=\"LID\"][]?"; |
196 | 207 | String cql2 = "[pos=\"LID\"][]?[pos=\"ADJ\"]"; |
197 | 208 | String cql3 = "[pos=\"LID\"][pos=\"LID\"][pos=\"ADJ\"]"; |
... | ... | @@ -204,12 +215,12 @@ public class MtasSearchTestConsistency { |
204 | 215 | QueryResult queryResult3 = doQuery(indexReader, FIELD_CONTENT, cql3, null, |
205 | 216 | null, null); |
206 | 217 | assertEquals("Adjective preceded by Article", |
207 | - queryResult1.hits, queryResult2.hits - queryResult3.hits); | |
218 | + queryResult1.hits, (long) queryResult2.hits - queryResult3.hits); | |
208 | 219 | indexReader.close(); |
209 | 220 | } |
210 | 221 | |
211 | 222 | @org.junit.Test |
212 | - public void basicSearchPrecededBy2() throws IOException, ParseException { | |
223 | + public void basicSearchPrecededBy2() throws IOException { | |
213 | 224 | String cql1 = "[]?[pos=\"ADJ\"] precededby [pos=\"LID\"]"; |
214 | 225 | String cql2 = "[pos=\"LID\"][]?[pos=\"ADJ\"]"; |
215 | 226 | // get total number |
... | ... | @@ -230,8 +241,7 @@ public class MtasSearchTestConsistency { |
230 | 241 | QueryResult queryResult = doQuery(indexReader, FIELD_CONTENT, "[]", null, |
231 | 242 | null, null); |
232 | 243 | indexReader.close(); |
233 | - int averageNumberOfPositions = Math | |
234 | - .round(queryResult.hits / queryResult.docs); | |
244 | + int averageNumberOfPositions = queryResult.hits / queryResult.docs; | |
235 | 245 | // do position query |
236 | 246 | try { |
237 | 247 | ArrayList<Integer> fullDocSet = docs; |
... | ... | @@ -243,13 +253,13 @@ public class MtasSearchTestConsistency { |
243 | 253 | "n,sum,mean,min,max")); |
244 | 254 | fieldStats.statsPositionList.add(new ComponentPosition( |
245 | 255 | "maximum", null, (double) averageNumberOfPositions, "sum")); |
246 | - HashMap<String, HashMap<String, Object>> response = doAdvancedSearch( | |
256 | + Map<String, HashMap<String, Object>> response = doAdvancedSearch( | |
247 | 257 | fullDocSet, fieldStats); |
248 | - HashMap<String, Object> responseTotal = (HashMap<String, Object>) response | |
258 | + Map<String, Object> responseTotal = (Map<String, Object>) response | |
249 | 259 | .get("statsPositions").get("total"); |
250 | - HashMap<String, Object> responseMinimum = (HashMap<String, Object>) response | |
260 | + Map<String, Object> responseMinimum = (Map<String, Object>) response | |
251 | 261 | .get("statsPositions").get("minimum"); |
252 | - HashMap<String, Object> responseMaximum = (HashMap<String, Object>) response | |
262 | + Map<String, Object> responseMaximum = (Map<String, Object>) response | |
253 | 263 | .get("statsPositions").get("maximum"); |
254 | 264 | Double total = responseTotal != null ? (Double) responseTotal.get("sum") |
255 | 265 | : 0; |
... | ... | @@ -257,12 +267,12 @@ public class MtasSearchTestConsistency { |
257 | 267 | ? (Long) responseMinimum.get("sum") : 0; |
258 | 268 | Long totalMaximum = responseTotal != null |
259 | 269 | ? (Long) responseMaximum.get("sum") : 0; |
260 | - assertEquals("Number of positions", new Long(total.longValue()), | |
261 | - new Long(queryResult.hits)); | |
270 | + assertEquals("Number of positions", total.longValue(), | |
271 | + queryResult.hits); | |
262 | 272 | assertEquals("Minimum and maximum on number of positions", |
263 | - new Long(total.longValue()), new Long(totalMinimum + totalMaximum)); | |
273 | + total.longValue(), totalMinimum + totalMaximum); | |
264 | 274 | } catch (mtas.parser.function.ParseException e) { |
265 | - e.printStackTrace(); | |
275 | + log.error(e); | |
266 | 276 | } |
267 | 277 | } |
268 | 278 | |
... | ... | @@ -285,9 +295,11 @@ public class MtasSearchTestConsistency { |
285 | 295 | Long maximum = responseTotal != null ? (Long) responseTotal.get("max") |
286 | 296 | : 0; |
287 | 297 | // compute for each doc |
288 | - Long subDocs = Long.valueOf(0), subTotal = Long.valueOf(0), | |
289 | - subMinimum = null, subMaximum = null; | |
290 | - ArrayList<Integer> subDocSet = new ArrayList<Integer>(); | |
298 | + Long subDocs = Long.valueOf(0); | |
299 | + Long subTotal = Long.valueOf(0); | |
300 | + Long subMinimum = null; | |
301 | + Long subMaximum = null; | |
302 | + ArrayList<Integer> subDocSet = new ArrayList<>(); | |
291 | 303 | for (Integer docId : fullDocSet) { |
292 | 304 | subDocSet.add(docId); |
293 | 305 | fieldStats = new ComponentField(FIELD_ID); |
... | ... | @@ -318,7 +330,7 @@ public class MtasSearchTestConsistency { |
318 | 330 | assertEquals("Minimum positions", minimum, subMinimum); |
319 | 331 | assertEquals("Maximum positions", maximum, subMaximum); |
320 | 332 | } catch (mtas.parser.function.ParseException e) { |
321 | - e.printStackTrace(); | |
333 | + log.error(e); | |
322 | 334 | } |
323 | 335 | } |
324 | 336 | |
... | ... | @@ -341,9 +353,11 @@ public class MtasSearchTestConsistency { |
341 | 353 | Long maximum = responseTotal != null ? (Long) responseTotal.get("max") |
342 | 354 | : 0; |
343 | 355 | // compute for each doc |
344 | - Long subDocs = Long.valueOf(0), subTotal = Long.valueOf(0), | |
345 | - subMinimum = null, subMaximum = null; | |
346 | - ArrayList<Integer> subDocSet = new ArrayList<Integer>(); | |
356 | + Long subDocs = Long.valueOf(0); | |
357 | + Long subTotal = Long.valueOf(0); | |
358 | + Long subMinimum = null; | |
359 | + Long subMaximum = null; | |
360 | + ArrayList<Integer> subDocSet = new ArrayList<>(); | |
347 | 361 | for (Integer docId : fullDocSet) { |
348 | 362 | subDocSet.add(docId); |
349 | 363 | fieldStats = new ComponentField(FIELD_ID); |
... | ... | @@ -374,7 +388,7 @@ public class MtasSearchTestConsistency { |
374 | 388 | assertEquals("Minimum positions", minimum, subMinimum); |
375 | 389 | assertEquals("Maximum positions", maximum, subMaximum); |
376 | 390 | } catch (mtas.parser.function.ParseException e) { |
377 | - e.printStackTrace(); | |
391 | + log.error(e); | |
378 | 392 | } |
379 | 393 | } |
380 | 394 | |
... | ... | @@ -392,8 +406,7 @@ public class MtasSearchTestConsistency { |
392 | 406 | QueryResult queryResult3 = doQuery(indexReader, FIELD_CONTENT, cql3, null, |
393 | 407 | null, null); |
394 | 408 | indexReader.close(); |
395 | - int averageNumberOfPositions = Math | |
396 | - .round(queryResult1.hits / queryResult1.docs); | |
409 | + int averageNumberOfPositions = queryResult1.hits / queryResult1.docs; | |
397 | 410 | // do stats query for nouns |
398 | 411 | try { |
399 | 412 | ArrayList<Integer> fullDocSet = docs; |
... | ... | @@ -452,31 +465,32 @@ public class MtasSearchTestConsistency { |
452 | 465 | ? (Long) responseMinimum1.get("sum") : 0; |
453 | 466 | Long totalMaximum1 = responseTotal1 != null |
454 | 467 | ? (Long) responseMaximum1.get("sum") : 0; |
455 | - assertEquals("Number of nouns", new Long(total1.longValue()), | |
456 | - new Long(queryResult1.hits)); | |
457 | - assertEquals("Number of articles", new Long(total2.longValue()), | |
458 | - new Long(queryResult2.hits)); | |
468 | + assertEquals("Number of nouns", total1.longValue(), | |
469 | + queryResult1.hits); | |
470 | + assertEquals("Number of articles", total2.longValue(), | |
471 | + queryResult2.hits); | |
459 | 472 | assertEquals("Number of nouns and articles - external 1", |
460 | - new Long(total12.longValue()), | |
461 | - new Long(queryResult1.hits + queryResult2.hits)); | |
473 | + total12.longValue(), | |
474 | + (long) queryResult1.hits + queryResult2.hits); | |
462 | 475 | assertEquals("Number of nouns and articles - external 2", |
463 | - new Long(total12.longValue()), new Long(queryResult3.hits)); | |
476 | + total12.longValue(), queryResult3.hits); | |
464 | 477 | assertEquals("Number of nouns and articles - internal", |
465 | - new Long(total12.longValue()), new Long(total3.longValue())); | |
478 | + total12.longValue(), total3.longValue()); | |
466 | 479 | assertEquals("Number of nouns and articles - functions", |
467 | - new Long(difference12.longValue()), | |
468 | - new Long(queryResult1.hits - queryResult2.hits)); | |
480 | + difference12.longValue(), | |
481 | + (long) queryResult1.hits - queryResult2.hits); | |
469 | 482 | assertEquals("Minimum and maximum on number of positions nouns", |
470 | - new Long(total1.longValue()), | |
471 | - new Long(totalMinimum1 + totalMaximum1)); | |
483 | + total1.longValue(), | |
484 | + totalMinimum1 + totalMaximum1); | |
472 | 485 | } catch (mtas.parser.function.ParseException | ParseException e) { |
473 | - e.printStackTrace(); | |
486 | + log.error(e); | |
474 | 487 | } |
475 | 488 | } |
476 | 489 | |
477 | 490 | @org.junit.Test |
478 | 491 | public void collectGroup() throws IOException { |
479 | 492 | String cql = "[pos=\"LID\"]"; |
493 | + DirectoryReader indexReader = DirectoryReader.open(directory); | |
480 | 494 | try { |
481 | 495 | ArrayList<Integer> fullDocSet = docs; |
482 | 496 | ComponentField fieldStats = new ComponentField(FIELD_ID); |
... | ... | @@ -490,7 +504,6 @@ public class MtasSearchTestConsistency { |
490 | 504 | fullDocSet, fieldStats); |
491 | 505 | ArrayList<HashMap<String, Object>> list = (ArrayList<HashMap<String, Object>>) response |
492 | 506 | .get("group").get("articles"); |
493 | - DirectoryReader indexReader = DirectoryReader.open(directory); | |
494 | 507 | int subTotal = 0; |
495 | 508 | for (HashMap<String, Object> listItem : list) { |
496 | 509 | HashMap<String, HashMap<Integer, HashMap<String, String>[]>> group = (HashMap<String, HashMap<Integer, HashMap<String, String>[]>>) listItem |
... | ... | @@ -512,7 +525,9 @@ public class MtasSearchTestConsistency { |
512 | 525 | assertEquals("Total number of articles", total, Long.valueOf(subTotal)); |
513 | 526 | indexReader.close(); |
514 | 527 | } catch (ParseException | mtas.parser.function.ParseException e) { |
515 | - e.printStackTrace(); | |
528 | + log.error(e); | |
529 | + } finally { | |
530 | + indexReader.close(); | |
516 | 531 | } |
517 | 532 | } |
518 | 533 | |
... | ... | @@ -520,6 +535,7 @@ public class MtasSearchTestConsistency { |
520 | 535 | public void collectTermvector() throws IOException { |
521 | 536 | String prefix = "t_lc"; |
522 | 537 | Integer number = 100; |
538 | + IndexReader indexReader = DirectoryReader.open(directory); | |
523 | 539 | try { |
524 | 540 | ArrayList<Integer> fullDocSet = docs; |
525 | 541 | ComponentField fieldStats = new ComponentField(FIELD_ID); |
... | ... | @@ -540,18 +556,17 @@ public class MtasSearchTestConsistency { |
540 | 556 | .get("termvector").get("toplist"); |
541 | 557 | Map<String, Object> fullList = (Map<String, Object>) response |
542 | 558 | .get("termvector").get("fulllist"); |
543 | - IndexReader indexReader = DirectoryReader.open(directory); | |
544 | - for (String key : topList.keySet()) { | |
545 | - HashMap<String, Object> responseTopTotal = (HashMap<String, Object>) topList | |
546 | - .get(key); | |
559 | + | |
560 | + for (Entry<String,Object> entry : topList.entrySet()) { | |
561 | + HashMap<String, Object> responseTopTotal = (HashMap<String, Object>) entry.getValue(); | |
547 | 562 | HashMap<String, Object> responseFullTotal = (HashMap<String, Object>) fullList |
548 | - .get(key); | |
563 | + .get(entry.getKey()); | |
549 | 564 | Long topTotal = responseTopTotal != null |
550 | 565 | ? (Long) responseTopTotal.get("sum") : 0; |
551 | 566 | Long subFullTotal = responseFullTotal != null |
552 | 567 | ? (Long) responseFullTotal.get("sum") : 0; |
553 | 568 | // recompute |
554 | - String termBase = prefix + MtasToken.DELIMITER + key; | |
569 | + String termBase = prefix + MtasToken.DELIMITER + entry.getKey(); | |
555 | 570 | MtasSpanQuery q = new MtasSpanRegexpQuery(new Term(FIELD_CONTENT, |
556 | 571 | "\"" + termBase.replace("\"", "\"\\\"\"") + "\"\u0000*"), true); |
557 | 572 | QueryResult queryResult = doQuery(indexReader, FIELD_CONTENT, q, null); |
... | ... | @@ -562,9 +577,8 @@ public class MtasSearchTestConsistency { |
562 | 577 | + " compared with fullItem", topTotal, subFullTotal); |
563 | 578 | } |
564 | 579 | Long fullTotal = Long.valueOf(0); |
565 | - for (String key : fullList.keySet()) { | |
566 | - HashMap<String, Object> responseFullTotal = (HashMap<String, Object>) fullList | |
567 | - .get(key); | |
580 | + for (Entry<String,Object> entry : fullList.entrySet()) { | |
581 | + HashMap<String, Object> responseFullTotal = (HashMap<String, Object>) entry.getValue(); | |
568 | 582 | Long subFullTotal = responseFullTotal != null |
569 | 583 | ? (Long) responseFullTotal.get("sum") : 0; |
570 | 584 | fullTotal += subFullTotal; |
... | ... | @@ -573,18 +587,20 @@ public class MtasSearchTestConsistency { |
573 | 587 | fullTotal); |
574 | 588 | indexReader.close(); |
575 | 589 | } catch (mtas.parser.function.ParseException e) { |
576 | - e.printStackTrace(); | |
590 | + log.error(e); | |
591 | + } finally { | |
592 | + indexReader.close(); | |
577 | 593 | } |
578 | 594 | } |
579 | 595 | |
580 | 596 | private HashMap<String, HashMap<String, Object>> doAdvancedSearch( |
581 | 597 | ArrayList<Integer> fullDocSet, ComponentField fieldStats) { |
582 | - HashMap<String, HashMap<String, Object>> response = new HashMap<String, HashMap<String, Object>>(); | |
598 | + HashMap<String, HashMap<String, Object>> response = new HashMap<>(); | |
583 | 599 | IndexReader indexReader; |
584 | 600 | try { |
585 | 601 | indexReader = DirectoryReader.open(directory); |
586 | 602 | IndexSearcher searcher = new IndexSearcher(indexReader); |
587 | - ArrayList<Integer> fullDocList = new ArrayList<Integer>(); | |
603 | + ArrayList<Integer> fullDocList = new ArrayList<>(); | |
588 | 604 | CodecUtil.collectField(FIELD_CONTENT, searcher, indexReader, fullDocList, |
589 | 605 | fullDocSet, fieldStats); |
590 | 606 | // add stats - position |
... | ... | @@ -603,7 +619,7 @@ public class MtasSearchTestConsistency { |
603 | 619 | for (ComponentSpan cs : fieldStats.statsSpanList) { |
604 | 620 | response.get("statsSpans").put(cs.key, |
605 | 621 | cs.dataCollector.getResult().getData().rewrite(false)); |
606 | - HashMap<String, Object> functions = new HashMap<String, Object>(); | |
622 | + HashMap<String, Object> functions = new HashMap<>(); | |
607 | 623 | response.get("statsSpansFunctions").put(cs.key, functions); |
608 | 624 | for (SubComponentFunction scf : cs.functions) { |
609 | 625 | functions.put(scf.key, |
... | ... | @@ -613,33 +629,32 @@ public class MtasSearchTestConsistency { |
613 | 629 | response.put("group", new HashMap<String, Object>()); |
614 | 630 | for (ComponentGroup cg : fieldStats.groupList) { |
615 | 631 | SortedMap<String, ?> list = cg.dataCollector.getResult().getList(); |
616 | - ArrayList<HashMap<String, Object>> groupList = new ArrayList<HashMap<String, Object>>(); | |
617 | - for (String key : list.keySet()) { | |
618 | - HashMap<String, Object> subList = new HashMap<String, Object>(); | |
632 | + ArrayList<HashMap<String, Object>> groupList = new ArrayList<>(); | |
633 | + for (Entry<String,?> entry : list.entrySet()) { | |
634 | + HashMap<String, Object> subList = new HashMap<>(); | |
619 | 635 | StringBuilder newKey = new StringBuilder(""); |
620 | - subList.put("group", GroupHit.keyToObject(key, newKey)); | |
636 | + subList.put("group", GroupHit.keyToObject(entry.getKey(), newKey)); | |
621 | 637 | subList.put("key", newKey.toString().trim()); |
622 | - subList.putAll(((MtasDataItem<?, ?>) list.get(key)).rewrite(false)); | |
638 | + subList.putAll(((MtasDataItem<?, ?>) entry.getValue()).rewrite(false)); | |
623 | 639 | groupList.add(subList); |
624 | 640 | } |
625 | 641 | response.get("group").put(cg.key, groupList); |
626 | 642 | } |
627 | 643 | response.put("termvector", new HashMap<String, Object>()); |
628 | 644 | for (ComponentTermVector ct : fieldStats.termVectorList) { |
629 | - HashMap<String, Map<String, Object>> tvList = new HashMap<String, Map<String, Object>>(); | |
645 | + HashMap<String, Map<String, Object>> tvList = new HashMap<>(); | |
630 | 646 | Map<String, ?> tcList = ct.subComponentFunction.dataCollector |
631 | 647 | .getResult().getList(); |
632 | - for (String key : tcList.keySet()) { | |
633 | - tvList.put(key, | |
634 | - ((MtasDataItem<?, ?>) tcList.get(key)).rewrite(false)); | |
648 | + for (Entry<String,?> entry : tcList.entrySet()) { | |
649 | + tvList.put(entry.getKey(), | |
650 | + ((MtasDataItem<?, ?>) entry.getValue()).rewrite(false)); | |
635 | 651 | } |
636 | 652 | response.get("termvector").put(ct.key, tvList); |
637 | 653 | } |
638 | 654 | indexReader.close(); |
639 | 655 | } catch (IOException | IllegalAccessException | IllegalArgumentException |
640 | 656 | | InvocationTargetException e) { |
641 | - // TODO Auto-generated catch block | |
642 | - e.printStackTrace(); | |
657 | + log.error(e); | |
643 | 658 | } |
644 | 659 | return response; |
645 | 660 | } |
... | ... | @@ -647,15 +662,15 @@ public class MtasSearchTestConsistency { |
647 | 662 | private static void createIndex(String configFile, |
648 | 663 | HashMap<String, String> files) throws IOException { |
649 | 664 | // analyzer |
650 | - Map<String, String> paramsCharFilterMtas = new HashMap<String, String>(); | |
665 | + Map<String, String> paramsCharFilterMtas = new HashMap<>(); | |
651 | 666 | paramsCharFilterMtas.put("type", "file"); |
652 | - Map<String, String> paramsTokenizer = new HashMap<String, String>(); | |
667 | + Map<String, String> paramsTokenizer = new HashMap<>(); | |
653 | 668 | paramsTokenizer.put("configFile", configFile); |
654 | 669 | Analyzer mtasAnalyzer = CustomAnalyzer |
655 | 670 | .builder(Paths.get("docker").toAbsolutePath()) |
656 | 671 | .addCharFilter("mtas", paramsCharFilterMtas) |
657 | 672 | .withTokenizer("mtas", paramsTokenizer).build(); |
658 | - Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>(); | |
673 | + Map<String, Analyzer> analyzerPerField = new HashMap<>(); | |
659 | 674 | analyzerPerField.put(FIELD_CONTENT, mtasAnalyzer); |
660 | 675 | PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper( |
661 | 676 | new StandardAnalyzer(), analyzerPerField); |
... | ... | @@ -668,19 +683,19 @@ public class MtasSearchTestConsistency { |
668 | 683 | w.deleteAll(); |
669 | 684 | // add |
670 | 685 | int counter = 0; |
671 | - for (String title : files.keySet()) { | |
672 | - addDoc(w, counter, title, files.get(title)); | |
686 | + for (Entry<String,String> entry : files.entrySet()) { | |
687 | + addDoc(w, counter, entry.getKey(), entry.getValue()); | |
673 | 688 | if (counter == 0) { |
674 | 689 | w.commit(); |
675 | 690 | } else { |
676 | - addDoc(w, counter, title, files.get(title)); | |
677 | - addDoc(w, counter, "deletable", files.get(title)); | |
691 | + addDoc(w, counter, entry.getKey(), entry.getValue()); | |
692 | + addDoc(w, counter, "deletable", entry.getValue()); | |
678 | 693 | w.commit(); |
679 | 694 | w.deleteDocuments( |
680 | - new Term(FIELD_ID, Integer.valueOf(counter).toString())); | |
695 | + new Term(FIELD_ID, Integer.toString(counter))); | |
681 | 696 | w.deleteDocuments( |
682 | 697 | new Term(FIELD_TITLE, "deletable")); |
683 | - addDoc(w, counter, title, files.get(title)); | |
698 | + addDoc(w, counter, entry.getKey(), entry.getValue()); | |
684 | 699 | } |
685 | 700 | counter++; |
686 | 701 | } |
... | ... | @@ -698,13 +713,12 @@ public class MtasSearchTestConsistency { |
698 | 713 | doc.add(new TextField(FIELD_CONTENT, file, Field.Store.YES)); |
699 | 714 | w.addDocument(doc); |
700 | 715 | } catch (Exception e) { |
701 | - System.out.println("Couldn't add " + title + " (" + file + ")"); | |
702 | - e.printStackTrace(); | |
716 | + log.error("Couldn't add " + title + " (" + file + ")", e); | |
703 | 717 | } |
704 | 718 | } |
705 | 719 | |
706 | 720 | private static ArrayList<Integer> getLiveDocs(IndexReader indexReader) { |
707 | - ArrayList<Integer> list = new ArrayList<Integer>(); | |
721 | + ArrayList<Integer> list = new ArrayList<>(); | |
708 | 722 | ListIterator<LeafReaderContext> iterator = indexReader.leaves() |
709 | 723 | .listIterator(); |
710 | 724 | while (iterator.hasNext()) { |
... | ... | @@ -734,7 +748,7 @@ public class MtasSearchTestConsistency { |
734 | 748 | MtasSpanQuery q = createQuery(field, cql, ignore, maximumIgnoreLength); |
735 | 749 | queryResult = doQuery(indexReader, field, q, prefixes); |
736 | 750 | } catch (mtas.parser.cql.ParseException e) { |
737 | - e.printStackTrace(); | |
751 | + log.error(e); | |
738 | 752 | } |
739 | 753 | return queryResult; |
740 | 754 | } |
... | ... | @@ -742,11 +756,10 @@ public class MtasSearchTestConsistency { |
742 | 756 | private QueryResult doQuery(IndexReader indexReader, String field, |
743 | 757 | MtasSpanQuery q, ArrayList<String> prefixes) throws IOException { |
744 | 758 | QueryResult queryResult = new QueryResult(); |
745 | - queryResult.query = q.toString(field); | |
746 | 759 | ListIterator<LeafReaderContext> iterator = indexReader.leaves() |
747 | 760 | .listIterator(); |
748 | 761 | IndexSearcher searcher = new IndexSearcher(indexReader); |
749 | - SpanWeight spanweight = ((MtasSpanQuery) q.rewrite(indexReader)) | |
762 | + SpanWeight spanweight = q.rewrite(indexReader) | |
750 | 763 | .createWeight(searcher, false); |
751 | 764 | |
752 | 765 | while (iterator.hasNext()) { |
... | ... | @@ -761,7 +774,7 @@ public class MtasSearchTestConsistency { |
761 | 774 | queryResult.docs++; |
762 | 775 | while (spans.nextStartPosition() != Spans.NO_MORE_POSITIONS) { |
763 | 776 | queryResult.hits++; |
764 | - if (prefixes != null && prefixes.size() > 0) { | |
777 | + if (prefixes != null && !prefixes.isEmpty()) { | |
765 | 778 | ArrayList<MtasTreeHit<String>> terms = mtasCodecInfo |
766 | 779 | .getPositionedTermsByPrefixesAndPositionRange(field, |
767 | 780 | spans.docID(), prefixes, spans.startPosition(), |
... | ... | @@ -778,13 +791,13 @@ public class MtasSearchTestConsistency { |
778 | 791 | } |
779 | 792 | } |
780 | 793 | } |
781 | - | |
782 | 794 | return queryResult; |
783 | 795 | } |
784 | 796 | |
785 | 797 | private void testNumberOfHits(IndexReader indexReader, String field, |
786 | 798 | List<String> cqls1, List<String> cqls2) throws IOException { |
787 | - Integer sum1 = 0, sum2 = 0; | |
799 | + Integer sum1 = 0; | |
800 | + Integer sum2 = 0; | |
788 | 801 | QueryResult queryResult; |
789 | 802 | for (String cql1 : cqls1) { |
790 | 803 | queryResult = doQuery(indexReader, field, cql1, null, null, null); |
... | ... | @@ -797,9 +810,8 @@ public class MtasSearchTestConsistency { |
797 | 810 | assertEquals(sum1, sum2); |
798 | 811 | } |
799 | 812 | |
800 | - public class QueryResult { | |
813 | + private static class QueryResult { | |
801 | 814 | |
802 | - public String query; | |
803 | 815 | public int docs; |
804 | 816 | public int hits; |
805 | 817 | public List<QueryHit> resultList; |
... | ... | @@ -807,7 +819,7 @@ public class MtasSearchTestConsistency { |
807 | 819 | public QueryResult() { |
808 | 820 | docs = 0; |
809 | 821 | hits = 0; |
810 | - resultList = new ArrayList<QueryHit>(); | |
822 | + resultList = new ArrayList<>(); | |
811 | 823 | } |
812 | 824 | |
813 | 825 | @Override |
... | ... | @@ -829,20 +841,20 @@ public class MtasSearchTestConsistency { |
829 | 841 | QueryResult other = (QueryResult) obj; |
830 | 842 | return other.hits == hits && other.docs == docs; |
831 | 843 | } |
844 | + | |
845 | + @Override | |
846 | + public int hashCode() { | |
847 | + int h = this.getClass().getSimpleName().hashCode(); | |
848 | + h = (h * 5) ^ docs; | |
849 | + h = (h * 7) ^ hits; | |
850 | + return h; | |
851 | + } | |
832 | 852 | |
833 | 853 | } |
834 | 854 | |
835 | - public class QueryHit { | |
836 | - int docId, startposition, endPosition; | |
837 | - String prefix, value; | |
838 | - | |
839 | - public QueryHit(int docId, int startPosition, int endPosition, | |
840 | - String prefix, String value) { | |
841 | - this.docId = docId; | |
842 | - this.startposition = startPosition; | |
843 | - this.endPosition = endPosition; | |
844 | - this.prefix = prefix; | |
845 | - this.value = value; | |
855 | + private static class QueryHit { | |
856 | + protected QueryHit(int docId, int startPosition, int endPosition, | |
857 | + String prefix, String value) { | |
846 | 858 | } |
847 | 859 | } |
848 | 860 | |
... | ... |
junit/mtas/solr/MtasSolrBase.java
... | ... | @@ -7,39 +7,66 @@ import java.nio.file.Path; |
7 | 7 | import java.nio.file.Paths; |
8 | 8 | import java.util.ArrayList; |
9 | 9 | import java.util.HashMap; |
10 | +import java.util.Map; | |
10 | 11 | |
12 | +import org.apache.commons.logging.Log; | |
13 | +import org.apache.commons.logging.LogFactory; | |
11 | 14 | import org.apache.solr.common.SolrInputDocument; |
12 | 15 | import org.apache.solr.common.util.NamedList; |
13 | 16 | |
14 | 17 | public class MtasSolrBase { |
15 | - | |
16 | - public static Number getFromMtasStats(NamedList<Object> response, String type, String key, String name) { | |
17 | - assertFalse("no (valid) response", response==null || !(response instanceof NamedList)); | |
18 | - NamedList<Object> mtasResponse = (NamedList<Object>) response.get("mtas"); | |
19 | - assertFalse("no (valid) mtas response", mtasResponse==null || !(mtasResponse.get("stats") instanceof NamedList)); | |
20 | - NamedList<Object> mtasStatsResponse = (NamedList<Object>) mtasResponse.get("stats"); | |
21 | - assertFalse("no (valid) mtas stats response", mtasStatsResponse==null || !(mtasStatsResponse.get(type) instanceof ArrayList)); | |
22 | - ArrayList<NamedList> mtasStatsTypeResponse = (ArrayList<NamedList>) mtasStatsResponse.get(type); | |
23 | - assertFalse("no (valid) mtas stats "+type+" response", mtasStatsTypeResponse==null || mtasStatsTypeResponse.isEmpty()); | |
24 | - NamedList<Object> item = null; | |
25 | - for(NamedList<Object> mtasStatsSpansResponseItem : mtasStatsTypeResponse) { | |
26 | - if(mtasStatsSpansResponseItem.get("key")!=null && (mtasStatsSpansResponseItem.get("key") instanceof String)) { | |
27 | - if(mtasStatsSpansResponseItem.get("key").equals(key)) { | |
28 | - item = mtasStatsSpansResponseItem; | |
29 | - break; | |
30 | - } | |
31 | - } | |
32 | - } | |
33 | - assertFalse("no item with key "+key, item==null); | |
34 | - assertFalse("no variable "+name, item.get(name)==null); | |
35 | - assertFalse("variable "+name+" is "+item.get(name).getClass(), !(item.get(name) instanceof Long) && !(item.get(name) instanceof Double)); | |
36 | - if(item.get(name) instanceof Long) { | |
37 | - return (Long) item.get(name); | |
18 | + | |
19 | + private MtasSolrBase() { | |
20 | + // do nothing | |
21 | + } | |
22 | + | |
23 | + private static Log log = LogFactory.getLog(MtasSolrBase.class); | |
24 | + | |
25 | + public static Number getFromMtasStats(NamedList<Object> response, String type, | |
26 | + String key, String name) { | |
27 | + if (response == null) { | |
28 | + log.error("no (valid); response"); | |
38 | 29 | } else { |
39 | - return (Double) item.get(name); | |
30 | + NamedList<Object> mtasResponse = (NamedList<Object>) response.get("mtas"); | |
31 | + if (mtasResponse == null | |
32 | + || !(mtasResponse.get("stats") instanceof NamedList)) { | |
33 | + log.error("no (valid) mtas response"); | |
34 | + } else { | |
35 | + NamedList<Object> mtasStatsResponse = (NamedList<Object>) mtasResponse | |
36 | + .get("stats"); | |
37 | + if (mtasStatsResponse == null | |
38 | + || !(mtasStatsResponse.get(type) instanceof ArrayList)) { | |
39 | + log.error("no (valid) mtas stats response"); | |
40 | + } else { | |
41 | + ArrayList<NamedList> mtasStatsTypeResponse = (ArrayList<NamedList>) mtasStatsResponse | |
42 | + .get(type); | |
43 | + if (mtasStatsTypeResponse == null || mtasStatsTypeResponse.isEmpty()) { | |
44 | + log.error("no (valid) mtas stats " + type + " response"); | |
45 | + } else { | |
46 | + NamedList<Object> item = null; | |
47 | + for (NamedList<Object> mtasStatsSpansResponseItem : mtasStatsTypeResponse) { | |
48 | + if (mtasStatsSpansResponseItem.get("key") != null | |
49 | + && (mtasStatsSpansResponseItem.get("key") instanceof String) | |
50 | + && mtasStatsSpansResponseItem.get("key").equals(key)) { | |
51 | + item = mtasStatsSpansResponseItem; | |
52 | + break; | |
53 | + } | |
54 | + } | |
55 | + assertFalse("no item with key " + key, item == null); | |
56 | + assertFalse("no variable " + name, | |
57 | + item != null && item.get(name) == null); | |
58 | + if (item != null && item.get(name) instanceof Long) { | |
59 | + return (Long) item.get(name); | |
60 | + } else if (item != null) { | |
61 | + return (Double) item.get(name); | |
62 | + } | |
63 | + } | |
64 | + } | |
65 | + } | |
40 | 66 | } |
67 | + return null; | |
41 | 68 | } |
42 | - | |
69 | + | |
43 | 70 | public static boolean deleteDirectory(File directory) { |
44 | 71 | if (directory.exists()) { |
45 | 72 | File[] files = directory.listFiles(); |
... | ... | @@ -47,19 +74,18 @@ public class MtasSolrBase { |
47 | 74 | for (int i = 0; i < files.length; i++) { |
48 | 75 | if (files[i].isDirectory()) { |
49 | 76 | deleteDirectory(files[i]); |
50 | - } else { | |
51 | - files[i].delete(); | |
77 | + } else if (!files[i].delete()) { | |
78 | + log.info("can't delete " + files[i]); | |
52 | 79 | } |
53 | 80 | } |
54 | 81 | } |
55 | 82 | } |
56 | 83 | return (directory.delete()); |
57 | 84 | } |
58 | - | |
59 | - public static HashMap<Integer, SolrInputDocument> createDocuments() { | |
60 | - HashMap<Integer, SolrInputDocument> solrDocuments = new HashMap<>(); | |
85 | + | |
86 | + public static Map<Integer, SolrInputDocument> createDocuments() { | |
87 | + Map<Integer, SolrInputDocument> solrDocuments = new HashMap<>(); | |
61 | 88 | Path dataPath = Paths.get("junit").resolve("data"); |
62 | - solrDocuments = new HashMap<Integer, SolrInputDocument>(); | |
63 | 89 | // data |
64 | 90 | SolrInputDocument newDoc1 = new SolrInputDocument(); |
65 | 91 | newDoc1.addField("id", "1"); |
... | ... | @@ -85,6 +111,4 @@ public class MtasSolrBase { |
85 | 111 | return solrDocuments; |
86 | 112 | } |
87 | 113 | |
88 | - | |
89 | - | |
90 | 114 | } |
... | ... |
junit/mtas/solr/MtasSolrTestDistributedSearchConsistency.java
... | ... | @@ -8,6 +8,10 @@ import java.io.IOException; |
8 | 8 | import java.nio.file.Path; |
9 | 9 | import java.nio.file.Paths; |
10 | 10 | import java.util.HashMap; |
11 | +import java.util.Map; | |
12 | + | |
13 | +import org.apache.commons.logging.Log; | |
14 | +import org.apache.commons.logging.LogFactory; | |
11 | 15 | import org.apache.solr.client.solrj.SolrServerException; |
12 | 16 | import org.apache.solr.client.solrj.embedded.JettyConfig; |
13 | 17 | import org.apache.solr.client.solrj.impl.CloudSolrClient; |
... | ... | @@ -23,30 +27,59 @@ import org.apache.solr.common.params.ModifiableSolrParams; |
23 | 27 | import org.apache.solr.common.util.NamedList; |
24 | 28 | import com.google.common.io.Files; |
25 | 29 | |
30 | +/** | |
31 | + * The Class MtasSolrTestDistributedSearchConsistency. | |
32 | + */ | |
26 | 33 | public class MtasSolrTestDistributedSearchConsistency { |
27 | 34 | |
35 | + /** The log. */ | |
36 | + private static Log log = LogFactory | |
37 | + .getLog(MtasSolrTestDistributedSearchConsistency.class); | |
38 | + | |
39 | + /** The Constant COLLECTION_ALL_OPTIMIZED. */ | |
28 | 40 | private static final String COLLECTION_ALL_OPTIMIZED = "collection1"; |
41 | + | |
42 | + /** The Constant COLLECTION_ALL_MULTIPLE_SEGMENTS. */ | |
29 | 43 | private static final String COLLECTION_ALL_MULTIPLE_SEGMENTS = "collection2"; |
44 | + | |
45 | + /** The Constant COLLECTION_PART1_OPTIMIZED. */ | |
30 | 46 | private static final String COLLECTION_PART1_OPTIMIZED = "collection3"; |
47 | + | |
48 | + /** The Constant COLLECTION_PART2_MULTIPLE_SEGMENTS. */ | |
31 | 49 | private static final String COLLECTION_PART2_MULTIPLE_SEGMENTS = "collection4"; |
50 | + | |
51 | + /** The Constant COLLECTION_DISTRIBUTED. */ | |
32 | 52 | private static final String COLLECTION_DISTRIBUTED = "collection5"; |
33 | 53 | |
54 | + /** The cloud cluster. */ | |
34 | 55 | private static MiniSolrCloudCluster cloudCluster; |
56 | + | |
57 | + /** The cloud base dir. */ | |
35 | 58 | private static Path cloudBaseDir; |
36 | 59 | |
37 | - private static HashMap<Integer, SolrInputDocument> solrDocuments; | |
60 | + /** The solr documents. */ | |
61 | + private static Map<Integer, SolrInputDocument> solrDocuments; | |
38 | 62 | |
63 | + /** | |
64 | + * Setup. | |
65 | + */ | |
39 | 66 | @org.junit.BeforeClass |
40 | 67 | public static void setup() { |
41 | 68 | solrDocuments = MtasSolrBase.createDocuments(); |
42 | 69 | createCloud(); |
43 | 70 | } |
44 | 71 | |
72 | + /** | |
73 | + * Shutdown. | |
74 | + */ | |
45 | 75 | @org.junit.AfterClass |
46 | 76 | public static void shutdown() { |
47 | 77 | shutdownCloud(); |
48 | 78 | } |
49 | 79 | |
80 | + /** | |
81 | + * Cql query parser. | |
82 | + */ | |
50 | 83 | @org.junit.Test |
51 | 84 | public void cqlQueryParser() { |
52 | 85 | ModifiableSolrParams params = new ModifiableSolrParams(); |
... | ... | @@ -62,6 +95,9 @@ public class MtasSolrTestDistributedSearchConsistency { |
62 | 95 | list.get(COLLECTION_DISTRIBUTED).getResults().size()); |
63 | 96 | } |
64 | 97 | |
98 | + /** | |
99 | + * Cql query parser filter. | |
100 | + */ | |
65 | 101 | @org.junit.Test |
66 | 102 | public void cqlQueryParserFilter() { |
67 | 103 | ModifiableSolrParams params = new ModifiableSolrParams(); |
... | ... | @@ -77,9 +113,13 @@ public class MtasSolrTestDistributedSearchConsistency { |
77 | 113 | list.get(COLLECTION_DISTRIBUTED).getResults().size()); |
78 | 114 | } |
79 | 115 | |
116 | + /** | |
117 | + * Mtas request handler stats tokens. | |
118 | + * | |
119 | + * @throws IOException Signals that an I/O exception has occurred. | |
120 | + */ | |
80 | 121 | @org.junit.Test |
81 | - public void mtasRequestHandlerStatsTokens() | |
82 | - throws SolrServerException, IOException { | |
122 | + public void mtasRequestHandlerStatsTokens() throws IOException { | |
83 | 123 | ModifiableSolrParams params = new ModifiableSolrParams(); |
84 | 124 | String[] types = new String[] { "n", "sum", "mean", "min", "max" }; |
85 | 125 | params.set("q", "*:*"); |
... | ... | @@ -96,9 +136,13 @@ public class MtasSolrTestDistributedSearchConsistency { |
96 | 136 | "statsKey", types); |
97 | 137 | } |
98 | 138 | |
139 | + /** | |
140 | + * Mtas request handler stats positions. | |
141 | + * | |
142 | + * @throws IOException Signals that an I/O exception has occurred. | |
143 | + */ | |
99 | 144 | @org.junit.Test |
100 | - public void mtasRequestHandlerStatsPositions() | |
101 | - throws SolrServerException, IOException { | |
145 | + public void mtasRequestHandlerStatsPositions() throws IOException { | |
102 | 146 | ModifiableSolrParams params = new ModifiableSolrParams(); |
103 | 147 | String[] types = new String[] { "n", "sum", "mean", "min", "max" }; |
104 | 148 | params.set("q", "*:*"); |
... | ... | @@ -115,9 +159,13 @@ public class MtasSolrTestDistributedSearchConsistency { |
115 | 159 | "statsKey", types); |
116 | 160 | } |
117 | 161 | |
162 | + /** | |
163 | + * Mtas request handler stats spans. | |
164 | + * | |
165 | + * @throws IOException Signals that an I/O exception has occurred. | |
166 | + */ | |
118 | 167 | @org.junit.Test |
119 | - public void mtasRequestHandlerStatsSpans() | |
120 | - throws SolrServerException, IOException { | |
168 | + public void mtasRequestHandlerStatsSpans() throws IOException { | |
121 | 169 | ModifiableSolrParams params = new ModifiableSolrParams(); |
122 | 170 | String[] types = new String[] { "n", "sum", "mean", "min", "max" }; |
123 | 171 | params.set("q", "*:*"); |
... | ... | @@ -136,9 +184,15 @@ public class MtasSolrTestDistributedSearchConsistency { |
136 | 184 | "statsKey", types); |
137 | 185 | } |
138 | 186 | |
187 | + /** | |
188 | + * Creates the results. | |
189 | + * | |
190 | + * @param params the params | |
191 | + * @return the hash map | |
192 | + */ | |
139 | 193 | private static HashMap<String, QueryResponse> createResults( |
140 | 194 | final ModifiableSolrParams params) { |
141 | - HashMap<String, QueryResponse> list = new HashMap<String, QueryResponse>(); | |
195 | + HashMap<String, QueryResponse> list = new HashMap<>(); | |
142 | 196 | CloudSolrClient client = cloudCluster.getSolrClient(); |
143 | 197 | try { |
144 | 198 | list.put(COLLECTION_ALL_OPTIMIZED, |
... | ... | @@ -154,21 +208,40 @@ public class MtasSolrTestDistributedSearchConsistency { |
154 | 208 | list.put(COLLECTION_DISTRIBUTED, |
155 | 209 | client.query(COLLECTION_DISTRIBUTED, params)); |
156 | 210 | } catch (SolrServerException | IOException e) { |
157 | - e.printStackTrace(); | |
211 | + log.error(e); | |
158 | 212 | } |
159 | 213 | return list; |
160 | 214 | } |
161 | 215 | |
216 | + /** | |
217 | + * Creates the stats assertions. | |
218 | + * | |
219 | + * @param response1 the response 1 | |
220 | + * @param response2 the response 2 | |
221 | + * @param type the type | |
222 | + * @param key the key | |
223 | + * @param names the names | |
224 | + */ | |
162 | 225 | private static void createStatsAssertions(NamedList<Object> response1, |
163 | 226 | NamedList<Object> response2, String type, String key, String[] names) { |
164 | 227 | NamedList<Object>[] responses2 = new NamedList[] { response2 }; |
165 | 228 | createStatsAssertions(response1, responses2, type, key, names); |
166 | 229 | } |
167 | 230 | |
231 | + /** | |
232 | + * Creates the stats assertions. | |
233 | + * | |
234 | + * @param response1 the response 1 | |
235 | + * @param responses2 the responses 2 | |
236 | + * @param type the type | |
237 | + * @param key the key | |
238 | + * @param names the names | |
239 | + */ | |
168 | 240 | private static void createStatsAssertions(NamedList<Object> response1, |
169 | 241 | NamedList<Object>[] responses2, String type, String key, String[] names) { |
170 | - for (String name : names) { | |
171 | - assertFalse("no "+type+" - "+name, MtasSolrBase.getFromMtasStats(response1, type, key, name).equals(0)); | |
242 | + for (String name : names) { | |
243 | + assertFalse("no " + type + " - " + name, | |
244 | + MtasSolrBase.getFromMtasStats(response1, type, key, name).equals(0)); | |
172 | 245 | for (NamedList<Object> response2 : responses2) { |
173 | 246 | assertEquals(MtasSolrBase.getFromMtasStats(response1, type, key, name), |
174 | 247 | MtasSolrBase.getFromMtasStats(response2, type, key, name)); |
... | ... | @@ -176,59 +249,72 @@ public class MtasSolrTestDistributedSearchConsistency { |
176 | 249 | } |
177 | 250 | } |
178 | 251 | |
252 | + /** | |
253 | + * Creates the cloud. | |
254 | + */ | |
179 | 255 | private static void createCloud() { |
180 | 256 | Path dataPath = Paths.get("junit").resolve("data"); |
181 | 257 | String solrxml = MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML; |
182 | 258 | JettyConfig jettyConfig = JettyConfig.builder().setContext("/solr").build(); |
183 | - File cloudBase = Files.createTempDir(); | |
259 | + File cloudBase = Files.createTempDir(); | |
184 | 260 | cloudBaseDir = cloudBase.toPath(); |
185 | - //create subdirectories | |
261 | + // create subdirectories | |
186 | 262 | Path clusterDir = cloudBaseDir.resolve("cluster"); |
187 | 263 | Path logDir = cloudBaseDir.resolve("log"); |
188 | - clusterDir.toFile().mkdir(); | |
189 | - logDir.toFile().mkdir(); | |
190 | - //set log directory | |
191 | - System.setProperty("solr.log.dir", logDir.toAbsolutePath().toString()); | |
192 | - try { | |
193 | - cloudCluster = new MiniSolrCloudCluster(1, clusterDir, solrxml, | |
194 | - jettyConfig); | |
195 | - CloudSolrClient client = cloudCluster.getSolrClient(); | |
196 | - client.connect(); | |
197 | - createCloudCollection(COLLECTION_ALL_OPTIMIZED, 1, 1, | |
198 | - dataPath.resolve("conf")); | |
199 | - createCloudCollection(COLLECTION_ALL_MULTIPLE_SEGMENTS, 1, 1, | |
200 | - dataPath.resolve("conf")); | |
201 | - createCloudCollection(COLLECTION_PART1_OPTIMIZED, 1, 1, | |
202 | - dataPath.resolve("conf")); | |
203 | - createCloudCollection(COLLECTION_PART2_MULTIPLE_SEGMENTS, 1, 1, | |
204 | - dataPath.resolve("conf")); | |
205 | - createCloudCollection(COLLECTION_DISTRIBUTED, 1, 1, | |
206 | - dataPath.resolve("conf")); | |
264 | + if (clusterDir.toFile().mkdir() && logDir.toFile().mkdir()) { | |
265 | + // set log directory | |
266 | + System.setProperty("solr.log.dir", logDir.toAbsolutePath().toString()); | |
267 | + try { | |
268 | + cloudCluster = new MiniSolrCloudCluster(1, clusterDir, solrxml, | |
269 | + jettyConfig); | |
270 | + CloudSolrClient client = cloudCluster.getSolrClient(); | |
271 | + client.connect(); | |
272 | + createCloudCollection(COLLECTION_ALL_OPTIMIZED, 1, 1, | |
273 | + dataPath.resolve("conf")); | |
274 | + createCloudCollection(COLLECTION_ALL_MULTIPLE_SEGMENTS, 1, 1, | |
275 | + dataPath.resolve("conf")); | |
276 | + createCloudCollection(COLLECTION_PART1_OPTIMIZED, 1, 1, | |
277 | + dataPath.resolve("conf")); | |
278 | + createCloudCollection(COLLECTION_PART2_MULTIPLE_SEGMENTS, 1, 1, | |
279 | + dataPath.resolve("conf")); | |
280 | + createCloudCollection(COLLECTION_DISTRIBUTED, 1, 1, | |
281 | + dataPath.resolve("conf")); | |
207 | 282 | |
208 | - // collection1 | |
209 | - client.add(COLLECTION_ALL_OPTIMIZED, solrDocuments.get(1)); | |
210 | - client.add(COLLECTION_ALL_OPTIMIZED, solrDocuments.get(2)); | |
211 | - client.add(COLLECTION_ALL_OPTIMIZED, solrDocuments.get(3)); | |
212 | - client.commit(COLLECTION_ALL_OPTIMIZED); | |
213 | - // collection2 | |
214 | - client.add(COLLECTION_ALL_MULTIPLE_SEGMENTS, solrDocuments.get(1)); | |
215 | - client.commit(COLLECTION_ALL_MULTIPLE_SEGMENTS); | |
216 | - client.add(COLLECTION_ALL_MULTIPLE_SEGMENTS, solrDocuments.get(2)); | |
217 | - client.add(COLLECTION_ALL_MULTIPLE_SEGMENTS, solrDocuments.get(3)); | |
218 | - client.commit(COLLECTION_ALL_MULTIPLE_SEGMENTS); | |
219 | - // collection3 | |
220 | - client.add(COLLECTION_PART1_OPTIMIZED, solrDocuments.get(1)); | |
221 | - client.commit(COLLECTION_PART1_OPTIMIZED); | |
222 | - // collection4 | |
223 | - client.add(COLLECTION_PART2_MULTIPLE_SEGMENTS, solrDocuments.get(2)); | |
224 | - client.add(COLLECTION_PART2_MULTIPLE_SEGMENTS, solrDocuments.get(3)); | |
225 | - client.commit(COLLECTION_PART2_MULTIPLE_SEGMENTS); | |
226 | - } catch (Exception e) { | |
227 | - e.printStackTrace(); | |
283 | + // collection1 | |
284 | + client.add(COLLECTION_ALL_OPTIMIZED, solrDocuments.get(1)); | |
285 | + client.add(COLLECTION_ALL_OPTIMIZED, solrDocuments.get(2)); | |
286 | + client.add(COLLECTION_ALL_OPTIMIZED, solrDocuments.get(3)); | |
287 | + client.commit(COLLECTION_ALL_OPTIMIZED); | |
288 | + // collection2 | |
289 | + client.add(COLLECTION_ALL_MULTIPLE_SEGMENTS, solrDocuments.get(1)); | |
290 | + client.commit(COLLECTION_ALL_MULTIPLE_SEGMENTS); | |
291 | + client.add(COLLECTION_ALL_MULTIPLE_SEGMENTS, solrDocuments.get(2)); | |
292 | + client.add(COLLECTION_ALL_MULTIPLE_SEGMENTS, solrDocuments.get(3)); | |
293 | + client.commit(COLLECTION_ALL_MULTIPLE_SEGMENTS); | |
294 | + // collection3 | |
295 | + client.add(COLLECTION_PART1_OPTIMIZED, solrDocuments.get(1)); | |
296 | + client.commit(COLLECTION_PART1_OPTIMIZED); | |
297 | + // collection4 | |
298 | + client.add(COLLECTION_PART2_MULTIPLE_SEGMENTS, solrDocuments.get(2)); | |
299 | + client.add(COLLECTION_PART2_MULTIPLE_SEGMENTS, solrDocuments.get(3)); | |
300 | + client.commit(COLLECTION_PART2_MULTIPLE_SEGMENTS); | |
301 | + } catch (Exception e) { | |
302 | + log.error(e); | |
303 | + } | |
304 | + } else { | |
305 | + log.error("couldn't create directories"); | |
228 | 306 | } |
229 | - | |
230 | 307 | } |
231 | 308 | |
309 | + /** | |
310 | + * Creates the cloud collection. | |
311 | + * | |
312 | + * @param collectionName the collection name | |
313 | + * @param numShards the num shards | |
314 | + * @param replicationFactor the replication factor | |
315 | + * @param confDir the conf dir | |
316 | + * @throws Exception the exception | |
317 | + */ | |
232 | 318 | private static void createCloudCollection(String collectionName, |
233 | 319 | int numShards, int replicationFactor, Path confDir) throws Exception { |
234 | 320 | CloudSolrClient client = cloudCluster.getSolrClient(); |
... | ... | @@ -255,12 +341,15 @@ public class MtasSolrTestDistributedSearchConsistency { |
255 | 341 | client.request(request); |
256 | 342 | } |
257 | 343 | |
344 | + /** | |
345 | + * Shutdown cloud. | |
346 | + */ | |
258 | 347 | private static void shutdownCloud() { |
259 | 348 | try { |
260 | 349 | System.clearProperty("solr.log.dir"); |
261 | 350 | cloudCluster.shutdown(); |
262 | 351 | } catch (Exception e) { |
263 | - e.printStackTrace(); | |
352 | + log.error(e); | |
264 | 353 | } finally { |
265 | 354 | MtasSolrBase.deleteDirectory(cloudBaseDir.toFile()); |
266 | 355 | } |
... | ... |
junit/mtas/solr/MtasSolrTestSearchConsistency.java
... | ... | @@ -3,9 +3,13 @@ package mtas.solr; |
3 | 3 | import static org.junit.Assert.assertEquals; |
4 | 4 | import static org.junit.Assert.assertFalse; |
5 | 5 | |
6 | +import java.io.BufferedWriter; | |
6 | 7 | import java.io.File; |
8 | +import java.io.FileOutputStream; | |
7 | 9 | import java.io.FileWriter; |
8 | 10 | import java.io.IOException; |
11 | +import java.io.OutputStreamWriter; | |
12 | +import java.nio.charset.StandardCharsets; | |
9 | 13 | import java.nio.file.Files; |
10 | 14 | import java.nio.file.Path; |
11 | 15 | import java.nio.file.Paths; |
... | ... | @@ -13,7 +17,11 @@ import java.util.ArrayList; |
13 | 17 | import java.util.Arrays; |
14 | 18 | import java.util.HashMap; |
15 | 19 | import java.util.List; |
20 | +import java.util.Map; | |
16 | 21 | |
22 | +import org.apache.commons.logging.Log; | |
23 | +import org.apache.commons.logging.LogFactory; | |
24 | +import org.apache.lucene.search.highlight.DefaultEncoder; | |
17 | 25 | import org.apache.solr.client.solrj.SolrRequest; |
18 | 26 | import org.apache.solr.client.solrj.SolrRequest.METHOD; |
19 | 27 | import org.apache.solr.client.solrj.SolrServerException; |
... | ... | @@ -28,12 +36,12 @@ import org.apache.solr.core.CoreContainer; |
28 | 36 | |
29 | 37 | public class MtasSolrTestSearchConsistency { |
30 | 38 | |
39 | + private static Log log = LogFactory | |
40 | + .getLog(MtasSolrTestSearchConsistency.class); | |
41 | + | |
31 | 42 | private static EmbeddedSolrServer server; |
32 | - private static CoreContainer container; | |
33 | 43 | |
34 | 44 | private static Path solrPath; |
35 | - | |
36 | - private static HashMap<Integer, SolrInputDocument> solrDocuments; | |
37 | 45 | |
38 | 46 | @org.junit.BeforeClass |
39 | 47 | public static void setup() { |
... | ... | @@ -41,13 +49,15 @@ public class MtasSolrTestSearchConsistency { |
41 | 49 | |
42 | 50 | Path dataPath = Paths.get("junit").resolve("data"); |
43 | 51 | // data |
44 | - solrDocuments = MtasSolrBase.createDocuments(); | |
52 | + Map<Integer, SolrInputDocument> solrDocuments = MtasSolrBase | |
53 | + .createDocuments(); | |
45 | 54 | |
46 | 55 | // create |
47 | 56 | ArrayList<String> collections = new ArrayList<>( |
48 | 57 | Arrays.asList("collection1", "collection2", "collection3")); |
49 | 58 | initializeDirectory(dataPath, collections); |
50 | - container = new CoreContainer(solrPath.toAbsolutePath().toString()); | |
59 | + CoreContainer container = new CoreContainer( | |
60 | + solrPath.toAbsolutePath().toString()); | |
51 | 61 | container.load(); |
52 | 62 | server = new EmbeddedSolrServer(container, collections.get(0)); |
53 | 63 | |
... | ... | @@ -65,18 +75,15 @@ public class MtasSolrTestSearchConsistency { |
65 | 75 | server.add("collection3", solrDocuments.get(2)); |
66 | 76 | server.commit("collection3"); |
67 | 77 | |
68 | - } catch (IOException e) { | |
69 | - e.printStackTrace(); | |
70 | - } catch (SolrServerException e) { | |
71 | - e.printStackTrace(); | |
78 | + } catch (IOException | SolrServerException e) { | |
79 | + log.error(e); | |
72 | 80 | } |
73 | 81 | } |
74 | 82 | |
75 | 83 | private static void initializeDirectory(Path dataPath, |
76 | 84 | List<String> collections) throws IOException { |
77 | 85 | solrPath = Files.createTempDirectory("junitSolr"); |
78 | - // create and fill | |
79 | - solrPath.toFile().mkdir(); | |
86 | + // create and fill | |
80 | 87 | Files.copy(dataPath.resolve("conf").resolve("solr.xml"), |
81 | 88 | solrPath.resolve("solr.xml")); |
82 | 89 | // create collection(s) |
... | ... | @@ -88,24 +95,31 @@ public class MtasSolrTestSearchConsistency { |
88 | 95 | private static void createCollection(String collectionName, Path dataPath) |
89 | 96 | throws IOException { |
90 | 97 | File solrFile; |
91 | - FileWriter writer; | |
98 | + BufferedWriter writer; | |
92 | 99 | // create directories |
93 | - solrPath.resolve(collectionName).toFile().mkdir(); | |
94 | - solrPath.resolve(collectionName).resolve("conf").toFile().mkdir(); | |
95 | - solrPath.resolve(collectionName).resolve("data").toFile().mkdir(); | |
96 | - // copy files | |
97 | - Files.copy(dataPath.resolve("conf").resolve("solrconfig.xml"), solrPath | |
98 | - .resolve(collectionName).resolve("conf").resolve("solrconfig.xml")); | |
99 | - Files.copy(dataPath.resolve("conf").resolve("schema.xml"), | |
100 | - solrPath.resolve(collectionName).resolve("conf").resolve("schema.xml")); | |
101 | - Files.copy(dataPath.resolve("conf").resolve("folia.xml"), | |
102 | - solrPath.resolve(collectionName).resolve("conf").resolve("folia.xml")); | |
103 | - // create core.properties | |
104 | - solrFile = solrPath.resolve(collectionName).resolve("core.properties") | |
105 | - .toFile(); | |
106 | - writer = new FileWriter(solrFile, false); | |
107 | - writer.write("name=" + collectionName + "\n"); | |
108 | - writer.close(); | |
100 | + if (solrPath.resolve(collectionName).toFile().mkdir() | |
101 | + && solrPath.resolve(collectionName).resolve("conf").toFile().mkdir() | |
102 | + && solrPath.resolve(collectionName).resolve("data").toFile().mkdir()) { | |
103 | + // copy files | |
104 | + Files.copy(dataPath.resolve("conf").resolve("solrconfig.xml"), solrPath | |
105 | + .resolve(collectionName).resolve("conf").resolve("solrconfig.xml")); | |
106 | + Files.copy(dataPath.resolve("conf").resolve("schema.xml"), solrPath | |
107 | + .resolve(collectionName).resolve("conf").resolve("schema.xml")); | |
108 | + Files.copy(dataPath.resolve("conf").resolve("folia.xml"), solrPath | |
109 | + .resolve(collectionName).resolve("conf").resolve("folia.xml")); | |
110 | + // create core.properties | |
111 | + solrFile = solrPath.resolve(collectionName).resolve("core.properties") | |
112 | + .toFile(); | |
113 | + writer = new BufferedWriter(new OutputStreamWriter( | |
114 | + new FileOutputStream(solrFile), StandardCharsets.UTF_8)); | |
115 | + try { | |
116 | + writer.write("name=" + collectionName + "\n"); | |
117 | + } finally { | |
118 | + writer.close(); | |
119 | + } | |
120 | + } else { | |
121 | + throw new IOException("couldn't make directories"); | |
122 | + } | |
109 | 123 | } |
110 | 124 | |
111 | 125 | @org.junit.AfterClass |
... | ... | @@ -127,19 +141,19 @@ public class MtasSolrTestSearchConsistency { |
127 | 141 | SolrDocumentList docList2 = qResp2.getResults(); |
128 | 142 | SolrDocumentList docList3 = qResp3.getResults(); |
129 | 143 | assertFalse(docList1.isEmpty()); |
130 | - assertEquals(docList1.size(), docList2.size() + docList3.size()); | |
144 | + assertEquals(docList1.size(), (long) docList2.size() + docList3.size()); | |
131 | 145 | } catch (SolrServerException e) { |
132 | - new IOException(e.getMessage(), e); | |
146 | + throw new IOException(e.getMessage(), e); | |
133 | 147 | } |
134 | 148 | } |
135 | - | |
149 | + | |
136 | 150 | @org.junit.Test |
137 | 151 | public void cqlQueryParserFilter() throws IOException { |
138 | 152 | ModifiableSolrParams params1 = new ModifiableSolrParams(); |
139 | 153 | ModifiableSolrParams params2 = new ModifiableSolrParams(); |
140 | 154 | params1.set("q", |
141 | 155 | "{!mtas_cql field=\"mtas\" query=\"[pos=\\\"ADJ\\\"]{2}[pos=\\\"N\\\"]\"}"); |
142 | - params2.set("q","*"); | |
156 | + params2.set("q", "*"); | |
143 | 157 | params2.set("fq", |
144 | 158 | "{!mtas_cql field=\"mtas\" query=\"[pos=\\\"ADJ\\\"]{2}[pos=\\\"N\\\"]\"}"); |
145 | 159 | try { |
... | ... | @@ -148,35 +162,41 @@ public class MtasSolrTestSearchConsistency { |
148 | 162 | SolrDocumentList docList1 = qResp1.getResults(); |
149 | 163 | SolrDocumentList docList2 = qResp2.getResults(); |
150 | 164 | assertFalse(docList1.isEmpty()); |
151 | - assertEquals(docList1.size(), docList2.size()); | |
165 | + assertEquals(docList1.size(), docList2.size()); | |
152 | 166 | } catch (SolrServerException e) { |
153 | - new IOException(e.getMessage(), e); | |
167 | + throw new IOException(e.getMessage(), e); | |
154 | 168 | } |
155 | 169 | |
156 | 170 | } |
157 | 171 | |
158 | 172 | @org.junit.Test |
159 | - public void mtasRequestHandler() throws SolrServerException, IOException { | |
173 | + public void mtasRequestHandler() throws IOException { | |
160 | 174 | ModifiableSolrParams params = new ModifiableSolrParams(); |
161 | 175 | params.set("q", "*:*"); |
162 | 176 | params.set("mtas", "true"); |
163 | - params.set("mtas.stats","true"); | |
164 | - params.set("mtas.stats.spans","true"); | |
165 | - params.set("mtas.stats.spans.0.field","mtas"); | |
166 | - params.set("mtas.stats.spans.0.key","statsKey"); | |
167 | - params.set("mtas.stats.spans.0.query.0.type","cql"); | |
168 | - params.set("mtas.stats.spans.0.query.0.value","[]"); | |
169 | - params.set("mtas.stats.spans.0.type","n,sum,mean"); | |
170 | - params.set("mtas.stats.positions","true"); | |
171 | - params.set("mtas.stats.positions.0.field","mtas"); | |
172 | - params.set("mtas.stats.positions.0.key","statsKey"); | |
173 | - params.set("mtas.stats.positions.0.type","n,sum,mean"); | |
174 | - params.set("rows","0"); | |
177 | + params.set("mtas.stats", "true"); | |
178 | + params.set("mtas.stats.spans", "true"); | |
179 | + params.set("mtas.stats.spans.0.field", "mtas"); | |
180 | + params.set("mtas.stats.spans.0.key", "statsKey"); | |
181 | + params.set("mtas.stats.spans.0.query.0.type", "cql"); | |
182 | + params.set("mtas.stats.spans.0.query.0.value", "[]"); | |
183 | + params.set("mtas.stats.spans.0.type", "n,sum,mean"); | |
184 | + params.set("mtas.stats.positions", "true"); | |
185 | + params.set("mtas.stats.positions.0.field", "mtas"); | |
186 | + params.set("mtas.stats.positions.0.key", "statsKey"); | |
187 | + params.set("mtas.stats.positions.0.type", "n,sum,mean"); | |
188 | + params.set("rows", "0"); | |
175 | 189 | SolrRequest<?> request = new QueryRequest(params, METHOD.POST); |
176 | - NamedList<Object> response = server.request(request, "collection1"); | |
177 | - assertEquals(MtasSolrBase.getFromMtasStats(response, "spans", "statsKey", "sum"), MtasSolrBase.getFromMtasStats(response, "positions", "statsKey", "sum")); | |
190 | + NamedList<Object> response; | |
191 | + try { | |
192 | + response = server.request(request, "collection1"); | |
193 | + } catch (SolrServerException e) { | |
194 | + throw new IOException(e); | |
195 | + } | |
196 | + assertEquals( | |
197 | + MtasSolrBase.getFromMtasStats(response, "spans", "statsKey", "sum"), | |
198 | + MtasSolrBase.getFromMtasStats(response, "positions", "statsKey", | |
199 | + "sum")); | |
178 | 200 | } |
179 | - | |
180 | - | |
181 | 201 | |
182 | 202 | } |
... | ... |
pom.xml
... | ... | @@ -158,62 +158,61 @@ |
158 | 158 | </configuration> |
159 | 159 | </plugin> |
160 | 160 | <plugin> |
161 | - <groupId>org.codehaus.mojo</groupId> | |
162 | - <artifactId>cobertura-maven-plugin</artifactId> | |
163 | - <version>2.7</version> | |
164 | - <configuration> | |
165 | - </configuration> | |
166 | - <executions> | |
167 | - <execution> | |
168 | - <goals> | |
169 | - <goal>clean</goal> | |
170 | - <goal>check</goal> | |
171 | - </goals> | |
172 | - </execution> | |
173 | - </executions> | |
174 | - </plugin> | |
175 | - <plugin> | |
176 | - <groupId>org.jacoco</groupId> | |
177 | -<artifactId>jacoco-maven-plugin</artifactId> | |
178 | - <version>0.7.5.201505241946</version> | |
179 | - <executions> | |
180 | - <execution> | |
181 | - <id>default-prepare-agent</id> | |
182 | - <goals> | |
183 | - <goal>prepare-agent</goal> | |
184 | - </goals> | |
185 | - </execution> | |
186 | - <execution> | |
187 | - <id>default-report</id> | |
188 | - <phase>prepare-package</phase> | |
189 | - <goals> | |
190 | - <goal>report</goal> | |
191 | - </goals> | |
161 | + <groupId>org.codehaus.mojo</groupId> | |
162 | + <artifactId>cobertura-maven-plugin</artifactId> | |
163 | + <version>2.7</version> | |
164 | + <configuration> | |
165 | + </configuration> | |
166 | + <executions> | |
167 | + <execution> | |
168 | + <goals> | |
169 | + <goal>clean</goal> | |
170 | + <goal>check</goal> | |
171 | + </goals> | |
172 | + </execution> | |
173 | + </executions> | |
174 | + </plugin> | |
175 | + <plugin> | |
176 | + <groupId>org.jacoco</groupId> | |
177 | + <artifactId>jacoco-maven-plugin</artifactId> | |
178 | + <version>0.7.5.201505241946</version> | |
179 | + <executions> | |
180 | + <execution> | |
181 | + <id>default-prepare-agent</id> | |
182 | + <goals> | |
183 | + <goal>prepare-agent</goal> | |
184 | + </goals> | |
185 | + </execution> | |
186 | + <execution> | |
187 | + <id>default-report</id> | |
188 | + <phase>prepare-package</phase> | |
189 | + <goals> | |
190 | + <goal>report</goal> | |
191 | + </goals> | |
192 | 192 | |
193 | - </execution> | |
194 | - <execution> | |
195 | - <id>default-check</id> | |
196 | - <goals> | |
197 | - <goal>check</goal> | |
198 | - </goals> | |
199 | - <configuration> | |
200 | - <rules><!-- implementation is needed only for Maven 2 --> | |
201 | - <rule implementation="org.jacoco.maven.RuleConfiguration"> | |
202 | -<element>BUNDLE</element> | |
203 | - <limits><!-- implementation is needed only for Maven 2 --> | |
204 | - <limit implementation="org.jacoco.report.check.Limit"> | |
205 | -<counter>COMPLEXITY</counter> | |
206 | -<value>COVEREDRATIO</value> | |
207 | -<minimum>0.60</minimum> | |
208 | - </limit> | |
209 | - </limits> | |
210 | - </rule> | |
211 | - </rules> | |
212 | - </configuration> | |
213 | - </execution> | |
214 | - </executions> | |
215 | - </plugin> | |
216 | - | |
193 | + </execution> | |
194 | + <execution> | |
195 | + <id>default-check</id> | |
196 | + <goals> | |
197 | + <goal>check</goal> | |
198 | + </goals> | |
199 | + <configuration> | |
200 | + <rules><!-- implementation is needed only for Maven 2 --> | |
201 | + <rule implementation="org.jacoco.maven.RuleConfiguration"> | |
202 | + <element>BUNDLE</element> | |
203 | + <limits><!-- implementation is needed only for Maven 2 --> | |
204 | + <limit implementation="org.jacoco.report.check.Limit"> | |
205 | + <counter>COMPLEXITY</counter> | |
206 | + <value>COVEREDRATIO</value> | |
207 | + <minimum>0.60</minimum> | |
208 | + </limit> | |
209 | + </limits> | |
210 | + </rule> | |
211 | + </rules> | |
212 | + </configuration> | |
213 | + </execution> | |
214 | + </executions> | |
215 | + </plugin> | |
217 | 216 | </plugins> |
218 | 217 | </build> |
219 | 218 | <reporting> |
... | ... | @@ -240,9 +239,7 @@ |
240 | 239 | </reportSet> |
241 | 240 | <reportSet> |
242 | 241 | <id>aggregate</id> |
243 | - <configuration> | |
244 | - | |
245 | - </configuration> | |
242 | + <configuration/> | |
246 | 243 | <reports> |
247 | 244 | <report>aggregate</report> |
248 | 245 | </reports> |
... | ... | @@ -286,20 +283,33 @@ |
286 | 283 | <version>3.0.4</version> |
287 | 284 | <configuration> |
288 | 285 | <excludeFilterFile>conf/reports/findbugs-exclude.xml</excludeFilterFile> |
286 | + <includeTests>true</includeTests> | |
289 | 287 | </configuration> |
290 | 288 | </plugin> |
291 | - <plugin> | |
289 | + <!-- <plugin> | |
292 | 290 | <groupId>org.codehaus.mojo</groupId> |
293 | 291 | <artifactId>cobertura-maven-plugin</artifactId> |
294 | 292 | <version>2.7</version> |
295 | 293 | <reportSets> |
294 | + <reportSet> | |
295 | + <reports> | |
296 | + <report>cobertura</report> | |
297 | + </reports> | |
298 | + </reportSet> | |
299 | + </reportSets> | |
300 | + </plugin> --> | |
301 | + <plugin> | |
302 | + <groupId>org.jacoco</groupId> | |
303 | + <artifactId>jacoco-maven-plugin</artifactId> | |
304 | + <reportSets> | |
296 | 305 | <reportSet> |
297 | 306 | <reports> |
298 | - <report>cobertura</report> | |
307 | + <!-- select non-aggregate reports --> | |
308 | + <report>report</report> | |
299 | 309 | </reports> |
300 | 310 | </reportSet> |
301 | 311 | </reportSets> |
302 | - </plugin> | |
312 | + </plugin> | |
303 | 313 | </plugins> |
304 | 314 | </reporting> |
305 | 315 | <repositories> |
... | ... |
src/mtas/codec/util/CodecComponent.java
... | ... | @@ -282,32 +282,39 @@ public class CodecComponent { |
282 | 282 | public static class ComponentDocument implements BasicComponent { |
283 | 283 | |
284 | 284 | /** The regexp. */ |
285 | - public String key, prefix, regexp, ignoreRegexp; | |
285 | + public String key; | |
286 | + public String prefix; | |
287 | + public String regexp; | |
288 | + public String ignoreRegexp; | |
286 | 289 | |
287 | 290 | /** The list. */ |
288 | - public HashSet<String> list, ignoreList; | |
291 | + public Set<String> list; | |
292 | + public Set<String> ignoreList; | |
289 | 293 | |
290 | - public boolean listRegexp, listExpand, ignoreListRegexp; | |
294 | + public boolean listRegexp; | |
295 | + public boolean listExpand; | |
296 | + public boolean ignoreListRegexp; | |
291 | 297 | |
292 | 298 | public int listExpandNumber; |
293 | 299 | |
294 | 300 | /** The stats type. */ |
295 | - public String dataType, statsType; | |
301 | + public String dataType; | |
302 | + public String statsType; | |
296 | 303 | |
297 | 304 | /** The stats items. */ |
298 | - public TreeSet<String> statsItems; | |
305 | + public Set<String> statsItems; | |
299 | 306 | |
300 | 307 | /** The number. */ |
301 | 308 | public int listNumber; |
302 | 309 | |
303 | 310 | /** The unique key. */ |
304 | - public HashMap<Integer, String> uniqueKey; | |
311 | + public Map<Integer, String> uniqueKey; | |
305 | 312 | |
306 | 313 | /** The stats. */ |
307 | - public HashMap<Integer, MtasDataCollector<?, ?>> statsData; | |
314 | + public Map<Integer, MtasDataCollector<?, ?>> statsData; | |
308 | 315 | |
309 | 316 | /** The list. */ |
310 | - public HashMap<Integer, MtasDataCollector<?, ?>> statsList; | |
317 | + public Map<Integer, MtasDataCollector<?, ?>> statsList; | |
311 | 318 | |
312 | 319 | /** |
313 | 320 | * Instantiates a new component document. |
... | ... | @@ -576,6 +583,7 @@ public class CodecComponent { |
576 | 583 | this.queryType = queryType; |
577 | 584 | this.queryPrefix = queryPrefix; |
578 | 585 | this.queryIgnore = queryIgnore; |
586 | + this.queryMaximumIgnoreLength = queryMaximumIgnoreLength; | |
579 | 587 | this.queryVariables = queryVariables; |
580 | 588 | this.key = key; |
581 | 589 | this.left = left; |
... | ... |
src/mtas/codec/util/CodecUtil.java
... | ... | @@ -6,6 +6,7 @@ import java.util.ArrayList; |
6 | 6 | import java.util.Arrays; |
7 | 7 | import java.util.HashMap; |
8 | 8 | import java.util.List; |
9 | +import java.util.Set; | |
9 | 10 | import java.util.TreeSet; |
10 | 11 | import java.util.regex.Matcher; |
11 | 12 | import java.util.regex.Pattern; |
... | ... | @@ -317,7 +318,7 @@ public class CodecUtil { |
317 | 318 | * the function parser |
318 | 319 | * @return the string |
319 | 320 | */ |
320 | - static String createStatsType(TreeSet<String> statsItems, String sortType, | |
321 | + static String createStatsType(Set<String> statsItems, String sortType, | |
321 | 322 | MtasFunctionParserFunction functionParser) { |
322 | 323 | String statsType = STATS_BASIC; |
323 | 324 | for (String statsItem : statsItems) { |
... | ... |
src/mtas/codec/util/DataCollector.java
1 | 1 | package mtas.codec.util; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | +import java.util.Set; | |
4 | 5 | import java.util.TreeSet; |
5 | 6 | |
6 | 7 | import mtas.codec.util.collector.MtasDataCollector; |
... | ... | @@ -50,7 +51,7 @@ public class DataCollector { |
50 | 51 | * Signals that an I/O exception has occurred. |
51 | 52 | */ |
52 | 53 | public static MtasDataCollector<?, ?> getCollector(String collectorType, |
53 | - String dataType, String statsType, TreeSet<String> statsItems, | |
54 | + String dataType, String statsType, Set<String> statsItems, | |
54 | 55 | String sortType, String sortDirection, Integer start, Integer number, |
55 | 56 | String segmentRegistration, String boundary) throws IOException { |
56 | 57 | return getCollector(collectorType, dataType, statsType, statsItems, |
... | ... | @@ -102,10 +103,10 @@ public class DataCollector { |
102 | 103 | * Signals that an I/O exception has occurred. |
103 | 104 | */ |
104 | 105 | public static MtasDataCollector<?, ?> getCollector(String collectorType, |
105 | - String dataType, String statsType, TreeSet<String> statsItems, | |
106 | + String dataType, String statsType, Set<String> statsItems, | |
106 | 107 | String sortType, String sortDirection, Integer start, Integer number, |
107 | 108 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
108 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
109 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
109 | 110 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
110 | 111 | String segmentRegistration, String boundary) throws IOException { |
111 | 112 | if (dataType != null && dataType.equals(CodecUtil.DATA_TYPE_LONG)) { |
... | ... |
src/mtas/codec/util/collector/MtasDataAdvanced.java
... | ... | @@ -68,10 +68,10 @@ abstract class MtasDataAdvanced<T1 extends Number & Comparable<T1>, T2 extends N |
68 | 68 | * @throws IOException Signals that an I/O exception has occurred. |
69 | 69 | */ |
70 | 70 | public MtasDataAdvanced(String collectorType, String dataType, |
71 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
71 | + Set<String> statsItems, String sortType, String sortDirection, | |
72 | 72 | Integer start, Integer number, String[] subCollectorTypes, |
73 | 73 | String[] subDataTypes, String[] subStatsTypes, |
74 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
74 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
75 | 75 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
76 | 76 | MtasDataOperations<T1, T2> operations, String segmentRegistration, |
77 | 77 | String boundary) throws IOException { |
... | ... |
src/mtas/codec/util/collector/MtasDataBasic.java
... | ... | @@ -59,10 +59,10 @@ abstract class MtasDataBasic<T1 extends Number & Comparable<T1>, T2 extends Numb |
59 | 59 | * @throws IOException Signals that an I/O exception has occurred. |
60 | 60 | */ |
61 | 61 | public MtasDataBasic(String collectorType, String dataType, |
62 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
62 | + Set<String> statsItems, String sortType, String sortDirection, | |
63 | 63 | Integer start, Integer number, String[] subCollectorTypes, |
64 | 64 | String[] subDataTypes, String[] subStatsTypes, |
65 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
65 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
66 | 66 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
67 | 67 | MtasDataOperations<T1, T2> operations, String segmentRegistration, |
68 | 68 | String boundary) throws IOException { |
... | ... |
src/mtas/codec/util/collector/MtasDataCollector.java
... | ... | @@ -69,7 +69,7 @@ public abstract class MtasDataCollector<T1 extends Number & Comparable<T1>, T2 e |
69 | 69 | protected String dataType; |
70 | 70 | |
71 | 71 | /** The stats items. */ |
72 | - public TreeSet<String> statsItems; | |
72 | + public Set<String> statsItems; | |
73 | 73 | |
74 | 74 | /** The sort type. */ |
75 | 75 | protected String sortType; |
... | ... | @@ -142,7 +142,7 @@ public abstract class MtasDataCollector<T1 extends Number & Comparable<T1>, T2 e |
142 | 142 | private String[] subStatsTypes; |
143 | 143 | |
144 | 144 | /** The sub stats items. */ |
145 | - private TreeSet<String>[] subStatsItems; | |
145 | + private Set<String>[] subStatsItems; | |
146 | 146 | |
147 | 147 | /** The sub sort types. */ |
148 | 148 | private String[] subSortTypes; |
... | ... | @@ -193,7 +193,7 @@ public abstract class MtasDataCollector<T1 extends Number & Comparable<T1>, T2 e |
193 | 193 | private transient String[] newSubStatsTypes; |
194 | 194 | |
195 | 195 | /** The new sub stats items. */ |
196 | - private transient TreeSet<String>[] newSubStatsItems; | |
196 | + private transient Set<String>[] newSubStatsItems; | |
197 | 197 | |
198 | 198 | /** The new sub sort types. */ |
199 | 199 | private transient String[] newSubSortTypes; |
... | ... | @@ -237,7 +237,7 @@ public abstract class MtasDataCollector<T1 extends Number & Comparable<T1>, T2 e |
237 | 237 | */ |
238 | 238 | @SuppressWarnings("unchecked") |
239 | 239 | protected MtasDataCollector(String collectorType, String dataType, |
240 | - String statsType, TreeSet<String> statsItems, String sortType, | |
240 | + String statsType, Set<String> statsItems, String sortType, | |
241 | 241 | String sortDirection, Integer start, Integer number, |
242 | 242 | String segmentRegistration, String boundary) throws IOException { |
243 | 243 | // set properties |
... | ... | @@ -315,10 +315,10 @@ public abstract class MtasDataCollector<T1 extends Number & Comparable<T1>, T2 e |
315 | 315 | * @throws IOException Signals that an I/O exception has occurred. |
316 | 316 | */ |
317 | 317 | protected MtasDataCollector(String collectorType, String dataType, |
318 | - String statsType, TreeSet<String> statsItems, String sortType, | |
318 | + String statsType, Set<String> statsItems, String sortType, | |
319 | 319 | String sortDirection, Integer start, Integer number, |
320 | 320 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
321 | - TreeSet<String>[] subStatsItems, String subSortTypes[], | |
321 | + Set<String>[] subStatsItems, String subSortTypes[], | |
322 | 322 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
323 | 323 | String segmentRegistration, String boundary) throws IOException { |
324 | 324 | // initialize |
... | ... | @@ -520,7 +520,7 @@ public abstract class MtasDataCollector<T1 extends Number & Comparable<T1>, T2 e |
520 | 520 | newKeyList[0] = DataCollector.COLLECTOR_TYPE_DATA; |
521 | 521 | newSourceNumberList[0] = 1; |
522 | 522 | newErrorNumber[0] = 0; |
523 | - newErrorList[0] = new HashMap<String, Integer>(); | |
523 | + newErrorList[0] = new HashMap<>(); | |
524 | 524 | newPosition = 1; |
525 | 525 | newCurrentPosition = newPosition - 1; |
526 | 526 | newCurrentExisting = false; |
... | ... |
src/mtas/codec/util/collector/MtasDataDoubleAdvanced.java
... | ... | @@ -2,6 +2,7 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.Collections; |
5 | +import java.util.Set; | |
5 | 6 | import java.util.TreeSet; |
6 | 7 | import org.apache.commons.lang.ArrayUtils; |
7 | 8 | import mtas.codec.util.CodecUtil; |
... | ... | @@ -53,10 +54,10 @@ public class MtasDataDoubleAdvanced extends MtasDataAdvanced<Double, Double> { |
53 | 54 | * Signals that an I/O exception has occurred. |
54 | 55 | */ |
55 | 56 | public MtasDataDoubleAdvanced(String collectorType, |
56 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
57 | + Set<String> statsItems, String sortType, String sortDirection, | |
57 | 58 | Integer start, Integer number, String[] subCollectorTypes, |
58 | 59 | String[] subDataTypes, String[] subStatsTypes, |
59 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
60 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
60 | 61 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
61 | 62 | String segmentRegistration, String boundary) throws IOException { |
62 | 63 | super(collectorType, CodecUtil.DATA_TYPE_DOUBLE, statsItems, sortType, |
... | ... |
src/mtas/codec/util/collector/MtasDataDoubleBasic.java
... | ... | @@ -2,6 +2,7 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.Collections; |
5 | +import java.util.Set; | |
5 | 6 | import java.util.TreeSet; |
6 | 7 | import org.apache.commons.lang.ArrayUtils; |
7 | 8 | import mtas.codec.util.CodecUtil; |
... | ... | @@ -52,10 +53,10 @@ public class MtasDataDoubleBasic extends MtasDataBasic<Double, Double> { |
52 | 53 | * @throws IOException |
53 | 54 | * Signals that an I/O exception has occurred. |
54 | 55 | */ |
55 | - public MtasDataDoubleBasic(String collectorType, TreeSet<String> statsItems, | |
56 | + public MtasDataDoubleBasic(String collectorType, Set<String> statsItems, | |
56 | 57 | String sortType, String sortDirection, Integer start, Integer number, |
57 | 58 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
58 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
59 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
59 | 60 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
60 | 61 | String segmentRegistration, String boundary) throws IOException { |
61 | 62 | super(collectorType, CodecUtil.DATA_TYPE_DOUBLE, statsItems, sortType, |
... | ... |
src/mtas/codec/util/collector/MtasDataDoubleFull.java
... | ... | @@ -2,6 +2,7 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.Collections; |
5 | +import java.util.Set; | |
5 | 6 | import java.util.TreeSet; |
6 | 7 | import org.apache.commons.lang.ArrayUtils; |
7 | 8 | import mtas.codec.util.CodecUtil; |
... | ... | @@ -52,10 +53,10 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> { |
52 | 53 | * @throws IOException |
53 | 54 | * Signals that an I/O exception has occurred. |
54 | 55 | */ |
55 | - public MtasDataDoubleFull(String collectorType, TreeSet<String> statsItems, | |
56 | + public MtasDataDoubleFull(String collectorType, Set<String> statsItems, | |
56 | 57 | String sortType, String sortDirection, Integer start, Integer number, |
57 | 58 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
58 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
59 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
59 | 60 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
60 | 61 | String segmentRegistration, String boundary) throws IOException { |
61 | 62 | super(collectorType, CodecUtil.DATA_TYPE_DOUBLE, statsItems, sortType, |
... | ... |
src/mtas/codec/util/collector/MtasDataFull.java
... | ... | @@ -51,10 +51,10 @@ abstract class MtasDataFull<T1 extends Number & Comparable<T1>, T2 extends Numbe |
51 | 51 | * @throws IOException Signals that an I/O exception has occurred. |
52 | 52 | */ |
53 | 53 | public MtasDataFull(String collectorType, String dataType, |
54 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
54 | + Set<String> statsItems, String sortType, String sortDirection, | |
55 | 55 | Integer start, Integer number, String[] subCollectorTypes, |
56 | 56 | String[] subDataTypes, String[] subStatsTypes, |
57 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
57 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
58 | 58 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
59 | 59 | MtasDataOperations<T1, T2> operations, String segmentRegistration, |
60 | 60 | String boundary) throws IOException { |
... | ... |
src/mtas/codec/util/collector/MtasDataItem.java
... | ... | @@ -4,6 +4,7 @@ import java.io.IOException; |
4 | 4 | import java.io.Serializable; |
5 | 5 | import java.util.HashMap; |
6 | 6 | import java.util.Map; |
7 | +import java.util.Set; | |
7 | 8 | import java.util.TreeSet; |
8 | 9 | |
9 | 10 | /** |
... | ... | @@ -24,7 +25,7 @@ public abstract class MtasDataItem<T1 extends Number & Comparable<T1>, T2 extend |
24 | 25 | protected MtasDataCollector<?, ?> sub; |
25 | 26 | |
26 | 27 | /** The stats items. */ |
27 | - protected TreeSet<String> statsItems; | |
28 | + protected Set<String> statsItems; | |
28 | 29 | |
29 | 30 | /** The sort direction. */ |
30 | 31 | protected String sortType; |
... | ... | @@ -34,7 +35,7 @@ public abstract class MtasDataItem<T1 extends Number & Comparable<T1>, T2 extend |
34 | 35 | protected int errorNumber; |
35 | 36 | |
36 | 37 | /** The error list. */ |
37 | - protected HashMap<String, Integer> errorList; | |
38 | + protected Map<String, Integer> errorList; | |
38 | 39 | |
39 | 40 | /** The comparable sort value. */ |
40 | 41 | protected MtasDataItemNumberComparator<?> comparableSortValue; |
... | ... | @@ -63,9 +64,9 @@ public abstract class MtasDataItem<T1 extends Number & Comparable<T1>, T2 extend |
63 | 64 | * @param sourceNumber |
64 | 65 | * the source number |
65 | 66 | */ |
66 | - public MtasDataItem(MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, | |
67 | + public MtasDataItem(MtasDataCollector<?, ?> sub, Set<String> statsItems, | |
67 | 68 | String sortType, String sortDirection, int errorNumber, |
68 | - HashMap<String, Integer> errorList, int sourceNumber) { | |
69 | + Map<String, Integer> errorList, int sourceNumber) { | |
69 | 70 | this.sub = sub; |
70 | 71 | this.statsItems = statsItems; |
71 | 72 | this.sortType = sortType; |
... | ... |
src/mtas/codec/util/collector/MtasDataItemAdvanced.java
... | ... | @@ -6,6 +6,8 @@ import java.util.HashMap; |
6 | 6 | import java.util.Map; |
7 | 7 | import java.util.TreeSet; |
8 | 8 | import java.util.Map.Entry; |
9 | +import java.util.Set; | |
10 | + | |
9 | 11 | import mtas.codec.util.CodecUtil; |
10 | 12 | |
11 | 13 | /** |
... | ... | @@ -77,8 +79,8 @@ abstract class MtasDataItemAdvanced<T1 extends Number & Comparable<T1>, T2 exten |
77 | 79 | */ |
78 | 80 | public MtasDataItemAdvanced(T1 valueSum, T2 valueSumOfLogs, |
79 | 81 | T1 valueSumOfSquares, T1 valueMin, T1 valueMax, Long valueN, |
80 | - MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, String sortType, | |
81 | - String sortDirection, int errorNumber, HashMap<String, Integer> errorList, | |
82 | + MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType, | |
83 | + String sortDirection, int errorNumber, Map<String, Integer> errorList, | |
82 | 84 | MtasDataOperations<T1, T2> operations, int sourceNumber) { |
83 | 85 | super(sub, statsItems, sortType, sortDirection, errorNumber, errorList, |
84 | 86 | sourceNumber); |
... | ... |
src/mtas/codec/util/collector/MtasDataItemBasic.java
... | ... | @@ -6,6 +6,8 @@ import java.util.HashMap; |
6 | 6 | import java.util.Map; |
7 | 7 | import java.util.TreeSet; |
8 | 8 | import java.util.Map.Entry; |
9 | +import java.util.Set; | |
10 | + | |
9 | 11 | import mtas.codec.util.CodecUtil; |
10 | 12 | |
11 | 13 | /** |
... | ... | @@ -56,8 +58,8 @@ abstract class MtasDataItemBasic<T1 extends Number & Comparable<T1>, T2 extends |
56 | 58 | * the source number |
57 | 59 | */ |
58 | 60 | public MtasDataItemBasic(T1 valueSum, long valueN, |
59 | - MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, String sortType, | |
60 | - String sortDirection, int errorNumber, HashMap<String, Integer> errorList, | |
61 | + MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType, | |
62 | + String sortDirection, int errorNumber, Map<String, Integer> errorList, | |
61 | 63 | MtasDataOperations<T1, T2> operations, int sourceNumber) { |
62 | 64 | super(sub, statsItems, sortType, sortDirection, errorNumber, errorList, |
63 | 65 | sourceNumber); |
... | ... |
src/mtas/codec/util/collector/MtasDataItemDoubleAdvanced.java
1 | 1 | package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | +import java.util.Map; | |
5 | +import java.util.Set; | |
4 | 6 | import java.util.TreeSet; |
5 | 7 | import mtas.codec.util.CodecUtil; |
6 | 8 | |
... | ... | @@ -45,8 +47,8 @@ public class MtasDataItemDoubleAdvanced |
45 | 47 | */ |
46 | 48 | public MtasDataItemDoubleAdvanced(Double valueSum, Double valueSumOfLogs, |
47 | 49 | Double valueSumOfSquares, Double valueMin, Double valueMax, long valueN, |
48 | - MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, String sortType, | |
49 | - String sortDirection, int errorNumber, HashMap<String, Integer> errorList, | |
50 | + MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType, | |
51 | + String sortDirection, int errorNumber, Map<String, Integer> errorList, | |
50 | 52 | int sourceNumber) { |
51 | 53 | super(valueSum, valueSumOfLogs, valueSumOfSquares, valueMin, valueMax, |
52 | 54 | valueN, sub, statsItems, sortType, sortDirection, errorNumber, |
... | ... |
src/mtas/codec/util/collector/MtasDataItemDoubleBasic.java
1 | 1 | package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | +import java.util.Map; | |
5 | +import java.util.Set; | |
4 | 6 | import java.util.TreeSet; |
5 | 7 | import mtas.codec.util.CodecUtil; |
6 | 8 | |
... | ... | @@ -35,8 +37,8 @@ public class MtasDataItemDoubleBasic extends MtasDataItemBasic<Double, Double> { |
35 | 37 | * the source number |
36 | 38 | */ |
37 | 39 | public MtasDataItemDoubleBasic(Double valueSum, long valueN, |
38 | - MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, String sortType, | |
39 | - String sortDirection, int errorNumber, HashMap<String, Integer> errorList, | |
40 | + MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType, | |
41 | + String sortDirection, int errorNumber, Map<String, Integer> errorList, | |
40 | 42 | int sourceNumber) { |
41 | 43 | super(valueSum, valueN, sub, statsItems, sortType, sortDirection, |
42 | 44 | errorNumber, errorList, new MtasDataDoubleOperations(), sourceNumber); |
... | ... |
src/mtas/codec/util/collector/MtasDataItemDoubleFull.java
... | ... | @@ -2,6 +2,8 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | 4 | import java.util.LinkedHashMap; |
5 | +import java.util.Map; | |
6 | +import java.util.Set; | |
5 | 7 | import java.util.TreeSet; |
6 | 8 | import java.util.regex.Matcher; |
7 | 9 | import java.util.regex.Pattern; |
... | ... | @@ -40,8 +42,8 @@ public class MtasDataItemDoubleFull extends MtasDataItemFull<Double, Double> { |
40 | 42 | * the source number |
41 | 43 | */ |
42 | 44 | public MtasDataItemDoubleFull(double[] value, MtasDataCollector<?, ?> sub, |
43 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
44 | - int errorNumber, HashMap<String, Integer> errorList, int sourceNumber) { | |
45 | + Set<String> statsItems, String sortType, String sortDirection, | |
46 | + int errorNumber, Map<String, Integer> errorList, int sourceNumber) { | |
45 | 47 | super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection, |
46 | 48 | errorNumber, errorList, new MtasDataDoubleOperations(), sourceNumber); |
47 | 49 | } |
... | ... |
src/mtas/codec/util/collector/MtasDataItemFull.java
... | ... | @@ -6,6 +6,7 @@ import java.util.HashMap; |
6 | 6 | import java.util.Map; |
7 | 7 | import java.util.TreeSet; |
8 | 8 | import java.util.Map.Entry; |
9 | +import java.util.Set; | |
9 | 10 | import java.util.regex.Matcher; |
10 | 11 | import java.util.regex.Pattern; |
11 | 12 | import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
... | ... | @@ -61,8 +62,8 @@ abstract class MtasDataItemFull<T1 extends Number & Comparable<T1>, T2 extends N |
61 | 62 | * the source number |
62 | 63 | */ |
63 | 64 | public MtasDataItemFull(T1[] value, MtasDataCollector<?, ?> sub, |
64 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
65 | - int errorNumber, HashMap<String, Integer> errorList, | |
65 | + Set<String> statsItems, String sortType, String sortDirection, | |
66 | + int errorNumber, Map<String, Integer> errorList, | |
66 | 67 | MtasDataOperations<T1, T2> operations, int sourceNumber) { |
67 | 68 | super(sub, statsItems, sortType, sortDirection, errorNumber, errorList, |
68 | 69 | sourceNumber); |
... | ... |
src/mtas/codec/util/collector/MtasDataItemLongAdvanced.java
1 | 1 | package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | +import java.util.Map; | |
5 | +import java.util.Set; | |
4 | 6 | import java.util.TreeSet; |
5 | 7 | import mtas.codec.util.CodecUtil; |
6 | 8 | |
... | ... | @@ -44,8 +46,8 @@ class MtasDataItemLongAdvanced extends MtasDataItemAdvanced<Long, Double> { |
44 | 46 | */ |
45 | 47 | public MtasDataItemLongAdvanced(Long valueSum, Double valueSumOfLogs, |
46 | 48 | Long valueSumOfSquares, Long valueMin, Long valueMax, long valueN, |
47 | - MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, String sortType, | |
48 | - String sortDirection, int errorNumber, HashMap<String, Integer> errorList, | |
49 | + MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType, | |
50 | + String sortDirection, int errorNumber, Map<String, Integer> errorList, | |
49 | 51 | int sourceNumber) { |
50 | 52 | super(valueSum, valueSumOfLogs, valueSumOfSquares, valueMin, valueMax, |
51 | 53 | valueN, sub, statsItems, sortType, sortDirection, errorNumber, |
... | ... |
src/mtas/codec/util/collector/MtasDataItemLongBasic.java
1 | 1 | package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | +import java.util.Map; | |
5 | +import java.util.Set; | |
4 | 6 | import java.util.TreeSet; |
5 | 7 | import mtas.codec.util.CodecUtil; |
6 | 8 | |
... | ... | @@ -35,8 +37,8 @@ class MtasDataItemLongBasic extends MtasDataItemBasic<Long, Double> { |
35 | 37 | * the source number |
36 | 38 | */ |
37 | 39 | public MtasDataItemLongBasic(Long valueSum, long valueN, |
38 | - MtasDataCollector<?, ?> sub, TreeSet<String> statsItems, String sortType, | |
39 | - String sortDirection, int errorNumber, HashMap<String, Integer> errorList, | |
40 | + MtasDataCollector<?, ?> sub, Set<String> statsItems, String sortType, | |
41 | + String sortDirection, int errorNumber, Map<String, Integer> errorList, | |
40 | 42 | int sourceNumber) { |
41 | 43 | super(valueSum, valueN, sub, statsItems, sortType, sortDirection, |
42 | 44 | errorNumber, errorList, new MtasDataLongOperations(), sourceNumber); |
... | ... |
src/mtas/codec/util/collector/MtasDataItemLongFull.java
... | ... | @@ -2,6 +2,8 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | 4 | import java.util.LinkedHashMap; |
5 | +import java.util.Map; | |
6 | +import java.util.Set; | |
5 | 7 | import java.util.TreeSet; |
6 | 8 | import java.util.regex.Matcher; |
7 | 9 | import java.util.regex.Pattern; |
... | ... | @@ -40,8 +42,8 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> { |
40 | 42 | * the source number |
41 | 43 | */ |
42 | 44 | public MtasDataItemLongFull(long[] value, MtasDataCollector<?, ?> sub, |
43 | - TreeSet<String> statsItems, String sortType, String sortDirection, | |
44 | - int errorNumber, HashMap<String, Integer> errorList, int sourceNumber) { | |
45 | + Set<String> statsItems, String sortType, String sortDirection, | |
46 | + int errorNumber, Map<String, Integer> errorList, int sourceNumber) { | |
45 | 47 | super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection, |
46 | 48 | errorNumber, errorList, new MtasDataLongOperations(), sourceNumber); |
47 | 49 | } |
... | ... | @@ -55,7 +57,7 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> { |
55 | 57 | */ |
56 | 58 | @Override |
57 | 59 | protected HashMap<String, Object> getDistribution(String argument) { |
58 | - HashMap<String, Object> result = new LinkedHashMap<String, Object>(); | |
60 | + HashMap<String, Object> result = new LinkedHashMap<>(); | |
59 | 61 | Long start = null, end = null, step = null; |
60 | 62 | Integer number = null; |
61 | 63 | if (argument != null) { |
... | ... | @@ -136,9 +138,9 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> { |
136 | 138 | Long r = Math.min(end, l + step - 1); |
137 | 139 | String key; |
138 | 140 | if (step > 1 && r > l) { |
139 | - key = "[" + String.valueOf(l) + "," + String.valueOf(r) + "]"; | |
141 | + key = "[" + l + "," + r + "]"; | |
140 | 142 | } else { |
141 | - key = "[" + String.valueOf(l) + "]"; | |
143 | + key = "[" + l + "]"; | |
142 | 144 | } |
143 | 145 | result.put(key, list[i]); |
144 | 146 | } |
... | ... | @@ -172,13 +174,13 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> { |
172 | 174 | createStats(); |
173 | 175 | switch (sortType) { |
174 | 176 | case CodecUtil.STATS_TYPE_SUM: |
175 | - return new MtasDataItemNumberComparator<Long>(Math.round(stats.getSum()), sortDirection); | |
177 | + return new MtasDataItemNumberComparator<>(Math.round(stats.getSum()), sortDirection); | |
176 | 178 | case CodecUtil.STATS_TYPE_MAX: |
177 | - return new MtasDataItemNumberComparator<Long>(Math.round(stats.getMax()), sortDirection); | |
179 | + return new MtasDataItemNumberComparator<>(Math.round(stats.getMax()), sortDirection); | |
178 | 180 | case CodecUtil.STATS_TYPE_MIN: |
179 | - return new MtasDataItemNumberComparator<Long>(Math.round(stats.getMin()), sortDirection); | |
181 | + return new MtasDataItemNumberComparator<>(Math.round(stats.getMin()), sortDirection); | |
180 | 182 | case CodecUtil.STATS_TYPE_SUMSQ: |
181 | - return new MtasDataItemNumberComparator<Long>(Math.round(stats.getSumsq()), sortDirection); | |
183 | + return new MtasDataItemNumberComparator<>(Math.round(stats.getSumsq()), sortDirection); | |
182 | 184 | default: |
183 | 185 | return null; |
184 | 186 | } |
... | ... | @@ -194,26 +196,26 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> { |
194 | 196 | createStats(); |
195 | 197 | switch (sortType) { |
196 | 198 | case CodecUtil.STATS_TYPE_SUMOFLOGS: |
197 | - return new MtasDataItemNumberComparator<Double>( | |
199 | + return new MtasDataItemNumberComparator<>( | |
198 | 200 | stats.getN() * Math.log(stats.getGeometricMean()), sortDirection); |
199 | 201 | case CodecUtil.STATS_TYPE_MEAN: |
200 | - return new MtasDataItemNumberComparator<Double>(stats.getMean(), sortDirection); | |
202 | + return new MtasDataItemNumberComparator<>(stats.getMean(), sortDirection); | |
201 | 203 | case CodecUtil.STATS_TYPE_GEOMETRICMEAN: |
202 | - return new MtasDataItemNumberComparator<Double>(stats.getGeometricMean(), sortDirection); | |
204 | + return new MtasDataItemNumberComparator<>(stats.getGeometricMean(), sortDirection); | |
203 | 205 | case CodecUtil.STATS_TYPE_STANDARDDEVIATION: |
204 | - return new MtasDataItemNumberComparator<Double>(stats.getStandardDeviation(), sortDirection); | |
206 | + return new MtasDataItemNumberComparator<>(stats.getStandardDeviation(), sortDirection); | |
205 | 207 | case CodecUtil.STATS_TYPE_VARIANCE: |
206 | - return new MtasDataItemNumberComparator<Double>(stats.getVariance(), sortDirection); | |
208 | + return new MtasDataItemNumberComparator<>(stats.getVariance(), sortDirection); | |
207 | 209 | case CodecUtil.STATS_TYPE_POPULATIONVARIANCE: |
208 | - return new MtasDataItemNumberComparator<Double>(stats.getPopulationVariance(), sortDirection); | |
210 | + return new MtasDataItemNumberComparator<>(stats.getPopulationVariance(), sortDirection); | |
209 | 211 | case CodecUtil.STATS_TYPE_QUADRATICMEAN: |
210 | - return new MtasDataItemNumberComparator<Double>(stats.getQuadraticMean(), sortDirection); | |
212 | + return new MtasDataItemNumberComparator<>(stats.getQuadraticMean(), sortDirection); | |
211 | 213 | case CodecUtil.STATS_TYPE_KURTOSIS: |
212 | - return new MtasDataItemNumberComparator<Double>(stats.getKurtosis(), sortDirection); | |
214 | + return new MtasDataItemNumberComparator<>(stats.getKurtosis(), sortDirection); | |
213 | 215 | case CodecUtil.STATS_TYPE_MEDIAN: |
214 | - return new MtasDataItemNumberComparator<Double>(stats.getPercentile(50), sortDirection); | |
216 | + return new MtasDataItemNumberComparator<>(stats.getPercentile(50), sortDirection); | |
215 | 217 | case CodecUtil.STATS_TYPE_SKEWNESS: |
216 | - return new MtasDataItemNumberComparator<Double>(stats.getSkewness(), sortDirection); | |
218 | + return new MtasDataItemNumberComparator<>(stats.getSkewness(), sortDirection); | |
217 | 219 | default: |
218 | 220 | return null; |
219 | 221 | } |
... | ... |
src/mtas/codec/util/collector/MtasDataLongAdvanced.java
... | ... | @@ -2,6 +2,7 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.Collections; |
5 | +import java.util.Set; | |
5 | 6 | import java.util.TreeSet; |
6 | 7 | import org.apache.commons.lang.ArrayUtils; |
7 | 8 | import mtas.codec.util.CodecUtil; |
... | ... | @@ -52,10 +53,10 @@ public class MtasDataLongAdvanced extends MtasDataAdvanced<Long, Double> { |
52 | 53 | * @throws IOException |
53 | 54 | * Signals that an I/O exception has occurred. |
54 | 55 | */ |
55 | - public MtasDataLongAdvanced(String collectorType, TreeSet<String> statsItems, | |
56 | + public MtasDataLongAdvanced(String collectorType, Set<String> statsItems, | |
56 | 57 | String sortType, String sortDirection, Integer start, Integer number, |
57 | 58 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
58 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
59 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
59 | 60 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
60 | 61 | String segmentRegistration, String boundary) throws IOException { |
61 | 62 | super(collectorType, CodecUtil.DATA_TYPE_LONG, statsItems, sortType, |
... | ... |
src/mtas/codec/util/collector/MtasDataLongBasic.java
... | ... | @@ -2,6 +2,7 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.Collections; |
5 | +import java.util.Set; | |
5 | 6 | import java.util.TreeSet; |
6 | 7 | import org.apache.commons.lang.ArrayUtils; |
7 | 8 | import mtas.codec.util.CodecUtil; |
... | ... | @@ -52,10 +53,10 @@ public class MtasDataLongBasic extends MtasDataBasic<Long, Double> { |
52 | 53 | * @throws IOException |
53 | 54 | * Signals that an I/O exception has occurred. |
54 | 55 | */ |
55 | - public MtasDataLongBasic(String collectorType, TreeSet<String> statsItems, | |
56 | + public MtasDataLongBasic(String collectorType, Set<String> statsItems, | |
56 | 57 | String sortType, String sortDirection, Integer start, Integer number, |
57 | 58 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
58 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
59 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
59 | 60 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
60 | 61 | String segmentRegistration, String boundary) throws IOException { |
61 | 62 | super(collectorType, CodecUtil.DATA_TYPE_LONG, statsItems, sortType, |
... | ... |
src/mtas/codec/util/collector/MtasDataLongFull.java
... | ... | @@ -2,6 +2,7 @@ package mtas.codec.util.collector; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.Collections; |
5 | +import java.util.Set; | |
5 | 6 | import java.util.TreeSet; |
6 | 7 | import org.apache.commons.lang.ArrayUtils; |
7 | 8 | import mtas.codec.util.CodecUtil; |
... | ... | @@ -52,10 +53,10 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> { |
52 | 53 | * @throws IOException |
53 | 54 | * Signals that an I/O exception has occurred. |
54 | 55 | */ |
55 | - public MtasDataLongFull(String collectorType, TreeSet<String> statsItems, | |
56 | + public MtasDataLongFull(String collectorType, Set<String> statsItems, | |
56 | 57 | String sortType, String sortDirection, Integer start, Integer number, |
57 | 58 | String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, |
58 | - TreeSet<String>[] subStatsItems, String[] subSortTypes, | |
59 | + Set<String>[] subStatsItems, String[] subSortTypes, | |
59 | 60 | String[] subSortDirections, Integer[] subStart, Integer[] subNumber, |
60 | 61 | String segmentRegistration, String boundary) throws IOException { |
61 | 62 | super(collectorType, CodecUtil.DATA_TYPE_LONG, statsItems, sortType, |
... | ... |
src/mtas/search/spans/util/MtasSpanUniquePosition.java
src/mtas/solr/handler/component/MtasSolrSearchComponent.java
... | ... | @@ -5,6 +5,8 @@ import java.lang.reflect.InvocationTargetException; |
5 | 5 | import java.util.ArrayList; |
6 | 6 | import java.util.Collections; |
7 | 7 | import java.util.Iterator; |
8 | + | |
9 | +import mtas.analysis.MtasTokenizer; | |
8 | 10 | import mtas.codec.MtasCodecPostingsFormat; |
9 | 11 | import mtas.codec.util.CodecComponent.ComponentDocument; |
10 | 12 | import mtas.codec.util.CodecComponent.ComponentFacet; |
... | ... | @@ -28,6 +30,9 @@ import mtas.solr.handler.component.util.MtasSolrComponentList; |
28 | 30 | import mtas.solr.handler.component.util.MtasSolrComponentPrefix; |
29 | 31 | import mtas.solr.handler.component.util.MtasSolrComponentStats; |
30 | 32 | import mtas.solr.handler.component.util.MtasSolrComponentTermvector; |
33 | + | |
34 | +import org.apache.commons.logging.Log; | |
35 | +import org.apache.commons.logging.LogFactory; | |
31 | 36 | import org.apache.solr.common.util.NamedList; |
32 | 37 | import org.apache.solr.common.util.SimpleOrderedMap; |
33 | 38 | import org.apache.solr.handler.component.ResponseBuilder; |
... | ... | @@ -42,6 +47,9 @@ import org.apache.solr.search.SolrIndexSearcher; |
42 | 47 | */ |
43 | 48 | public class MtasSolrSearchComponent extends SearchComponent { |
44 | 49 | |
50 | + private static Log log = LogFactory.getLog(MtasSolrSearchComponent.class); | |
51 | + | |
52 | + | |
45 | 53 | /** The search component. */ |
46 | 54 | MtasSolrSearchComponent searchComponent; |
47 | 55 | |
... | ... | @@ -290,7 +298,7 @@ public class MtasSolrSearchComponent extends SearchComponent { |
290 | 298 | docListList, docSetList, mtasFields.list.get(field)); |
291 | 299 | } catch (IllegalAccessException | IllegalArgumentException |
292 | 300 | | InvocationTargetException e) { |
293 | - e.printStackTrace(); | |
301 | + log.error(e); | |
294 | 302 | throw new IOException(e.getMessage()); |
295 | 303 | } |
296 | 304 | } |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentDocument.java
... | ... | @@ -22,8 +22,10 @@ import mtas.solr.handler.component.MtasSolrSearchComponent; |
22 | 22 | /** |
23 | 23 | * The Class MtasSolrComponentDocument. |
24 | 24 | */ |
25 | -public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDocument> { | |
25 | +public class MtasSolrComponentDocument | |
26 | + implements MtasSolrComponent<ComponentDocument> { | |
26 | 27 | |
28 | + /** The log. */ | |
27 | 29 | private static Log log = LogFactory.getLog(MtasSolrComponentDocument.class); |
28 | 30 | |
29 | 31 | /** The Constant PARAM_MTAS_DOCUMENT. */ |
... | ... | @@ -76,15 +78,8 @@ public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDoc |
76 | 78 | // do nothing for now |
77 | 79 | } |
78 | 80 | |
79 | - /** | |
80 | - * Prepare. | |
81 | - * | |
82 | - * @param rb | |
83 | - * the rb | |
84 | - * @param mtasFields | |
85 | - * the mtas fields | |
86 | - * @throws IOException | |
87 | - * Signals that an I/O exception has occurred. | |
81 | + /* (non-Javadoc) | |
82 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr.handler.component.ResponseBuilder, mtas.codec.util.CodecComponent.ComponentFields) | |
88 | 83 | */ |
89 | 84 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
90 | 85 | throws IOException { |
... | ... | @@ -213,17 +208,11 @@ public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDoc |
213 | 208 | } |
214 | 209 | } |
215 | 210 | |
216 | - /** | |
217 | - * Creates the. | |
218 | - * | |
219 | - * @param document | |
220 | - * the document | |
221 | - * @return the simple ordered map | |
222 | - * @throws IOException | |
223 | - * Signals that an I/O exception has occurred. | |
211 | + /* (non-Javadoc) | |
212 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.CodecComponent.BasicComponent, java.lang.Boolean) | |
224 | 213 | */ |
225 | - public SimpleOrderedMap<Object> create(ComponentDocument document, Boolean encode) | |
226 | - throws IOException { | |
214 | + public SimpleOrderedMap<Object> create(ComponentDocument document, | |
215 | + Boolean encode) throws IOException { | |
227 | 216 | SimpleOrderedMap<Object> mtasDocumentResponse = new SimpleOrderedMap<>(); |
228 | 217 | mtasDocumentResponse.add("key", document.key); |
229 | 218 | ArrayList<NamedList<Object>> mtasDocumentItemResponses = new ArrayList<>(); |
... | ... | @@ -244,7 +233,7 @@ public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDoc |
244 | 233 | new MtasSolrMtasResult(list, |
245 | 234 | new String[] { list.getDataType(), list.getDataType() }, |
246 | 235 | new String[] { list.getStatsType(), list.getStatsType() }, |
247 | - new TreeSet[] { list.statsItems, list.statsItems }, | |
236 | + new Set[] { list.statsItems, list.statsItems }, | |
248 | 237 | new String[] { null, null }, new String[] { null, null }, |
249 | 238 | new Integer[] { 0, 0 }, new Integer[] { 1, 1 }, null)); |
250 | 239 | } else { |
... | ... | @@ -261,15 +250,8 @@ public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDoc |
261 | 250 | return mtasDocumentResponse; |
262 | 251 | } |
263 | 252 | |
264 | - /** | |
265 | - * Modify request. | |
266 | - * | |
267 | - * @param rb | |
268 | - * the rb | |
269 | - * @param who | |
270 | - * the who | |
271 | - * @param sreq | |
272 | - * the sreq | |
253 | + /* (non-Javadoc) | |
254 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache.solr.handler.component.ResponseBuilder, org.apache.solr.handler.component.SearchComponent, org.apache.solr.handler.component.ShardRequest) | |
273 | 255 | */ |
274 | 256 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
275 | 257 | ShardRequest sreq) { |
... | ... | @@ -294,11 +276,8 @@ public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDoc |
294 | 276 | |
295 | 277 | } |
296 | 278 | |
297 | - /** | |
298 | - * Finish stage. | |
299 | - * | |
300 | - * @param rb | |
301 | - * the rb | |
279 | + /* (non-Javadoc) | |
280 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.solr.handler.component.ResponseBuilder) | |
302 | 281 | */ |
303 | 282 | public void finishStage(ResponseBuilder rb) { |
304 | 283 | if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) |
... | ... | @@ -313,15 +292,8 @@ public class MtasSolrComponentDocument implements MtasSolrComponent<ComponentDoc |
313 | 292 | } |
314 | 293 | } |
315 | 294 | |
316 | - /** | |
317 | - * Distributed process. | |
318 | - * | |
319 | - * @param rb | |
320 | - * the rb | |
321 | - * @param mtasFields | |
322 | - * the mtas fields | |
323 | - * @throws IOException | |
324 | - * Signals that an I/O exception has occurred. | |
295 | + /* (non-Javadoc) | |
296 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.apache.solr.handler.component.ResponseBuilder, mtas.codec.util.CodecComponent.ComponentFields) | |
325 | 297 | */ |
326 | 298 | public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields) |
327 | 299 | throws IOException { |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentFacet.java
... | ... | @@ -3,8 +3,11 @@ package mtas.solr.handler.component.util; |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.ArrayList; |
5 | 5 | import java.util.HashMap; |
6 | +import java.util.Map.Entry; | |
6 | 7 | import java.util.Set; |
7 | 8 | |
9 | +import org.apache.commons.logging.Log; | |
10 | +import org.apache.commons.logging.LogFactory; | |
8 | 11 | import org.apache.lucene.document.FieldType.LegacyNumericType; |
9 | 12 | import org.apache.solr.common.util.NamedList; |
10 | 13 | import org.apache.solr.common.util.SimpleOrderedMap; |
... | ... | @@ -29,7 +32,11 @@ import mtas.solr.handler.component.MtasSolrSearchComponent; |
29 | 32 | * The Class MtasSolrComponentFacet. |
30 | 33 | */ |
31 | 34 | @SuppressWarnings("deprecation") |
32 | -public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> { | |
35 | +public class MtasSolrComponentFacet | |
36 | + implements MtasSolrComponent<ComponentFacet> { | |
37 | + | |
38 | + /** The log. */ | |
39 | + private static Log log = LogFactory.getLog(MtasSolrComponentFacet.class); | |
33 | 40 | |
34 | 41 | /** The search component. */ |
35 | 42 | MtasSolrSearchComponent searchComponent; |
... | ... | @@ -107,8 +114,13 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
107 | 114 | /** The Constant SUBNAME_MTAS_FACET_BASE_FUNCTION_TYPE. */ |
108 | 115 | public static final String SUBNAME_MTAS_FACET_BASE_FUNCTION_TYPE = "type"; |
109 | 116 | |
117 | + /** The Constant SUBNAME_MTAS_FACET_BASE_RANGE. */ | |
110 | 118 | public static final String SUBNAME_MTAS_FACET_BASE_RANGE = "range"; |
119 | + | |
120 | + /** The Constant SUBNAME_MTAS_FACET_BASE_RANGE_SIZE. */ | |
111 | 121 | public static final String SUBNAME_MTAS_FACET_BASE_RANGE_SIZE = "size"; |
122 | + | |
123 | + /** The Constant SUBNAME_MTAS_FACET_BASE_RANGE_BASE. */ | |
112 | 124 | public static final String SUBNAME_MTAS_FACET_BASE_RANGE_BASE = "base"; |
113 | 125 | |
114 | 126 | /** |
... | ... | @@ -121,21 +133,19 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
121 | 133 | this.searchComponent = searchComponent; |
122 | 134 | } |
123 | 135 | |
124 | - /** | |
125 | - * Prepare. | |
126 | - * | |
127 | - * @param rb | |
128 | - * the rb | |
129 | - * @param mtasFields | |
130 | - * the mtas fields | |
131 | - * @throws IOException | |
132 | - * Signals that an I/O exception has occurred. | |
136 | + /* | |
137 | + * (non-Javadoc) | |
138 | + * | |
139 | + * @see | |
140 | + * mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr. | |
141 | + * handler.component.ResponseBuilder, | |
142 | + * mtas.codec.util.CodecComponent.ComponentFields) | |
133 | 143 | */ |
134 | 144 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
135 | 145 | throws IOException { |
136 | 146 | Set<String> ids = MtasSolrResultUtil |
137 | 147 | .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_FACET); |
138 | - if (ids.size() > 0) { | |
148 | + if (!ids.isEmpty()) { | |
139 | 149 | int tmpCounter = 0; |
140 | 150 | String tmpValue; |
141 | 151 | String[] fields = new String[ids.size()]; |
... | ... | @@ -169,7 +179,7 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
169 | 179 | Set<String> qIds = MtasSolrResultUtil.getIdsFromParameters( |
170 | 180 | rb.req.getParams(), |
171 | 181 | PARAM_MTAS_FACET + "." + id + "." + NAME_MTAS_FACET_QUERY); |
172 | - if (qIds.size() > 0) { | |
182 | + if (!qIds.isEmpty()) { | |
173 | 183 | int tmpQCounter = 0; |
174 | 184 | queryTypes[tmpCounter] = new String[qIds.size()]; |
175 | 185 | queryValues[tmpCounter] = new String[qIds.size()]; |
... | ... | @@ -207,9 +217,9 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
207 | 217 | rb.req.getParams(), |
208 | 218 | PARAM_MTAS_FACET + "." + id + "." + NAME_MTAS_FACET_QUERY + "." |
209 | 219 | + qId + "." + SUBNAME_MTAS_FACET_QUERY_VARIABLE); |
210 | - queryVariables[tmpCounter][tmpQCounter] = new HashMap<String, String[]>(); | |
211 | - if (vIds.size() > 0) { | |
212 | - HashMap<String, ArrayList<String>> tmpVariables = new HashMap<String, ArrayList<String>>(); | |
220 | + queryVariables[tmpCounter][tmpQCounter] = new HashMap<>(); | |
221 | + if (!vIds.isEmpty()) { | |
222 | + HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>(); | |
213 | 223 | for (String vId : vIds) { |
214 | 224 | String name = rb.req.getParams().get(PARAM_MTAS_FACET + "." + id |
215 | 225 | + "." + NAME_MTAS_FACET_QUERY + "." + qId + "." |
... | ... | @@ -224,7 +234,7 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
224 | 234 | + SUBNAME_MTAS_FACET_QUERY_VARIABLE + "." + vId + "." |
225 | 235 | + SUBNAME_MTAS_FACET_QUERY_VARIABLE_VALUE, null); |
226 | 236 | if (value != null) { |
227 | - ArrayList<String> list = new ArrayList<String>(); | |
237 | + ArrayList<String> list = new ArrayList<>(); | |
228 | 238 | String[] subList = value.split("(?<!\\\\),"); |
229 | 239 | for (int i = 0; i < subList.length; i++) { |
230 | 240 | list.add( |
... | ... | @@ -234,10 +244,11 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
234 | 244 | } |
235 | 245 | } |
236 | 246 | } |
237 | - for (String name : tmpVariables.keySet()) { | |
238 | - queryVariables[tmpCounter][tmpQCounter].put(name, | |
239 | - tmpVariables.get(name) | |
240 | - .toArray(new String[tmpVariables.get(name).size()])); | |
247 | + for (Entry<String, ArrayList<String>> entry : tmpVariables | |
248 | + .entrySet()) { | |
249 | + queryVariables[tmpCounter][tmpQCounter].put(entry.getKey(), | |
250 | + entry.getValue() | |
251 | + .toArray(new String[entry.getValue().size()])); | |
241 | 252 | } |
242 | 253 | } |
243 | 254 | tmpQCounter++; |
... | ... | @@ -249,7 +260,7 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
249 | 260 | Set<String> bIds = MtasSolrResultUtil.getIdsFromParameters( |
250 | 261 | rb.req.getParams(), |
251 | 262 | PARAM_MTAS_FACET + "." + id + "." + NAME_MTAS_FACET_BASE); |
252 | - if (bIds.size() > 0) { | |
263 | + if (!bIds.isEmpty()) { | |
253 | 264 | int tmpBCounter = 0; |
254 | 265 | baseFields[tmpCounter] = new String[bIds.size()]; |
255 | 266 | baseFieldTypes[tmpCounter] = new String[bIds.size()]; |
... | ... | @@ -279,15 +290,16 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
279 | 290 | .get(PARAM_MTAS_FACET + "." + id + "." + NAME_MTAS_FACET_BASE |
280 | 291 | + "." + bId + "." + SUBNAME_MTAS_FACET_BASE_RANGE + "." |
281 | 292 | + SUBNAME_MTAS_FACET_BASE_RANGE_SIZE, null); |
282 | - baseRangeSizes[tmpCounter][tmpBCounter] = tmpValue == null | |
283 | - ? null : Double.parseDouble(tmpValue); | |
293 | + baseRangeSizes[tmpCounter][tmpBCounter] = tmpValue == null ? null | |
294 | + : Double.parseDouble(tmpValue); | |
284 | 295 | tmpValue = rb.req.getParams() |
285 | 296 | .get(PARAM_MTAS_FACET + "." + id + "." + NAME_MTAS_FACET_BASE |
286 | 297 | + "." + bId + "." + SUBNAME_MTAS_FACET_BASE_RANGE + "." |
287 | 298 | + SUBNAME_MTAS_FACET_BASE_RANGE_BASE, null); |
288 | - baseRangeBases[tmpCounter][tmpBCounter] = tmpValue == null ? null : Double.parseDouble(tmpValue); | |
289 | - baseSortTypes[tmpCounter][tmpBCounter] = rb.req | |
290 | - .getParams().get( | |
299 | + baseRangeBases[tmpCounter][tmpBCounter] = tmpValue == null ? null | |
300 | + : Double.parseDouble(tmpValue); | |
301 | + baseSortTypes[tmpCounter][tmpBCounter] = rb.req.getParams() | |
302 | + .get( | |
291 | 303 | PARAM_MTAS_FACET + "." + id + "." + NAME_MTAS_FACET_BASE |
292 | 304 | + "." + bId + "." + SUBNAME_MTAS_FACET_BASE_SORT_TYPE, |
293 | 305 | null); |
... | ... | @@ -372,7 +384,7 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
372 | 384 | for (int i = 0; i < fields.length; i++) { |
373 | 385 | ComponentField cf = mtasFields.list.get(fields[i]); |
374 | 386 | int queryNumber = queryValues[i].length; |
375 | - MtasSpanQuery ql[] = new MtasSpanQuery[queryNumber]; | |
387 | + MtasSpanQuery[] ql = new MtasSpanQuery[queryNumber]; | |
376 | 388 | for (int j = 0; j < queryNumber; j++) { |
377 | 389 | Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null) |
378 | 390 | ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]); |
... | ... | @@ -403,119 +415,116 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
403 | 415 | } |
404 | 416 | } |
405 | 417 | |
406 | - /** | |
407 | - * Modify request. | |
408 | - * | |
409 | - * @param rb | |
410 | - * the rb | |
411 | - * @param who | |
412 | - * the who | |
413 | - * @param sreq | |
414 | - * the sreq | |
418 | + /* | |
419 | + * (non-Javadoc) | |
420 | + * | |
421 | + * @see | |
422 | + * mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache | |
423 | + * .solr.handler.component.ResponseBuilder, | |
424 | + * org.apache.solr.handler.component.SearchComponent, | |
425 | + * org.apache.solr.handler.component.ShardRequest) | |
415 | 426 | */ |
416 | 427 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
417 | 428 | ShardRequest sreq) { |
418 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
419 | - if (sreq.params.getBool(PARAM_MTAS_FACET, false)) { | |
420 | - if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
421 | - // do nothing | |
422 | - } else { | |
423 | - // remove prefix for other requests | |
424 | - Set<String> keys = MtasSolrResultUtil | |
425 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_FACET); | |
426 | - sreq.params.remove(PARAM_MTAS_FACET); | |
427 | - for (String key : keys) { | |
429 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
430 | + && sreq.params.getBool(PARAM_MTAS_FACET, false)) { | |
431 | + if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
432 | + // do nothing | |
433 | + } else { | |
434 | + // remove prefix for other requests | |
435 | + Set<String> keys = MtasSolrResultUtil | |
436 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_FACET); | |
437 | + sreq.params.remove(PARAM_MTAS_FACET); | |
438 | + for (String key : keys) { | |
439 | + sreq.params.remove( | |
440 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_FIELD); | |
441 | + sreq.params | |
442 | + .remove(PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_KEY); | |
443 | + Set<String> subKeys = MtasSolrResultUtil.getIdsFromParameters( | |
444 | + rb.req.getParams(), | |
445 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY); | |
446 | + for (String subKey : subKeys) { | |
428 | 447 | sreq.params.remove( |
429 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_FIELD); | |
448 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY + "." | |
449 | + + subKey + "." + SUBNAME_MTAS_FACET_QUERY_TYPE); | |
430 | 450 | sreq.params.remove( |
431 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_KEY); | |
432 | - Set<String> subKeys = MtasSolrResultUtil.getIdsFromParameters( | |
433 | - rb.req.getParams(), | |
434 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY); | |
435 | - for (String subKey : subKeys) { | |
436 | - sreq.params.remove( | |
437 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY | |
438 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_QUERY_TYPE); | |
439 | - sreq.params.remove( | |
440 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY | |
441 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_QUERY_VALUE); | |
442 | - sreq.params.remove( | |
443 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY | |
444 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_QUERY_PREFIX); | |
445 | - sreq.params.remove( | |
446 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY | |
447 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_QUERY_IGNORE); | |
451 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY + "." | |
452 | + + subKey + "." + SUBNAME_MTAS_FACET_QUERY_VALUE); | |
453 | + sreq.params.remove( | |
454 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY + "." | |
455 | + + subKey + "." + SUBNAME_MTAS_FACET_QUERY_PREFIX); | |
456 | + sreq.params.remove( | |
457 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY + "." | |
458 | + + subKey + "." + SUBNAME_MTAS_FACET_QUERY_IGNORE); | |
459 | + sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
460 | + + NAME_MTAS_FACET_QUERY + "." + subKey + "." | |
461 | + + SUBNAME_MTAS_FACET_QUERY_MAXIMUM_IGNORE_LENGTH); | |
462 | + Set<String> subSubKeys = MtasSolrResultUtil | |
463 | + .getIdsFromParameters(rb.req.getParams(), | |
464 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY | |
465 | + + "." + subKey + "." | |
466 | + + SUBNAME_MTAS_FACET_QUERY_VARIABLE); | |
467 | + for (String subSubKey : subSubKeys) { | |
448 | 468 | sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." |
449 | 469 | + NAME_MTAS_FACET_QUERY + "." + subKey + "." |
450 | - + SUBNAME_MTAS_FACET_QUERY_MAXIMUM_IGNORE_LENGTH); | |
451 | - Set<String> subSubKeys = MtasSolrResultUtil | |
452 | - .getIdsFromParameters(rb.req.getParams(), | |
453 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_QUERY | |
454 | - + "." + subKey + "." | |
455 | - + SUBNAME_MTAS_FACET_QUERY_VARIABLE); | |
456 | - for (String subSubKey : subSubKeys) { | |
457 | - sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
458 | - + NAME_MTAS_FACET_QUERY + "." + subKey + "." | |
459 | - + SUBNAME_MTAS_FACET_QUERY_VARIABLE + "." + subSubKey + "." | |
460 | - + SUBNAME_MTAS_FACET_QUERY_VARIABLE_NAME); | |
461 | - sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
462 | - + NAME_MTAS_FACET_QUERY + "." + subKey + "." | |
463 | - + SUBNAME_MTAS_FACET_QUERY_VARIABLE + "." + subSubKey + "." | |
464 | - + SUBNAME_MTAS_FACET_QUERY_VARIABLE_VALUE); | |
465 | - } | |
470 | + + SUBNAME_MTAS_FACET_QUERY_VARIABLE + "." + subSubKey + "." | |
471 | + + SUBNAME_MTAS_FACET_QUERY_VARIABLE_NAME); | |
472 | + sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
473 | + + NAME_MTAS_FACET_QUERY + "." + subKey + "." | |
474 | + + SUBNAME_MTAS_FACET_QUERY_VARIABLE + "." + subSubKey + "." | |
475 | + + SUBNAME_MTAS_FACET_QUERY_VARIABLE_VALUE); | |
466 | 476 | } |
467 | - subKeys = MtasSolrResultUtil.getIdsFromParameters( | |
468 | - rb.req.getParams(), | |
469 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE); | |
470 | - for (String subKey : subKeys) { | |
471 | - sreq.params.remove( | |
472 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
473 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_FIELD); | |
474 | - sreq.params.remove( | |
475 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
476 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_TYPE); | |
477 | - sreq.params.remove( | |
478 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
479 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_RANGE + "." | |
480 | - + SUBNAME_MTAS_FACET_BASE_RANGE_SIZE); | |
481 | - sreq.params.remove( | |
482 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
483 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_RANGE + "." | |
484 | - + SUBNAME_MTAS_FACET_BASE_RANGE_BASE); | |
485 | - sreq.params.remove( | |
486 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
487 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_MAXIMUM); | |
488 | - sreq.params.remove( | |
489 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
490 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_MINIMUM); | |
491 | - sreq.params.remove( | |
492 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
493 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_NUMBER); | |
477 | + } | |
478 | + subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(), | |
479 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE); | |
480 | + for (String subKey : subKeys) { | |
481 | + sreq.params.remove( | |
482 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
483 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_FIELD); | |
484 | + sreq.params.remove( | |
485 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
486 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_TYPE); | |
487 | + sreq.params.remove( | |
488 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
489 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_RANGE + "." | |
490 | + + SUBNAME_MTAS_FACET_BASE_RANGE_SIZE); | |
491 | + sreq.params.remove( | |
492 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
493 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_RANGE + "." | |
494 | + + SUBNAME_MTAS_FACET_BASE_RANGE_BASE); | |
495 | + sreq.params.remove( | |
496 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
497 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_MAXIMUM); | |
498 | + sreq.params.remove( | |
499 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
500 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_MINIMUM); | |
501 | + sreq.params.remove( | |
502 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
503 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_NUMBER); | |
504 | + sreq.params.remove( | |
505 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
506 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_SORT_DIRECTION); | |
507 | + sreq.params.remove( | |
508 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE + "." | |
509 | + + subKey + "." + SUBNAME_MTAS_FACET_BASE_SORT_TYPE); | |
510 | + Set<String> subSubKeys = MtasSolrResultUtil | |
511 | + .getIdsFromParameters(rb.req.getParams(), | |
512 | + PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
513 | + + "." + subKey + "." | |
514 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION); | |
515 | + for (String subSubKey : subSubKeys) { | |
494 | 516 | sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." |
495 | 517 | + NAME_MTAS_FACET_BASE + "." + subKey + "." |
496 | - + SUBNAME_MTAS_FACET_BASE_SORT_DIRECTION); | |
497 | - sreq.params.remove( | |
498 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
499 | - + "." + subKey + "." + SUBNAME_MTAS_FACET_BASE_SORT_TYPE); | |
500 | - Set<String> subSubKeys = MtasSolrResultUtil | |
501 | - .getIdsFromParameters(rb.req.getParams(), | |
502 | - PARAM_MTAS_FACET + "." + key + "." + NAME_MTAS_FACET_BASE | |
503 | - + "." + subKey + "." | |
504 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION); | |
505 | - for (String subSubKey : subSubKeys) { | |
506 | - sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
507 | - + NAME_MTAS_FACET_BASE + "." + subKey + "." | |
508 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION + "." + subSubKey + "." | |
509 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION_EXPRESSION); | |
510 | - sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
511 | - + NAME_MTAS_FACET_BASE + "." + subKey + "." | |
512 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION + "." + subSubKey + "." | |
513 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION_KEY); | |
514 | - sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
515 | - + NAME_MTAS_FACET_BASE + "." + subKey + "." | |
516 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION + "." + subSubKey + "." | |
517 | - + SUBNAME_MTAS_FACET_BASE_FUNCTION_TYPE); | |
518 | - } | |
518 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION + "." + subSubKey + "." | |
519 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION_EXPRESSION); | |
520 | + sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
521 | + + NAME_MTAS_FACET_BASE + "." + subKey + "." | |
522 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION + "." + subSubKey + "." | |
523 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION_KEY); | |
524 | + sreq.params.remove(PARAM_MTAS_FACET + "." + key + "." | |
525 | + + NAME_MTAS_FACET_BASE + "." + subKey + "." | |
526 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION + "." + subSubKey + "." | |
527 | + + SUBNAME_MTAS_FACET_BASE_FUNCTION_TYPE); | |
519 | 528 | } |
520 | 529 | } |
521 | 530 | } |
... | ... | @@ -523,22 +532,18 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
523 | 532 | } |
524 | 533 | } |
525 | 534 | |
526 | - /** | |
527 | - * Creates the. | |
528 | - * | |
529 | - * @param facet | |
530 | - * the facet | |
531 | - * @param encode | |
532 | - * the encode | |
533 | - * @return the simple ordered map | |
534 | - * @throws IOException | |
535 | - * Signals that an I/O exception has occurred. | |
535 | + /* | |
536 | + * (non-Javadoc) | |
537 | + * | |
538 | + * @see | |
539 | + * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util. | |
540 | + * CodecComponent.BasicComponent, java.lang.Boolean) | |
536 | 541 | */ |
537 | 542 | public SimpleOrderedMap<Object> create(ComponentFacet facet, Boolean encode) |
538 | 543 | throws IOException { |
539 | 544 | SimpleOrderedMap<Object> mtasFacetResponse = new SimpleOrderedMap<>(); |
540 | 545 | mtasFacetResponse.add("key", facet.key); |
541 | - HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>>(); | |
546 | + HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>(); | |
542 | 547 | for (int i = 0; i < facet.baseFields.length; i++) { |
543 | 548 | if (facet.baseFunctionList[i] != null) { |
544 | 549 | for (MtasDataCollector<?, ?> functionDataCollector : facet.baseFunctionList[i] |
... | ... | @@ -546,7 +551,7 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
546 | 551 | SubComponentFunction[] tmpSubComponentFunctionList = facet.baseFunctionList[i] |
547 | 552 | .get(functionDataCollector); |
548 | 553 | if (tmpSubComponentFunctionList != null) { |
549 | - HashMap<String, MtasSolrMtasResult> tmpList = new HashMap<String, MtasSolrMtasResult>(); | |
554 | + HashMap<String, MtasSolrMtasResult> tmpList = new HashMap<>(); | |
550 | 555 | for (SubComponentFunction tmpSubComponentFunction : tmpSubComponentFunctionList) { |
551 | 556 | tmpList.put(tmpSubComponentFunction.key, |
552 | 557 | new MtasSolrMtasResult(tmpSubComponentFunction.dataCollector, |
... | ... | @@ -573,32 +578,33 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
573 | 578 | return mtasFacetResponse; |
574 | 579 | } |
575 | 580 | |
576 | - /** | |
577 | - * Finish stage. | |
578 | - * | |
579 | - * @param rb | |
580 | - * the rb | |
581 | + /* | |
582 | + * (non-Javadoc) | |
583 | + * | |
584 | + * @see | |
585 | + * mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache. | |
586 | + * solr.handler.component.ResponseBuilder) | |
581 | 587 | */ |
582 | 588 | @SuppressWarnings("unchecked") |
583 | 589 | public void finishStage(ResponseBuilder rb) { |
584 | - if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
585 | - if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
586 | - && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
587 | - for (ShardRequest sreq : rb.finished) { | |
588 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
589 | - && sreq.params.getBool(PARAM_MTAS_FACET, false)) { | |
590 | - for (ShardResponse shardResponse : sreq.responses) { | |
591 | - NamedList<Object> response = shardResponse.getSolrResponse() | |
592 | - .getResponse(); | |
593 | - try { | |
594 | - ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response | |
595 | - .findRecursive("mtas", "facet"); | |
596 | - if (data != null) { | |
597 | - MtasSolrResultUtil.decode(data); | |
598 | - } | |
599 | - } catch (ClassCastException e) { | |
600 | - // shouldn't happen | |
590 | + if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
591 | + && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
592 | + && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
593 | + for (ShardRequest sreq : rb.finished) { | |
594 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
595 | + && sreq.params.getBool(PARAM_MTAS_FACET, false)) { | |
596 | + for (ShardResponse shardResponse : sreq.responses) { | |
597 | + NamedList<Object> response = shardResponse.getSolrResponse() | |
598 | + .getResponse(); | |
599 | + try { | |
600 | + ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response | |
601 | + .findRecursive("mtas", "facet"); | |
602 | + if (data != null) { | |
603 | + MtasSolrResultUtil.decode(data); | |
601 | 604 | } |
605 | + } catch (ClassCastException e) { | |
606 | + log.debug(e); | |
607 | + // shouldn't happen | |
602 | 608 | } |
603 | 609 | } |
604 | 610 | } |
... | ... | @@ -606,15 +612,13 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
606 | 612 | } |
607 | 613 | } |
608 | 614 | |
609 | - /** | |
610 | - * Distributed process. | |
611 | - * | |
612 | - * @param rb | |
613 | - * the rb | |
614 | - * @param mtasFields | |
615 | - * the mtas fields | |
616 | - * @throws IOException | |
617 | - * Signals that an I/O exception has occurred. | |
615 | + /* | |
616 | + * (non-Javadoc) | |
617 | + * | |
618 | + * @see | |
619 | + * mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org. | |
620 | + * apache.solr.handler.component.ResponseBuilder, | |
621 | + * mtas.codec.util.CodecComponent.ComponentFields) | |
618 | 622 | */ |
619 | 623 | @SuppressWarnings("unchecked") |
620 | 624 | public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields) |
... | ... | @@ -623,20 +627,22 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
623 | 627 | NamedList<Object> mtasResponse = null; |
624 | 628 | try { |
625 | 629 | mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas"); |
626 | - if (mtasResponse != null) { | |
627 | - ArrayList<Object> mtasResponseFacet; | |
628 | - try { | |
629 | - mtasResponseFacet = (ArrayList<Object>) mtasResponse.get("facet"); | |
630 | - if (mtasResponseFacet != null) { | |
631 | - MtasSolrResultUtil.rewrite(mtasResponseFacet); | |
632 | - } | |
633 | - } catch (ClassCastException e) { | |
634 | - mtasResponseFacet = null; | |
635 | - } | |
636 | - } | |
637 | 630 | } catch (ClassCastException e) { |
631 | + log.debug(e); | |
638 | 632 | mtasResponse = null; |
639 | 633 | } |
634 | + if (mtasResponse != null) { | |
635 | + ArrayList<Object> mtasResponseFacet; | |
636 | + try { | |
637 | + mtasResponseFacet = (ArrayList<Object>) mtasResponse.get("facet"); | |
638 | + if (mtasResponseFacet != null) { | |
639 | + MtasSolrResultUtil.rewrite(mtasResponseFacet); | |
640 | + } | |
641 | + } catch (ClassCastException e) { | |
642 | + log.debug(e); | |
643 | + mtasResponse.remove("facet"); | |
644 | + } | |
645 | + } | |
640 | 646 | } |
641 | 647 | |
642 | 648 | /** |
... | ... | @@ -651,18 +657,16 @@ public class MtasSolrComponentFacet implements MtasSolrComponent<ComponentFacet> |
651 | 657 | private String getFieldType(IndexSchema schema, String field) { |
652 | 658 | SchemaField sf = schema.getField(field); |
653 | 659 | FieldType ft = sf.getType(); |
654 | - if (ft != null) { | |
655 | - if (ft.getNumericType() != null) { | |
656 | - LegacyNumericType nt = ft.getNumericType(); | |
657 | - if (nt.equals(LegacyNumericType.INT)) { | |
658 | - return ComponentFacet.TYPE_INTEGER; | |
659 | - } else if (nt.equals(LegacyNumericType.DOUBLE)) { | |
660 | - return ComponentFacet.TYPE_DOUBLE; | |
661 | - } else if (nt.equals(LegacyNumericType.LONG)) { | |
662 | - return ComponentFacet.TYPE_LONG; | |
663 | - } else if (nt.equals(LegacyNumericType.FLOAT)) { | |
664 | - return ComponentFacet.TYPE_FLOAT; | |
665 | - } | |
660 | + if (ft != null && ft.getNumericType() != null) { | |
661 | + LegacyNumericType nt = ft.getNumericType(); | |
662 | + if (nt.equals(LegacyNumericType.INT)) { | |
663 | + return ComponentFacet.TYPE_INTEGER; | |
664 | + } else if (nt.equals(LegacyNumericType.DOUBLE)) { | |
665 | + return ComponentFacet.TYPE_DOUBLE; | |
666 | + } else if (nt.equals(LegacyNumericType.LONG)) { | |
667 | + return ComponentFacet.TYPE_LONG; | |
668 | + } else if (nt.equals(LegacyNumericType.FLOAT)) { | |
669 | + return ComponentFacet.TYPE_FLOAT; | |
666 | 670 | } |
667 | 671 | } |
668 | 672 | return ComponentFacet.TYPE_STRING; |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentGroup.java
... | ... | @@ -3,10 +3,13 @@ package mtas.solr.handler.component.util; |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.ArrayList; |
5 | 5 | import java.util.HashMap; |
6 | +import java.util.Map.Entry; | |
6 | 7 | import java.util.Set; |
7 | 8 | import java.util.SortedSet; |
8 | 9 | import java.util.TreeSet; |
9 | 10 | |
11 | +import org.apache.commons.logging.Log; | |
12 | +import org.apache.commons.logging.LogFactory; | |
10 | 13 | import org.apache.solr.common.params.SolrParams; |
11 | 14 | import org.apache.solr.common.util.NamedList; |
12 | 15 | import org.apache.solr.common.util.SimpleOrderedMap; |
... | ... | @@ -24,7 +27,11 @@ import mtas.solr.handler.component.MtasSolrSearchComponent; |
24 | 27 | /** |
25 | 28 | * The Class MtasSolrComponentGroup. |
26 | 29 | */ |
27 | -public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> { | |
30 | +public class MtasSolrComponentGroup | |
31 | + implements MtasSolrComponent<ComponentGroup> { | |
32 | + | |
33 | + /** The log. */ | |
34 | + private static Log log = LogFactory.getLog(MtasSolrComponentGroup.class); | |
28 | 35 | |
29 | 36 | /** The search component. */ |
30 | 37 | MtasSolrSearchComponent searchComponent; |
... | ... | @@ -44,19 +51,20 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
44 | 51 | |
45 | 52 | /** The Constant NAME_MTAS_GROUP_QUERY_PREFIX. */ |
46 | 53 | public static final String NAME_MTAS_GROUP_QUERY_PREFIX = "query.prefix"; |
47 | - | |
54 | + | |
48 | 55 | /** The Constant NAME_MTAS_GROUP_QUERY_IGNORE. */ |
49 | 56 | public static final String NAME_MTAS_GROUP_QUERY_IGNORE = "query.ignore"; |
50 | - | |
51 | - public static final String NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumQueryLength"; | |
52 | 57 | |
53 | - /** The Constant NAME_MTAS_KWIC_QUERY_VARIABLE. */ | |
58 | + /** The Constant NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH. */ | |
59 | + public static final String NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumIgnoreLength"; | |
60 | + | |
61 | + /** The Constant NAME_MTAS_GROUP_QUERY_VARIABLE. */ | |
54 | 62 | public static final String NAME_MTAS_GROUP_QUERY_VARIABLE = "query.variable"; |
55 | 63 | |
56 | - /** The Constant NAME_MTAS_KWIC_QUERY_VARIABLE_NAME. */ | |
64 | + /** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME. */ | |
57 | 65 | public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME = "name"; |
58 | 66 | |
59 | - /** The Constant NAME_MTAS_KWIC_QUERY_VARIABLE_VALUE. */ | |
67 | + /** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE. */ | |
60 | 68 | public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE = "value"; |
61 | 69 | |
62 | 70 | /** The Constant NAME_MTAS_GROUP_KEY. */ |
... | ... | @@ -98,28 +106,25 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
98 | 106 | /** |
99 | 107 | * Instantiates a new mtas solr component group. |
100 | 108 | * |
101 | - * @param searchComponent | |
102 | - * the search component | |
109 | + * @param searchComponent the search component | |
103 | 110 | */ |
104 | 111 | public MtasSolrComponentGroup(MtasSolrSearchComponent searchComponent) { |
105 | 112 | this.searchComponent = searchComponent; |
106 | 113 | } |
107 | 114 | |
108 | - /** | |
109 | - * Prepare. | |
110 | - * | |
111 | - * @param rb | |
112 | - * the rb | |
113 | - * @param mtasFields | |
114 | - * the mtas fields | |
115 | - * @throws IOException | |
116 | - * Signals that an I/O exception has occurred. | |
115 | + /* | |
116 | + * (non-Javadoc) | |
117 | + * | |
118 | + * @see | |
119 | + * mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr. | |
120 | + * handler.component.ResponseBuilder, | |
121 | + * mtas.codec.util.CodecComponent.ComponentFields) | |
117 | 122 | */ |
118 | 123 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
119 | 124 | throws IOException { |
120 | 125 | Set<String> ids = MtasSolrResultUtil |
121 | 126 | .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP); |
122 | - if (ids.size() > 0) { | |
127 | + if (!ids.isEmpty()) { | |
123 | 128 | int tmpCounter = 0; |
124 | 129 | String[] fields = new String[ids.size()]; |
125 | 130 | String[] queryTypes = new String[ids.size()]; |
... | ... | @@ -164,15 +169,15 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
164 | 169 | queryIgnores[tmpCounter] = rb.req.getParams().get( |
165 | 170 | PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_IGNORE, |
166 | 171 | null); |
167 | - queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams().get( | |
168 | - PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH, | |
169 | - null); | |
172 | + queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams() | |
173 | + .get(PARAM_MTAS_GROUP + "." + id + "." | |
174 | + + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH, null); | |
170 | 175 | Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters( |
171 | 176 | rb.req.getParams(), |
172 | 177 | PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VARIABLE); |
173 | - queryVariables[tmpCounter] = new HashMap<String, String[]>(); | |
174 | - if (vIds.size() > 0) { | |
175 | - HashMap<String, ArrayList<String>> tmpVariables = new HashMap<String, ArrayList<String>>(); | |
178 | + queryVariables[tmpCounter] = new HashMap<>(); | |
179 | + if (!vIds.isEmpty()) { | |
180 | + HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>(); | |
176 | 181 | for (String vId : vIds) { |
177 | 182 | String name = rb.req.getParams() |
178 | 183 | .get(PARAM_MTAS_GROUP + "." + id + "." |
... | ... | @@ -187,7 +192,7 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
187 | 192 | + NAME_MTAS_GROUP_QUERY_VARIABLE + "." + vId + "." |
188 | 193 | + SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE, null); |
189 | 194 | if (value != null) { |
190 | - ArrayList<String> list = new ArrayList<String>(); | |
195 | + ArrayList<String> list = new ArrayList<>(); | |
191 | 196 | String[] subList = value.split("(?<!\\\\),"); |
192 | 197 | for (int i = 0; i < subList.length; i++) { |
193 | 198 | list.add( |
... | ... | @@ -197,9 +202,10 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
197 | 202 | } |
198 | 203 | } |
199 | 204 | } |
200 | - for (String name : tmpVariables.keySet()) { | |
201 | - queryVariables[tmpCounter].put(name, tmpVariables.get(name) | |
202 | - .toArray(new String[tmpVariables.get(name).size()])); | |
205 | + for (Entry<String, ArrayList<String>> entry : tmpVariables | |
206 | + .entrySet()) { | |
207 | + queryVariables[tmpCounter].put(entry.getKey(), | |
208 | + entry.getValue().toArray(new String[entry.getValue().size()])); | |
203 | 209 | } |
204 | 210 | } |
205 | 211 | groupingHitInsidePrefixes[tmpCounter] = null; |
... | ... | @@ -307,8 +313,7 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
307 | 313 | : keys[i].trim(); |
308 | 314 | int number = (numbers[i] == null) || (numbers[i].isEmpty()) |
309 | 315 | ? DEFAULT_NUMBER : Integer.parseInt(numbers[i]); |
310 | - mtasFields.list.get(fields[i]).groupList.add(new ComponentGroup(q, | |
311 | - key, | |
316 | + mtasFields.list.get(fields[i]).groupList.add(new ComponentGroup(q, key, | |
312 | 317 | number, groupingHitInsidePrefixes[i], |
313 | 318 | groupingHitInsideLeftPosition[i], groupingHitInsideLeftPrefixes[i], |
314 | 319 | groupingHitInsideRightPosition[i], |
... | ... | @@ -324,20 +329,15 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
324 | 329 | /** |
325 | 330 | * Prepare. |
326 | 331 | * |
327 | - * @param solrParams | |
328 | - * the solr params | |
329 | - * @param gids | |
330 | - * the gids | |
331 | - * @param name | |
332 | - * the name | |
333 | - * @param positions | |
334 | - * the positions | |
335 | - * @param prefixes | |
336 | - * the prefixes | |
332 | + * @param solrParams the solr params | |
333 | + * @param gids the gids | |
334 | + * @param name the name | |
335 | + * @param positions the positions | |
336 | + * @param prefixes the prefixes | |
337 | 337 | */ |
338 | 338 | private void prepare(SolrParams solrParams, SortedSet<String> gids, |
339 | 339 | String name, String[] positions, String[] prefixes) { |
340 | - if (gids.size() > 0) { | |
340 | + if (!gids.isEmpty()) { | |
341 | 341 | int tmpSubCounter = 0; |
342 | 342 | for (String gid : gids) { |
343 | 343 | positions[tmpSubCounter] = solrParams.get( |
... | ... | @@ -349,114 +349,108 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - /** | |
353 | - * Modify request. | |
354 | - * | |
355 | - * @param rb | |
356 | - * the rb | |
357 | - * @param who | |
358 | - * the who | |
359 | - * @param sreq | |
360 | - * the sreq | |
352 | + /* | |
353 | + * (non-Javadoc) | |
354 | + * | |
355 | + * @see | |
356 | + * mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache | |
357 | + * .solr.handler.component.ResponseBuilder, | |
358 | + * org.apache.solr.handler.component.SearchComponent, | |
359 | + * org.apache.solr.handler.component.ShardRequest) | |
361 | 360 | */ |
362 | 361 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
363 | 362 | ShardRequest sreq) { |
364 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
365 | - if (sreq.params.getBool(PARAM_MTAS_GROUP, false)) { | |
366 | - if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
367 | - // do nothing | |
368 | - } else { | |
369 | - // remove prefix for other requests | |
370 | - Set<String> keys = MtasSolrResultUtil | |
371 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP); | |
372 | - sreq.params.remove(PARAM_MTAS_GROUP); | |
373 | - Set<String> subKeys; | |
374 | - for (String key : keys) { | |
375 | - sreq.params.remove( | |
376 | - PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_FIELD); | |
377 | - sreq.params.remove( | |
378 | - PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_KEY); | |
363 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
364 | + && sreq.params.getBool(PARAM_MTAS_GROUP, false)) { | |
365 | + if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
366 | + // do nothing | |
367 | + } else { | |
368 | + // remove prefix for other requests | |
369 | + Set<String> keys = MtasSolrResultUtil | |
370 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP); | |
371 | + sreq.params.remove(PARAM_MTAS_GROUP); | |
372 | + Set<String> subKeys; | |
373 | + for (String key : keys) { | |
374 | + sreq.params.remove( | |
375 | + PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_FIELD); | |
376 | + sreq.params | |
377 | + .remove(PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_KEY); | |
378 | + sreq.params.remove( | |
379 | + PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_TYPE); | |
380 | + sreq.params.remove( | |
381 | + PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_VALUE); | |
382 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
383 | + + NAME_MTAS_GROUP_QUERY_PREFIX); | |
384 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
385 | + + NAME_MTAS_GROUP_QUERY_IGNORE); | |
386 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
387 | + + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH); | |
388 | + subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(), | |
389 | + PARAM_MTAS_GROUP + "." + key + "." | |
390 | + + NAME_MTAS_GROUP_GROUPING_LEFT); | |
391 | + for (String subKey : subKeys) { | |
379 | 392 | sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." |
380 | - + NAME_MTAS_GROUP_QUERY_TYPE); | |
393 | + + NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "." | |
394 | + + NAME_MTAS_GROUP_GROUPING_POSITION); | |
381 | 395 | sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." |
382 | - + NAME_MTAS_GROUP_QUERY_VALUE); | |
396 | + + NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "." | |
397 | + + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
398 | + } | |
399 | + subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(), | |
400 | + PARAM_MTAS_GROUP + "." + key + "." | |
401 | + + NAME_MTAS_GROUP_GROUPING_RIGHT); | |
402 | + for (String subKey : subKeys) { | |
383 | 403 | sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." |
384 | - + NAME_MTAS_GROUP_QUERY_PREFIX); | |
404 | + + NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "." | |
405 | + + NAME_MTAS_GROUP_GROUPING_POSITION); | |
385 | 406 | sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." |
386 | - + NAME_MTAS_GROUP_QUERY_IGNORE); | |
407 | + + NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "." | |
408 | + + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
409 | + } | |
410 | + subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(), | |
411 | + PARAM_MTAS_GROUP + "." + key + "." | |
412 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE); | |
413 | + for (String subKey : subKeys) { | |
387 | 414 | sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." |
388 | - + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH); | |
389 | - subKeys = MtasSolrResultUtil | |
390 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP + "." | |
391 | - + key + "." + NAME_MTAS_GROUP_GROUPING_LEFT); | |
392 | - for (String subKey : subKeys) { | |
393 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
394 | - + NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "." | |
395 | - + NAME_MTAS_GROUP_GROUPING_POSITION); | |
396 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
397 | - + NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "." | |
398 | - + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
399 | - } | |
400 | - subKeys = MtasSolrResultUtil | |
401 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP + "." | |
402 | - + key + "." + NAME_MTAS_GROUP_GROUPING_RIGHT); | |
403 | - for (String subKey : subKeys) { | |
404 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
405 | - + NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "." | |
406 | - + NAME_MTAS_GROUP_GROUPING_POSITION); | |
407 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
408 | - + NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "." | |
409 | - + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
410 | - } | |
411 | - subKeys = MtasSolrResultUtil | |
412 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP + "." | |
413 | - + key + "." + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE); | |
414 | - for (String subKey : subKeys) { | |
415 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
416 | - + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "." | |
417 | - + NAME_MTAS_GROUP_GROUPING_POSITION); | |
418 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
419 | - + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "." | |
420 | - + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
421 | - } | |
422 | - subKeys = MtasSolrResultUtil | |
423 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP + "." | |
424 | - + key + "." + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT); | |
425 | - for (String subKey : subKeys) { | |
426 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
427 | - + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey | |
428 | - + "." + NAME_MTAS_GROUP_GROUPING_POSITION); | |
429 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
430 | - + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey | |
431 | - + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
432 | - } | |
433 | - subKeys = MtasSolrResultUtil | |
434 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP + "." | |
435 | - + key + "." + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT); | |
436 | - for (String subKey : subKeys) { | |
437 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
438 | - + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey | |
439 | - + "." + NAME_MTAS_GROUP_GROUPING_POSITION); | |
440 | - sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
441 | - + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey | |
442 | - + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
443 | - } | |
415 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "." | |
416 | + + NAME_MTAS_GROUP_GROUPING_POSITION); | |
417 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
418 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "." | |
419 | + + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
420 | + } | |
421 | + subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(), | |
422 | + PARAM_MTAS_GROUP + "." + key + "." | |
423 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT); | |
424 | + for (String subKey : subKeys) { | |
425 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
426 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey + "." | |
427 | + + NAME_MTAS_GROUP_GROUPING_POSITION); | |
428 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
429 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey + "." | |
430 | + + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
431 | + } | |
432 | + subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(), | |
433 | + PARAM_MTAS_GROUP + "." + key + "." | |
434 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT); | |
435 | + for (String subKey : subKeys) { | |
436 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
437 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey + "." | |
438 | + + NAME_MTAS_GROUP_GROUPING_POSITION); | |
439 | + sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "." | |
440 | + + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey + "." | |
441 | + + NAME_MTAS_GROUP_GROUPING_PREFIXES); | |
444 | 442 | } |
445 | 443 | } |
446 | 444 | } |
447 | 445 | } |
448 | 446 | } |
449 | 447 | |
450 | - /** | |
451 | - * Creates the. | |
452 | - * | |
453 | - * @param group | |
454 | - * the group | |
455 | - * @param encode | |
456 | - * the encode | |
457 | - * @return the simple ordered map | |
458 | - * @throws IOException | |
459 | - * Signals that an I/O exception has occurred. | |
448 | + /* | |
449 | + * (non-Javadoc) | |
450 | + * | |
451 | + * @see | |
452 | + * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util. | |
453 | + * CodecComponent.BasicComponent, java.lang.Boolean) | |
460 | 454 | */ |
461 | 455 | @SuppressWarnings("unchecked") |
462 | 456 | public SimpleOrderedMap<Object> create(ComponentGroup group, Boolean encode) |
... | ... | @@ -477,32 +471,33 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
477 | 471 | return mtasGroupResponse; |
478 | 472 | } |
479 | 473 | |
480 | - /** | |
481 | - * Finish stage. | |
482 | - * | |
483 | - * @param rb | |
484 | - * the rb | |
474 | + /* | |
475 | + * (non-Javadoc) | |
476 | + * | |
477 | + * @see | |
478 | + * mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache. | |
479 | + * solr.handler.component.ResponseBuilder) | |
485 | 480 | */ |
486 | 481 | @SuppressWarnings("unchecked") |
487 | 482 | public void finishStage(ResponseBuilder rb) { |
488 | - if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
489 | - if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
490 | - && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
491 | - for (ShardRequest sreq : rb.finished) { | |
492 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
493 | - && sreq.params.getBool(PARAM_MTAS_GROUP, false)) { | |
494 | - for (ShardResponse shardResponse : sreq.responses) { | |
495 | - NamedList<Object> response = shardResponse.getSolrResponse() | |
496 | - .getResponse(); | |
497 | - try { | |
498 | - ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response | |
499 | - .findRecursive("mtas", "group"); | |
500 | - if (data != null) { | |
501 | - MtasSolrResultUtil.decode(data); | |
502 | - } | |
503 | - } catch (ClassCastException e) { | |
504 | - // shouldn't happen | |
483 | + if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
484 | + && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
485 | + && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
486 | + for (ShardRequest sreq : rb.finished) { | |
487 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
488 | + && sreq.params.getBool(PARAM_MTAS_GROUP, false)) { | |
489 | + for (ShardResponse shardResponse : sreq.responses) { | |
490 | + NamedList<Object> response = shardResponse.getSolrResponse() | |
491 | + .getResponse(); | |
492 | + try { | |
493 | + ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response | |
494 | + .findRecursive("mtas", "group"); | |
495 | + if (data != null) { | |
496 | + MtasSolrResultUtil.decode(data); | |
505 | 497 | } |
498 | + } catch (ClassCastException e) { | |
499 | + log.debug(e); | |
500 | + // shouldn't happen | |
506 | 501 | } |
507 | 502 | } |
508 | 503 | } |
... | ... | @@ -510,15 +505,13 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
510 | 505 | } |
511 | 506 | } |
512 | 507 | |
513 | - /** | |
514 | - * Distributed process. | |
515 | - * | |
516 | - * @param rb | |
517 | - * the rb | |
518 | - * @param mtasFields | |
519 | - * the mtas fields | |
520 | - * @throws IOException | |
521 | - * Signals that an I/O exception has occurred. | |
508 | + /* | |
509 | + * (non-Javadoc) | |
510 | + * | |
511 | + * @see | |
512 | + * mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org. | |
513 | + * apache.solr.handler.component.ResponseBuilder, | |
514 | + * mtas.codec.util.CodecComponent.ComponentFields) | |
522 | 515 | */ |
523 | 516 | @SuppressWarnings("unchecked") |
524 | 517 | public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields) |
... | ... | @@ -527,20 +520,22 @@ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> |
527 | 520 | NamedList<Object> mtasResponse = null; |
528 | 521 | try { |
529 | 522 | mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas"); |
530 | - if (mtasResponse != null) { | |
531 | - ArrayList<Object> mtasResponseGroup; | |
532 | - try { | |
533 | - mtasResponseGroup = (ArrayList<Object>) mtasResponse.get("group"); | |
534 | - if (mtasResponseGroup != null) { | |
535 | - MtasSolrResultUtil.rewrite(mtasResponseGroup); | |
536 | - } | |
537 | - } catch (ClassCastException e) { | |
538 | - mtasResponseGroup = null; | |
539 | - } | |
540 | - } | |
541 | 523 | } catch (ClassCastException e) { |
524 | + log.debug(e); | |
542 | 525 | mtasResponse = null; |
543 | 526 | } |
527 | + if (mtasResponse != null) { | |
528 | + ArrayList<Object> mtasResponseGroup; | |
529 | + try { | |
530 | + mtasResponseGroup = (ArrayList<Object>) mtasResponse.get("group"); | |
531 | + if (mtasResponseGroup != null) { | |
532 | + MtasSolrResultUtil.rewrite(mtasResponseGroup); | |
533 | + } | |
534 | + } catch (ClassCastException e) { | |
535 | + log.debug(e); | |
536 | + mtasResponse.remove("group"); | |
537 | + } | |
538 | + } | |
544 | 539 | } |
545 | 540 | |
546 | 541 | } |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentJoin.java
... | ... | @@ -5,6 +5,8 @@ import java.util.Arrays; |
5 | 5 | import java.util.HashSet; |
6 | 6 | import java.util.Set; |
7 | 7 | |
8 | +import org.apache.commons.logging.Log; | |
9 | +import org.apache.commons.logging.LogFactory; | |
8 | 10 | import org.apache.solr.common.util.NamedList; |
9 | 11 | import org.apache.solr.common.util.SimpleOrderedMap; |
10 | 12 | import org.apache.solr.handler.component.ResponseBuilder; |
... | ... | @@ -12,44 +14,41 @@ import org.apache.solr.handler.component.SearchComponent; |
12 | 14 | import org.apache.solr.handler.component.ShardRequest; |
13 | 15 | import org.apache.solr.handler.component.ShardResponse; |
14 | 16 | |
17 | +import mtas.codec.util.CodecComponent.BasicComponent; | |
15 | 18 | import mtas.codec.util.CodecComponent.ComponentFields; |
16 | 19 | import mtas.codec.util.CodecComponent.ComponentJoin; |
17 | 20 | import mtas.solr.handler.component.MtasSolrSearchComponent; |
18 | 21 | |
19 | 22 | /** |
20 | - * The Class MtasSolrComponentFacet. | |
23 | + * The Class MtasSolrComponentJoin. | |
21 | 24 | */ |
22 | 25 | @SuppressWarnings("deprecation") |
23 | -public class MtasSolrComponentJoin { | |
26 | +public class MtasSolrComponentJoin implements MtasSolrComponent<ComponentJoin> { | |
24 | 27 | |
25 | - /** The search component. */ | |
26 | - MtasSolrSearchComponent searchComponent; | |
28 | + /** The log. */ | |
29 | + private static Log log = LogFactory.getLog(MtasSolrComponentJoin.class); | |
27 | 30 | |
28 | - /** The Constant PARAM_MTAS_FACET. */ | |
31 | + /** The Constant PARAM_MTAS_JOIN. */ | |
29 | 32 | public static final String PARAM_MTAS_JOIN = MtasSolrSearchComponent.PARAM_MTAS |
30 | 33 | + ".join"; |
31 | 34 | |
35 | + /** The Constant NAME_MTAS_JOIN_FIELD. */ | |
32 | 36 | public static final String NAME_MTAS_JOIN_FIELD = "field"; |
33 | 37 | |
34 | 38 | /** |
35 | - * Instantiates a new mtas solr component facet. | |
39 | + * Instantiates a new mtas solr component join. | |
36 | 40 | * |
37 | - * @param searchComponent | |
38 | - * the search component | |
41 | + * @param searchComponent the search component | |
39 | 42 | */ |
40 | 43 | public MtasSolrComponentJoin(MtasSolrSearchComponent searchComponent) { |
41 | - this.searchComponent = searchComponent; | |
42 | 44 | } |
43 | 45 | |
44 | 46 | /** |
45 | 47 | * Prepare. |
46 | 48 | * |
47 | - * @param rb | |
48 | - * the rb | |
49 | - * @param mtasFields | |
50 | - * the mtas fields | |
51 | - * @throws IOException | |
52 | - * Signals that an I/O exception has occurred. | |
49 | + * @param rb the rb | |
50 | + * @param mtasFields the mtas fields | |
51 | + * @throws IOException Signals that an I/O exception has occurred. | |
53 | 52 | */ |
54 | 53 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
55 | 54 | throws IOException { |
... | ... | @@ -68,27 +67,23 @@ public class MtasSolrComponentJoin { |
68 | 67 | /** |
69 | 68 | * Modify request. |
70 | 69 | * |
71 | - * @param rb | |
72 | - * the rb | |
73 | - * @param who | |
74 | - * the who | |
75 | - * @param sreq | |
76 | - * the sreq | |
70 | + * @param rb the rb | |
71 | + * @param who the who | |
72 | + * @param sreq the sreq | |
77 | 73 | */ |
78 | 74 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
79 | 75 | ShardRequest sreq) { |
80 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
81 | - if (sreq.params.getBool(PARAM_MTAS_JOIN, false)) { | |
82 | - if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
83 | - // do nothing | |
84 | - } else { | |
85 | - // remove for other requests | |
86 | - Set<String> keys = MtasSolrResultUtil | |
87 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_JOIN); | |
88 | - sreq.params.remove(PARAM_MTAS_JOIN); | |
89 | - for (String key : keys) { | |
90 | - sreq.params.remove(PARAM_MTAS_JOIN + "." + key); | |
91 | - } | |
76 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
77 | + && sreq.params.getBool(PARAM_MTAS_JOIN, false)) { | |
78 | + if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
79 | + // do nothing | |
80 | + } else { | |
81 | + // remove for other requests | |
82 | + Set<String> keys = MtasSolrResultUtil | |
83 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_JOIN); | |
84 | + sreq.params.remove(PARAM_MTAS_JOIN); | |
85 | + for (String key : keys) { | |
86 | + sreq.params.remove(PARAM_MTAS_JOIN + "." + key); | |
92 | 87 | } |
93 | 88 | } |
94 | 89 | } |
... | ... | @@ -97,45 +92,49 @@ public class MtasSolrComponentJoin { |
97 | 92 | /** |
98 | 93 | * Creates the. |
99 | 94 | * |
100 | - * @param facet | |
101 | - * the facet | |
102 | - * @param encode | |
103 | - * the encode | |
104 | - * @return the simple ordered map | |
105 | - * @throws IOException | |
106 | - * Signals that an I/O exception has occurred. | |
95 | + * @param join the join | |
96 | + * @param encode the encode | |
97 | + * @return the object | |
98 | + * @throws IOException Signals that an I/O exception has occurred. | |
107 | 99 | */ |
108 | - public Object create(ComponentJoin join, Boolean encode) | |
109 | - throws IOException { | |
100 | + public SimpleOrderedMap<Object> create(ComponentJoin join, Boolean encode) throws IOException { | |
110 | 101 | MtasSolrJoinResult data = new MtasSolrJoinResult(join); |
102 | + SimpleOrderedMap<Object> mtasJoinResponse = new SimpleOrderedMap<>(); | |
111 | 103 | if (encode) { |
112 | - return MtasSolrResultUtil.encode(data); | |
104 | + mtasJoinResponse.add("_encoded_data", MtasSolrResultUtil.encode(data)); | |
113 | 105 | } else { |
114 | - return data.rewrite(); | |
106 | + mtasJoinResponse.add("data", data.rewrite()); | |
115 | 107 | } |
108 | + return mtasJoinResponse; | |
116 | 109 | } |
117 | 110 | |
111 | + /** | |
112 | + * Finish stage. | |
113 | + * | |
114 | + * @param rb the rb | |
115 | + */ | |
118 | 116 | @SuppressWarnings("unchecked") |
119 | 117 | public void finishStage(ResponseBuilder rb) { |
120 | - if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
121 | - if (rb.stage == MtasSolrSearchComponent.STAGE_JOIN) { | |
122 | - for (ShardRequest sreq : rb.finished) { | |
123 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
124 | - && sreq.params.getBool(PARAM_MTAS_JOIN, false)) { | |
125 | - for (ShardResponse shardResponse : sreq.responses) { | |
126 | - NamedList<Object> response = shardResponse.getSolrResponse() | |
127 | - .getResponse(); | |
128 | - try { | |
129 | - Object data = response | |
130 | - .findRecursive("mtas", "join"); | |
131 | - if (data != null && data instanceof String) { | |
132 | - NamedList<Object> mtasResponse = (NamedList<Object>) response.get("mtas"); | |
133 | - mtasResponse.remove("join"); | |
134 | - mtasResponse.add("join", MtasSolrResultUtil.decode((String) data)); | |
135 | - } | |
136 | - } catch (ClassCastException e) { | |
137 | - // shouldn't happen | |
138 | - } | |
118 | + if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
119 | + && rb.stage == MtasSolrSearchComponent.STAGE_JOIN) { | |
120 | + for (ShardRequest sreq : rb.finished) { | |
121 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
122 | + && sreq.params.getBool(PARAM_MTAS_JOIN, false)) { | |
123 | + for (ShardResponse shardResponse : sreq.responses) { | |
124 | + NamedList<Object> response = shardResponse.getSolrResponse() | |
125 | + .getResponse(); | |
126 | + try { | |
127 | + Object data = response.findRecursive("mtas", "join"); | |
128 | + if (data != null && data instanceof String) { | |
129 | + NamedList<Object> mtasResponse = (NamedList<Object>) response | |
130 | + .get("mtas"); | |
131 | + mtasResponse.remove("join"); | |
132 | + mtasResponse.add("join", | |
133 | + MtasSolrResultUtil.decode((String) data)); | |
134 | + } | |
135 | + } catch (ClassCastException e) { | |
136 | + log.debug(e); | |
137 | + // shouldn't happen | |
139 | 138 | } |
140 | 139 | } |
141 | 140 | } |
... | ... | @@ -143,6 +142,13 @@ public class MtasSolrComponentJoin { |
143 | 142 | } |
144 | 143 | } |
145 | 144 | |
145 | + /** | |
146 | + * Distributed process. | |
147 | + * | |
148 | + * @param rb the rb | |
149 | + * @param mtasFields the mtas fields | |
150 | + * @throws IOException Signals that an I/O exception has occurred. | |
151 | + */ | |
146 | 152 | @SuppressWarnings("unchecked") |
147 | 153 | public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields) |
148 | 154 | throws IOException { |
... | ... | @@ -150,25 +156,37 @@ public class MtasSolrComponentJoin { |
150 | 156 | NamedList<Object> mtasResponse = null; |
151 | 157 | try { |
152 | 158 | mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas"); |
153 | - if (mtasResponse != null) { | |
154 | - MtasSolrJoinResult mtasSolrJoinResult; | |
155 | - try { | |
156 | - mtasSolrJoinResult = (MtasSolrJoinResult) mtasResponse.get("join"); | |
157 | - if (mtasSolrJoinResult != null) { | |
158 | - mtasResponse.removeAll("join"); | |
159 | - mtasResponse.add("join", mtasSolrJoinResult.rewrite()); | |
160 | - } | |
161 | - } catch (ClassCastException e) { | |
162 | - mtasSolrJoinResult = null; | |
163 | - } | |
164 | - } | |
165 | 159 | } catch (ClassCastException e) { |
160 | + log.debug(e); | |
166 | 161 | mtasResponse = null; |
167 | 162 | } |
163 | + if (mtasResponse != null) { | |
164 | + MtasSolrJoinResult mtasSolrJoinResult; | |
165 | + try { | |
166 | + mtasSolrJoinResult = (MtasSolrJoinResult) mtasResponse.get("join"); | |
167 | + if (mtasSolrJoinResult != null) { | |
168 | + mtasResponse.removeAll("join"); | |
169 | + mtasResponse.add("join", mtasSolrJoinResult.rewrite()); | |
170 | + } | |
171 | + } catch (ClassCastException e) { | |
172 | + log.debug(e); | |
173 | + mtasResponse.remove("join"); | |
174 | + } | |
175 | + } | |
168 | 176 | } |
169 | - | |
177 | + | |
178 | + /** | |
179 | + * Creates the key from request. | |
180 | + * | |
181 | + * @param rb the rb | |
182 | + * @return the string | |
183 | + */ | |
170 | 184 | private String createKeyFromRequest(ResponseBuilder rb) { |
171 | 185 | return rb.req.getParams().toQueryString(); |
172 | 186 | } |
173 | 187 | |
188 | + | |
189 | + | |
190 | + | |
191 | + | |
174 | 192 | } |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentKwic.java
... | ... | @@ -3,6 +3,7 @@ package mtas.solr.handler.component.util; |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.ArrayList; |
5 | 5 | import java.util.HashMap; |
6 | +import java.util.Map.Entry; | |
6 | 7 | import java.util.Set; |
7 | 8 | import java.util.TreeMap; |
8 | 9 | |
... | ... | @@ -27,9 +28,6 @@ import mtas.solr.handler.component.MtasSolrSearchComponent; |
27 | 28 | */ |
28 | 29 | public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
29 | 30 | |
30 | - /** The search component. */ | |
31 | - MtasSolrSearchComponent searchComponent; | |
32 | - | |
33 | 31 | /** The Constant PARAM_MTAS_KWIC. */ |
34 | 32 | public static final String PARAM_MTAS_KWIC = MtasSolrSearchComponent.PARAM_MTAS |
35 | 33 | + ".kwic"; |
... | ... | @@ -50,7 +48,7 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
50 | 48 | public static final String NAME_MTAS_KWIC_QUERY_IGNORE = "query.ignore"; |
51 | 49 | |
52 | 50 | /** The Constant NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH. */ |
53 | - public static final String NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumQueryLength"; | |
51 | + public static final String NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumIgnoreLength"; | |
54 | 52 | |
55 | 53 | /** The Constant NAME_MTAS_KWIC_QUERY_VARIABLE. */ |
56 | 54 | public static final String NAME_MTAS_KWIC_QUERY_VARIABLE = "query.variable"; |
... | ... | @@ -85,16 +83,17 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
85 | 83 | /** |
86 | 84 | * Instantiates a new mtas solr component kwic. |
87 | 85 | * |
88 | - * @param searchComponent the search component | |
86 | + * @param searchComponent | |
87 | + * the search component | |
89 | 88 | */ |
90 | 89 | public MtasSolrComponentKwic(MtasSolrSearchComponent searchComponent) { |
91 | - this.searchComponent = searchComponent; | |
92 | 90 | } |
93 | 91 | |
94 | 92 | /** |
95 | 93 | * Gets the positive integer. |
96 | 94 | * |
97 | - * @param number the number | |
95 | + * @param number | |
96 | + * the number | |
98 | 97 | * @return the positive integer |
99 | 98 | */ |
100 | 99 | private int getPositiveInteger(String number) { |
... | ... | @@ -108,15 +107,18 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
108 | 107 | /** |
109 | 108 | * Prepare. |
110 | 109 | * |
111 | - * @param rb the rb | |
112 | - * @param mtasFields the mtas fields | |
113 | - * @throws IOException Signals that an I/O exception has occurred. | |
110 | + * @param rb | |
111 | + * the rb | |
112 | + * @param mtasFields | |
113 | + * the mtas fields | |
114 | + * @throws IOException | |
115 | + * Signals that an I/O exception has occurred. | |
114 | 116 | */ |
115 | 117 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
116 | 118 | throws IOException { |
117 | 119 | Set<String> ids = MtasSolrResultUtil |
118 | 120 | .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC); |
119 | - if (ids.size() > 0) { | |
121 | + if (!ids.isEmpty()) { | |
120 | 122 | int tmpCounter = 0; |
121 | 123 | String[] fields = new String[ids.size()]; |
122 | 124 | String[] queryTypes = new String[ids.size()]; |
... | ... | @@ -152,9 +154,9 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
152 | 154 | Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters( |
153 | 155 | rb.req.getParams(), |
154 | 156 | PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VARIABLE); |
155 | - queryVariables[tmpCounter] = new HashMap<String, String[]>(); | |
156 | - if (vIds.size() > 0) { | |
157 | - HashMap<String, ArrayList<String>> tmpVariables = new HashMap<String, ArrayList<String>>(); | |
157 | + queryVariables[tmpCounter] = new HashMap<>(); | |
158 | + if (!vIds.isEmpty()) { | |
159 | + HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>(); | |
158 | 160 | for (String vId : vIds) { |
159 | 161 | String name = rb.req.getParams().get( |
160 | 162 | PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VARIABLE |
... | ... | @@ -169,7 +171,7 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
169 | 171 | + NAME_MTAS_KWIC_QUERY_VARIABLE + "." + vId + "." |
170 | 172 | + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE, null); |
171 | 173 | if (value != null) { |
172 | - ArrayList<String> list = new ArrayList<String>(); | |
174 | + ArrayList<String> list = new ArrayList<>(); | |
173 | 175 | String[] subList = value.split("(?<!\\\\),"); |
174 | 176 | for (int i = 0; i < subList.length; i++) { |
175 | 177 | list.add( |
... | ... | @@ -179,9 +181,10 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
179 | 181 | } |
180 | 182 | } |
181 | 183 | } |
182 | - for (String name : tmpVariables.keySet()) { | |
183 | - queryVariables[tmpCounter].put(name, tmpVariables.get(name) | |
184 | - .toArray(new String[tmpVariables.get(name).size()])); | |
184 | + for (Entry<String, ArrayList<String>> entry : tmpVariables | |
185 | + .entrySet()) { | |
186 | + queryVariables[tmpCounter].put(entry.getKey(), | |
187 | + entry.getValue().toArray(new String[entry.getValue().size()])); | |
185 | 188 | } |
186 | 189 | } |
187 | 190 | keys[tmpCounter] = rb.req.getParams() |
... | ... | @@ -271,44 +274,49 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
271 | 274 | /** |
272 | 275 | * Creates the. |
273 | 276 | * |
274 | - * @param kwic the kwic | |
277 | + * @param kwic | |
278 | + * the kwic | |
275 | 279 | * @return the simple ordered map |
276 | 280 | */ |
277 | 281 | public SimpleOrderedMap<Object> create(ComponentKwic kwic, Boolean encode) { |
278 | 282 | SimpleOrderedMap<Object> mtasKwicResponse = new SimpleOrderedMap<>(); |
279 | 283 | mtasKwicResponse.add("key", kwic.key); |
280 | - ArrayList<NamedList<Object>> mtasKwicItemResponses = new ArrayList<NamedList<Object>>(); | |
284 | + ArrayList<NamedList<Object>> mtasKwicItemResponses = new ArrayList<>(); | |
281 | 285 | if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)) { |
282 | 286 | for (int docId : kwic.hits.keySet()) { |
283 | 287 | NamedList<Object> mtasKwicItemResponse = new SimpleOrderedMap<>(); |
284 | 288 | ArrayList<KwicHit> list = kwic.hits.get(docId); |
285 | - ArrayList<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<NamedList<Object>>(); | |
289 | + ArrayList<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<>(); | |
286 | 290 | for (KwicHit h : list) { |
287 | 291 | NamedList<Object> mtasKwicItemResponseItem = new SimpleOrderedMap<>(); |
288 | - TreeMap<Integer, ArrayList<ArrayList<String>>> hitData = new TreeMap<Integer, ArrayList<ArrayList<String>>>(); | |
289 | - TreeMap<Integer, ArrayList<ArrayList<String>>> leftData = null, | |
290 | - rightData = null; | |
292 | + TreeMap<Integer, ArrayList<ArrayList<String>>> hitData = new TreeMap<>(); | |
293 | + TreeMap<Integer, ArrayList<ArrayList<String>>> leftData = null; | |
294 | + TreeMap<Integer, ArrayList<ArrayList<String>>> rightData = null; | |
291 | 295 | if (kwic.left > 0) { |
292 | - leftData = new TreeMap<Integer, ArrayList<ArrayList<String>>>(); | |
296 | + leftData = new TreeMap<>(); | |
293 | 297 | } |
294 | 298 | if (kwic.right > 0) { |
295 | - rightData = new TreeMap<Integer, ArrayList<ArrayList<String>>>(); | |
299 | + rightData = new TreeMap<>(); | |
296 | 300 | } |
297 | 301 | for (int position = Math.max(0, |
298 | 302 | h.startPosition - kwic.left); position <= (h.endPosition |
299 | 303 | + kwic.right); position++) { |
300 | 304 | if (h.hits.containsKey(position)) { |
301 | - ArrayList<ArrayList<String>> hitDataItem = new ArrayList<ArrayList<String>>(); | |
305 | + ArrayList<ArrayList<String>> hitDataItem = new ArrayList<>(); | |
302 | 306 | for (String term : h.hits.get(position)) { |
303 | - ArrayList<String> hitDataSubItem = new ArrayList<String>(); | |
307 | + ArrayList<String> hitDataSubItem = new ArrayList<>(); | |
304 | 308 | hitDataSubItem.add(CodecUtil.termPrefix(term)); |
305 | 309 | hitDataSubItem.add(CodecUtil.termValue(term)); |
306 | 310 | hitDataItem.add(hitDataSubItem); |
307 | 311 | } |
308 | 312 | if (position < h.startPosition) { |
309 | - leftData.put(position, hitDataItem); | |
313 | + if (leftData != null) { | |
314 | + leftData.put(position, hitDataItem); | |
315 | + } | |
310 | 316 | } else if (position > h.endPosition) { |
311 | - rightData.put(position, hitDataItem); | |
317 | + if (rightData != null) { | |
318 | + rightData.put(position, hitDataItem); | |
319 | + } | |
312 | 320 | } else { |
313 | 321 | hitData.put(position, hitDataItem); |
314 | 322 | } |
... | ... | @@ -336,12 +344,12 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
336 | 344 | for (int docId : kwic.tokens.keySet()) { |
337 | 345 | NamedList<Object> mtasKwicItemResponse = new SimpleOrderedMap<>(); |
338 | 346 | ArrayList<KwicToken> list = kwic.tokens.get(docId); |
339 | - ArrayList<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<NamedList<Object>>(); | |
347 | + ArrayList<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<>(); | |
340 | 348 | for (KwicToken k : list) { |
341 | 349 | NamedList<Object> mtasKwicItemResponseItem = new SimpleOrderedMap<>(); |
342 | 350 | mtasKwicItemResponseItem.add("startPosition", k.startPosition); |
343 | 351 | mtasKwicItemResponseItem.add("endPosition", k.endPosition); |
344 | - ArrayList<NamedList<Object>> mtasKwicItemResponseItemTokens = new ArrayList<NamedList<Object>>(); | |
352 | + ArrayList<NamedList<Object>> mtasKwicItemResponseItemTokens = new ArrayList<>(); | |
345 | 353 | for (MtasToken token : k.tokens) { |
346 | 354 | NamedList<Object> mtasKwicItemResponseItemToken = new SimpleOrderedMap<>(); |
347 | 355 | if (token.getId() != null) { |
... | ... | @@ -401,46 +409,48 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
401 | 409 | /** |
402 | 410 | * Modify request. |
403 | 411 | * |
404 | - * @param rb the rb | |
405 | - * @param who the who | |
406 | - * @param sreq the sreq | |
412 | + * @param rb | |
413 | + * the rb | |
414 | + * @param who | |
415 | + * the who | |
416 | + * @param sreq | |
417 | + * the sreq | |
407 | 418 | */ |
408 | 419 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
409 | 420 | ShardRequest sreq) { |
410 | 421 | if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { |
411 | - if (sreq.params.getBool(PARAM_MTAS_KWIC, false)) { | |
412 | - if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) { | |
413 | - // do nothing | |
414 | - } else { | |
415 | - Set<String> keys = MtasSolrResultUtil | |
416 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC); | |
417 | - sreq.params.remove(PARAM_MTAS_KWIC); | |
418 | - for (String key : keys) { | |
419 | - sreq.params.remove( | |
420 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_FIELD); | |
421 | - sreq.params.remove( | |
422 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_TYPE); | |
423 | - sreq.params.remove( | |
424 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_VALUE); | |
425 | - sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "." | |
426 | - + NAME_MTAS_KWIC_QUERY_PREFIX); | |
427 | - sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "." | |
428 | - + NAME_MTAS_KWIC_QUERY_IGNORE); | |
429 | - sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "." | |
430 | - + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH); | |
431 | - sreq.params | |
432 | - .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_KEY); | |
433 | - sreq.params.remove( | |
434 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_PREFIX); | |
435 | - sreq.params.remove( | |
436 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_NUMBER); | |
437 | - sreq.params.remove( | |
438 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_LEFT); | |
439 | - sreq.params.remove( | |
440 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_RIGHT); | |
441 | - sreq.params.remove( | |
442 | - PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_OUTPUT); | |
443 | - } | |
422 | + if (sreq.params.getBool(PARAM_MTAS_KWIC, false) | |
423 | + && (sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) { | |
424 | + // do nothing | |
425 | + } else { | |
426 | + Set<String> keys = MtasSolrResultUtil | |
427 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC); | |
428 | + sreq.params.remove(PARAM_MTAS_KWIC); | |
429 | + for (String key : keys) { | |
430 | + sreq.params | |
431 | + .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_FIELD); | |
432 | + sreq.params.remove( | |
433 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_TYPE); | |
434 | + sreq.params.remove( | |
435 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_VALUE); | |
436 | + sreq.params.remove( | |
437 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_PREFIX); | |
438 | + sreq.params.remove( | |
439 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_IGNORE); | |
440 | + sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "." | |
441 | + + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH); | |
442 | + sreq.params | |
443 | + .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_KEY); | |
444 | + sreq.params.remove( | |
445 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_PREFIX); | |
446 | + sreq.params.remove( | |
447 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_NUMBER); | |
448 | + sreq.params | |
449 | + .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_LEFT); | |
450 | + sreq.params | |
451 | + .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_RIGHT); | |
452 | + sreq.params.remove( | |
453 | + PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_OUTPUT); | |
444 | 454 | } |
445 | 455 | } |
446 | 456 | } |
... | ... | @@ -449,25 +459,25 @@ public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> { |
449 | 459 | /** |
450 | 460 | * Finish stage. |
451 | 461 | * |
452 | - * @param rb the rb | |
462 | + * @param rb | |
463 | + * the rb | |
453 | 464 | */ |
454 | 465 | public void finishStage(ResponseBuilder rb) { |
455 | - if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
456 | - if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
457 | - && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
458 | - for (ShardRequest sreq : rb.finished) { | |
459 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
460 | - && sreq.params.getBool(PARAM_MTAS_KWIC, false)) { | |
461 | - // nothing to do | |
462 | - } | |
466 | + if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
467 | + && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
468 | + && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
469 | + for (ShardRequest sreq : rb.finished) { | |
470 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
471 | + && sreq.params.getBool(PARAM_MTAS_KWIC, false)) { | |
472 | + // nothing to do | |
463 | 473 | } |
464 | 474 | } |
465 | 475 | } |
466 | 476 | } |
467 | - | |
477 | + | |
468 | 478 | public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields) |
469 | 479 | throws IOException { |
470 | - //nothing to do | |
480 | + // nothing to do | |
471 | 481 | } |
472 | 482 | |
473 | 483 | } |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentList.java
... | ... | @@ -3,9 +3,12 @@ package mtas.solr.handler.component.util; |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.ArrayList; |
5 | 5 | import java.util.HashMap; |
6 | +import java.util.Map.Entry; | |
6 | 7 | import java.util.Set; |
7 | 8 | import java.util.TreeMap; |
8 | 9 | |
10 | +import org.apache.commons.logging.Log; | |
11 | +import org.apache.commons.logging.LogFactory; | |
9 | 12 | import org.apache.solr.common.params.ModifiableSolrParams; |
10 | 13 | import org.apache.solr.common.util.NamedList; |
11 | 14 | import org.apache.solr.common.util.SimpleOrderedMap; |
... | ... | @@ -29,6 +32,8 @@ import mtas.solr.handler.component.MtasSolrSearchComponent; |
29 | 32 | */ |
30 | 33 | public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
31 | 34 | |
35 | + private static Log log = LogFactory.getLog(MtasSolrComponentList.class); | |
36 | + | |
32 | 37 | /** The search component. */ |
33 | 38 | MtasSolrSearchComponent searchComponent; |
34 | 39 | |
... | ... | @@ -47,7 +52,7 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
47 | 52 | |
48 | 53 | /** The Constant NAME_MTAS_LIST_QUERY_PREFIX. */ |
49 | 54 | public static final String NAME_MTAS_LIST_QUERY_PREFIX = "query.prefix"; |
50 | - | |
55 | + | |
51 | 56 | /** The Constant NAME_MTAS_LIST_QUERY_IGNORE. */ |
52 | 57 | public static final String NAME_MTAS_LIST_QUERY_IGNORE = "query.ignore"; |
53 | 58 | public static final String NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumIgnoreLength"; |
... | ... | @@ -85,7 +90,8 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
85 | 90 | /** |
86 | 91 | * Instantiates a new mtas solr component list. |
87 | 92 | * |
88 | - * @param searchComponent the search component | |
93 | + * @param searchComponent | |
94 | + * the search component | |
89 | 95 | */ |
90 | 96 | public MtasSolrComponentList(MtasSolrSearchComponent searchComponent) { |
91 | 97 | this.searchComponent = searchComponent; |
... | ... | @@ -94,21 +100,24 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
94 | 100 | /** |
95 | 101 | * Prepare. |
96 | 102 | * |
97 | - * @param rb the rb | |
98 | - * @param mtasFields the mtas fields | |
99 | - * @throws IOException Signals that an I/O exception has occurred. | |
103 | + * @param rb | |
104 | + * the rb | |
105 | + * @param mtasFields | |
106 | + * the mtas fields | |
107 | + * @throws IOException | |
108 | + * Signals that an I/O exception has occurred. | |
100 | 109 | */ |
101 | 110 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
102 | 111 | throws IOException { |
103 | 112 | Set<String> ids = MtasSolrResultUtil |
104 | 113 | .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_LIST); |
105 | - if (ids.size() > 0) { | |
114 | + if (!ids.isEmpty()) { | |
106 | 115 | int tmpCounter = 0; |
107 | 116 | String[] fields = new String[ids.size()]; |
108 | 117 | String[] queryTypes = new String[ids.size()]; |
109 | 118 | String[] queryValues = new String[ids.size()]; |
110 | 119 | String[] queryPrefixes = new String[ids.size()]; |
111 | - HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()]; | |
120 | + HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()]; | |
112 | 121 | String[] queryIgnores = new String[ids.size()]; |
113 | 122 | String[] queryMaximumIgnoreLengths = new String[ids.size()]; |
114 | 123 | String[] keys = new String[ids.size()]; |
... | ... | @@ -136,47 +145,45 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
136 | 145 | queryIgnores[tmpCounter] = rb.req.getParams().get( |
137 | 146 | PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_IGNORE, |
138 | 147 | null); |
139 | - queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams().get( | |
140 | - PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, | |
141 | - null); | |
148 | + queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams() | |
149 | + .get(PARAM_MTAS_LIST + "." + id + "." | |
150 | + + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, null); | |
142 | 151 | Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters( |
143 | 152 | rb.req.getParams(), |
144 | - PARAM_MTAS_LIST + "." + id + "." | |
145 | - + NAME_MTAS_LIST_QUERY_VARIABLE); | |
146 | - queryVariables[tmpCounter] = new HashMap<String, String[]>(); | |
147 | - if (vIds.size() > 0) { | |
148 | - HashMap<String, ArrayList<String>> tmpVariables = new HashMap<String, ArrayList<String>>(); | |
153 | + PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_VARIABLE); | |
154 | + queryVariables[tmpCounter] = new HashMap<>(); | |
155 | + if (!vIds.isEmpty()) { | |
156 | + HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>(); | |
149 | 157 | for (String vId : vIds) { |
150 | - String name = rb.req.getParams() | |
151 | - .get(PARAM_MTAS_LIST + "." + id + "." | |
152 | - + NAME_MTAS_LIST_QUERY_VARIABLE + "." + vId | |
153 | - + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME, | |
154 | - null); | |
158 | + String name = rb.req.getParams().get( | |
159 | + PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_VARIABLE | |
160 | + + "." + vId + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME, | |
161 | + null); | |
155 | 162 | if (name != null) { |
156 | 163 | if (!tmpVariables.containsKey(name)) { |
157 | 164 | tmpVariables.put(name, new ArrayList<String>()); |
158 | 165 | } |
159 | 166 | String value = rb.req.getParams() |
160 | 167 | .get(PARAM_MTAS_LIST + "." + id + "." |
161 | - + NAME_MTAS_LIST_QUERY_VARIABLE + "." + vId | |
162 | - + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE, | |
163 | - null); | |
168 | + + NAME_MTAS_LIST_QUERY_VARIABLE + "." + vId + "." | |
169 | + + SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE, null); | |
164 | 170 | if (value != null) { |
165 | - ArrayList<String> list = new ArrayList<String>(); | |
171 | + ArrayList<String> list = new ArrayList<>(); | |
166 | 172 | String[] subList = value.split("(?<!\\\\),"); |
167 | - for(int i=0; i<subList.length; i++) { | |
168 | - list.add(subList[i].replace("\\,", ",").replace("\\\\", "\\")); | |
169 | - } | |
170 | - tmpVariables.get(name).addAll(list); | |
173 | + for (int i = 0; i < subList.length; i++) { | |
174 | + list.add( | |
175 | + subList[i].replace("\\,", ",").replace("\\\\", "\\")); | |
176 | + } | |
177 | + tmpVariables.get(name).addAll(list); | |
171 | 178 | } |
172 | 179 | } |
173 | 180 | } |
174 | - for (String name : tmpVariables.keySet()) { | |
175 | - queryVariables[tmpCounter].put(name, | |
176 | - tmpVariables.get(name) | |
177 | - .toArray(new String[tmpVariables.get(name).size()])); | |
181 | + for (Entry<String, ArrayList<String>> entry : tmpVariables | |
182 | + .entrySet()) { | |
183 | + queryVariables[tmpCounter].put(entry.getKey(), | |
184 | + entry.getValue().toArray(new String[entry.getValue().size()])); | |
178 | 185 | } |
179 | - } | |
186 | + } | |
180 | 187 | prefixes[tmpCounter] = rb.req.getParams().get( |
181 | 188 | PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_PREFIX, null); |
182 | 189 | starts[tmpCounter] = rb.req.getParams() |
... | ... | @@ -212,7 +219,8 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
212 | 219 | MtasSolrResultUtil.compareAndCheck(prefixes, queryIgnores, |
213 | 220 | NAME_MTAS_LIST_QUERY_IGNORE, NAME_MTAS_LIST_FIELD, false); |
214 | 221 | MtasSolrResultUtil.compareAndCheck(prefixes, queryMaximumIgnoreLengths, |
215 | - NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_LIST_FIELD, false); | |
222 | + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_LIST_FIELD, | |
223 | + false); | |
216 | 224 | MtasSolrResultUtil.compareAndCheck(prefixes, fields, |
217 | 225 | NAME_MTAS_LIST_PREFIX, NAME_MTAS_LIST_FIELD, false); |
218 | 226 | MtasSolrResultUtil.compareAndCheck(starts, fields, NAME_MTAS_LIST_START, |
... | ... | @@ -227,9 +235,11 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
227 | 235 | NAME_MTAS_LIST_FIELD, false); |
228 | 236 | for (int i = 0; i < fields.length; i++) { |
229 | 237 | ComponentField cf = mtasFields.list.get(fields[i]); |
230 | - Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i]==null)? null : Integer.parseInt(queryMaximumIgnoreLengths[i]); | |
238 | + Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null) | |
239 | + ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]); | |
231 | 240 | MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i], |
232 | - queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i], queryIgnores[i], maximumIgnoreLength); | |
241 | + queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i], | |
242 | + queryIgnores[i], maximumIgnoreLength); | |
233 | 243 | // minimize number of queries |
234 | 244 | if (cf.spanQueryList.contains(q)) { |
235 | 245 | q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q)); |
... | ... | @@ -251,8 +261,9 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
251 | 261 | : Integer.parseInt(rights[i]); |
252 | 262 | String output = outputs[i]; |
253 | 263 | mtasFields.list.get(fields[i]).listList.add(new ComponentList(q, |
254 | - fields[i], queryValues[i], queryTypes[i], queryPrefixes[i], queryVariables[i], queryIgnores[i], queryMaximumIgnoreLengths[i], key, | |
255 | - prefix, start, number, left, right, output)); | |
264 | + fields[i], queryValues[i], queryTypes[i], queryPrefixes[i], | |
265 | + queryVariables[i], queryIgnores[i], queryMaximumIgnoreLengths[i], | |
266 | + key, prefix, start, number, left, right, output)); | |
256 | 267 | } |
257 | 268 | } |
258 | 269 | } |
... | ... | @@ -260,73 +271,78 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
260 | 271 | /** |
261 | 272 | * Modify request. |
262 | 273 | * |
263 | - * @param rb the rb | |
264 | - * @param who the who | |
265 | - * @param sreq the sreq | |
274 | + * @param rb | |
275 | + * the rb | |
276 | + * @param who | |
277 | + * the who | |
278 | + * @param sreq | |
279 | + * the sreq | |
266 | 280 | */ |
267 | 281 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
268 | 282 | ShardRequest sreq) { |
269 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
270 | - if (sreq.params.getBool(PARAM_MTAS_LIST, false)) { | |
271 | - // compute keys | |
272 | - Set<String> keys = MtasSolrResultUtil | |
273 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_LIST); | |
274 | - if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
275 | - for (String key : keys) { | |
276 | - sreq.params.remove( | |
277 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_PREFIX); | |
278 | - sreq.params.remove( | |
279 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_START); | |
280 | - sreq.params.remove( | |
281 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_NUMBER); | |
282 | - sreq.params.remove( | |
283 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_LEFT); | |
284 | - sreq.params.remove( | |
285 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_RIGHT); | |
286 | - sreq.params.remove( | |
287 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_OUTPUT); | |
288 | - // don't get data | |
289 | - sreq.params.add( | |
290 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_NUMBER, "0"); | |
291 | - } | |
292 | - } else { | |
293 | - sreq.params.remove(PARAM_MTAS_LIST); | |
294 | - for (String key : keys) { | |
295 | - sreq.params.remove( | |
296 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_FIELD); | |
297 | - sreq.params.remove( | |
298 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_VALUE); | |
299 | - sreq.params.remove( | |
300 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_TYPE); | |
301 | - sreq.params.remove( | |
302 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_PREFIX); | |
303 | - sreq.params.remove( | |
304 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_IGNORE); | |
305 | - sreq.params.remove( | |
306 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH); | |
307 | - Set<String> subKeys = MtasSolrResultUtil | |
308 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_VARIABLE); | |
309 | - for (String subKey : subKeys) { | |
310 | - sreq.params.remove( | |
311 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_VARIABLE+"."+subKey+"."+SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME); | |
312 | - sreq.params.remove( | |
313 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_VARIABLE+"."+subKey+"."+SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE); | |
314 | - } | |
315 | - sreq.params | |
316 | - .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_KEY); | |
317 | - sreq.params.remove( | |
318 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_PREFIX); | |
319 | - sreq.params.remove( | |
320 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_START); | |
321 | - sreq.params.remove( | |
322 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_NUMBER); | |
323 | - sreq.params.remove( | |
324 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_LEFT); | |
325 | - sreq.params.remove( | |
326 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_RIGHT); | |
327 | - sreq.params.remove( | |
328 | - PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_OUTPUT); | |
283 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
284 | + && sreq.params.getBool(PARAM_MTAS_LIST, false)) { | |
285 | + // compute keys | |
286 | + Set<String> keys = MtasSolrResultUtil | |
287 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_LIST); | |
288 | + if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
289 | + for (String key : keys) { | |
290 | + sreq.params.remove( | |
291 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_PREFIX); | |
292 | + sreq.params | |
293 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_START); | |
294 | + sreq.params.remove( | |
295 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_NUMBER); | |
296 | + sreq.params | |
297 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_LEFT); | |
298 | + sreq.params | |
299 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_RIGHT); | |
300 | + sreq.params.remove( | |
301 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_OUTPUT); | |
302 | + // don't get data | |
303 | + sreq.params.add( | |
304 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_NUMBER, "0"); | |
305 | + } | |
306 | + } else { | |
307 | + sreq.params.remove(PARAM_MTAS_LIST); | |
308 | + for (String key : keys) { | |
309 | + sreq.params | |
310 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_FIELD); | |
311 | + sreq.params.remove( | |
312 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_VALUE); | |
313 | + sreq.params.remove( | |
314 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_TYPE); | |
315 | + sreq.params.remove( | |
316 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_PREFIX); | |
317 | + sreq.params.remove( | |
318 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_QUERY_IGNORE); | |
319 | + sreq.params.remove(PARAM_MTAS_LIST + "." + key + "." | |
320 | + + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH); | |
321 | + Set<String> subKeys = MtasSolrResultUtil | |
322 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_LIST + "." | |
323 | + + key + "." + NAME_MTAS_LIST_QUERY_VARIABLE); | |
324 | + for (String subKey : subKeys) { | |
325 | + sreq.params.remove(PARAM_MTAS_LIST + "." + key + "." | |
326 | + + NAME_MTAS_LIST_QUERY_VARIABLE + "." + subKey + "." | |
327 | + + SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME); | |
328 | + sreq.params.remove(PARAM_MTAS_LIST + "." + key + "." | |
329 | + + NAME_MTAS_LIST_QUERY_VARIABLE + "." + subKey + "." | |
330 | + + SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE); | |
329 | 331 | } |
332 | + sreq.params | |
333 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_KEY); | |
334 | + sreq.params.remove( | |
335 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_PREFIX); | |
336 | + sreq.params | |
337 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_START); | |
338 | + sreq.params.remove( | |
339 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_NUMBER); | |
340 | + sreq.params | |
341 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_LEFT); | |
342 | + sreq.params | |
343 | + .remove(PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_RIGHT); | |
344 | + sreq.params.remove( | |
345 | + PARAM_MTAS_LIST + "." + key + "." + NAME_MTAS_LIST_OUTPUT); | |
330 | 346 | } |
331 | 347 | } |
332 | 348 | } |
... | ... | @@ -335,8 +351,10 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
335 | 351 | /** |
336 | 352 | * Distributed process. |
337 | 353 | * |
338 | - * @param rb the rb | |
339 | - * @param mtasFields the mtas fields | |
354 | + * @param rb | |
355 | + * the rb | |
356 | + * @param mtasFields | |
357 | + * the mtas fields | |
340 | 358 | */ |
341 | 359 | @SuppressWarnings("unchecked") |
342 | 360 | public void distributedProcess(ResponseBuilder rb, |
... | ... | @@ -344,7 +362,7 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
344 | 362 | |
345 | 363 | if (mtasFields.doList) { |
346 | 364 | // compute total from shards |
347 | - HashMap<String, HashMap<String, Integer>> listShardTotals = new HashMap<String, HashMap<String, Integer>>(); | |
365 | + HashMap<String, HashMap<String, Integer>> listShardTotals = new HashMap<>(); | |
348 | 366 | for (ShardRequest sreq : rb.finished) { |
349 | 367 | if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) |
350 | 368 | && sreq.params.getBool(PARAM_MTAS_LIST, false)) { |
... | ... | @@ -370,18 +388,18 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
370 | 388 | } |
371 | 389 | } |
372 | 390 | } catch (ClassCastException e) { |
391 | + log.debug(e); | |
373 | 392 | } |
374 | 393 | } |
375 | 394 | } |
376 | 395 | } |
377 | 396 | // compute shard requests |
378 | - HashMap<String, ModifiableSolrParams> shardRequests = new HashMap<String, ModifiableSolrParams>(); | |
397 | + HashMap<String, ModifiableSolrParams> shardRequests = new HashMap<>(); | |
379 | 398 | int requestId = 0; |
380 | 399 | for (String field : mtasFields.list.keySet()) { |
381 | 400 | for (ComponentList list : mtasFields.list.get(field).listList) { |
382 | 401 | requestId++; |
383 | 402 | if (listShardTotals.containsKey(list.key) && (list.number > 0)) { |
384 | - Integer position = 0; | |
385 | 403 | Integer start = list.start; |
386 | 404 | Integer number = list.number; |
387 | 405 | HashMap<String, Integer> totals = listShardTotals.get(list.key); |
... | ... | @@ -406,22 +424,31 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
406 | 424 | + NAME_MTAS_LIST_QUERY_TYPE, list.queryType); |
407 | 425 | params.add(PARAM_MTAS_LIST + "." + requestId + "." |
408 | 426 | + NAME_MTAS_LIST_QUERY_PREFIX, list.queryPrefix); |
409 | - params.add(PARAM_MTAS_LIST + "." + requestId + "." | |
427 | + params.add(PARAM_MTAS_LIST + "." + requestId + "." | |
410 | 428 | + NAME_MTAS_LIST_QUERY_IGNORE, list.queryIgnore); |
411 | - params.add(PARAM_MTAS_LIST + "." + requestId + "." | |
412 | - + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, list.queryMaximumIgnoreLength); | |
413 | - int subRequestId=0; | |
414 | - for(String name : list.queryVariables.keySet()) { | |
415 | - if(list.queryVariables.get(name)==null || list.queryVariables.get(name).length==0) { | |
416 | - params.add(PARAM_MTAS_LIST + "." + requestId + "." | |
417 | - + NAME_MTAS_LIST_QUERY_VARIABLE+ "."+subRequestId+"."+SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME, name); | |
429 | + params.add( | |
430 | + PARAM_MTAS_LIST + "." + requestId + "." | |
431 | + + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, | |
432 | + list.queryMaximumIgnoreLength); | |
433 | + int subRequestId = 0; | |
434 | + for (String name : list.queryVariables.keySet()) { | |
435 | + if (list.queryVariables.get(name) == null | |
436 | + || list.queryVariables.get(name).length == 0) { | |
437 | + params.add( | |
438 | + PARAM_MTAS_LIST + "." + requestId + "." | |
439 | + + NAME_MTAS_LIST_QUERY_VARIABLE + "." + subRequestId | |
440 | + + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME, | |
441 | + name); | |
418 | 442 | subRequestId++; |
419 | 443 | } else { |
420 | - for(String value : list.queryVariables.get(name)) { | |
444 | + for (String value : list.queryVariables.get(name)) { | |
421 | 445 | params.add(PARAM_MTAS_LIST + "." + requestId + "." |
422 | - + NAME_MTAS_LIST_QUERY_VARIABLE+ "."+subRequestId+"."+SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME, name); | |
446 | + + NAME_MTAS_LIST_QUERY_VARIABLE + "." + subRequestId | |
447 | + + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME, name); | |
423 | 448 | params.add(PARAM_MTAS_LIST + "." + requestId + "." |
424 | - + NAME_MTAS_LIST_QUERY_VARIABLE+ "."+subRequestId+"."+SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE, value); | |
449 | + + NAME_MTAS_LIST_QUERY_VARIABLE + "." + subRequestId | |
450 | + + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE, | |
451 | + value); | |
425 | 452 | subRequestId++; |
426 | 453 | } |
427 | 454 | } |
... | ... | @@ -442,20 +469,20 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
442 | 469 | + NAME_MTAS_LIST_RIGHT, Integer.toString(list.right)); |
443 | 470 | params.add(PARAM_MTAS_LIST + "." + requestId + "." |
444 | 471 | + NAME_MTAS_LIST_OUTPUT, list.output); |
445 | - number -= (subTotal - start); | |
446 | - start = 0; | |
472 | + number -= (subTotal - start); | |
473 | + start = 0; | |
447 | 474 | } else { |
448 | 475 | start -= subTotal; |
449 | 476 | } |
450 | - position += subTotal; | |
451 | 477 | } |
452 | 478 | } |
453 | - } | |
479 | + } | |
454 | 480 | } |
455 | 481 | |
456 | - for (String shardName : shardRequests.keySet()) { | |
482 | + for (Entry<String, ModifiableSolrParams> entry : shardRequests | |
483 | + .entrySet()) { | |
457 | 484 | ShardRequest sreq = new ShardRequest(); |
458 | - sreq.shards = new String[] { shardName }; | |
485 | + sreq.shards = new String[] { entry.getKey() }; | |
459 | 486 | sreq.purpose = ShardRequest.PURPOSE_PRIVATE; |
460 | 487 | sreq.params = new ModifiableSolrParams(); |
461 | 488 | sreq.params.add("fq", rb.req.getParams().getParams("fq")); |
... | ... | @@ -466,26 +493,27 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
466 | 493 | .getOriginalParams().getParams(MtasSolrSearchComponent.PARAM_MTAS)); |
467 | 494 | sreq.params.add(PARAM_MTAS_LIST, |
468 | 495 | rb.req.getOriginalParams().getParams(PARAM_MTAS_LIST)); |
469 | - sreq.params.add(shardRequests.get(shardName)); | |
496 | + sreq.params.add(entry.getValue()); | |
470 | 497 | rb.addRequest(searchComponent, sreq); |
471 | - } | |
498 | + } | |
472 | 499 | } |
473 | 500 | } |
474 | 501 | |
475 | 502 | /** |
476 | 503 | * Creates the. |
477 | 504 | * |
478 | - * @param list the list | |
505 | + * @param list | |
506 | + * the list | |
479 | 507 | * @return the simple ordered map |
480 | 508 | */ |
481 | 509 | public SimpleOrderedMap<Object> create(ComponentList list, Boolean encode) { |
482 | 510 | SimpleOrderedMap<Object> mtasListResponse = new SimpleOrderedMap<>(); |
483 | 511 | mtasListResponse.add("key", list.key); |
484 | - if(list.number==0) { | |
512 | + if (list.number == 0) { | |
485 | 513 | mtasListResponse.add("total", list.total); |
486 | 514 | } |
487 | 515 | if (list.output != null) { |
488 | - ArrayList<NamedList<Object>> mtasListItemResponses = new ArrayList<NamedList<Object>>(); | |
516 | + ArrayList<NamedList<Object>> mtasListItemResponses = new ArrayList<>(); | |
489 | 517 | if (list.output.equals(ComponentList.LIST_OUTPUT_HIT)) { |
490 | 518 | mtasListResponse.add("number", list.hits.size()); |
491 | 519 | for (ListHit hit : list.hits) { |
... | ... | @@ -502,31 +530,35 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
502 | 530 | mtasListItemResponse.add("startPosition", hit.startPosition); |
503 | 531 | mtasListItemResponse.add("endPosition", hit.endPosition); |
504 | 532 | |
505 | - TreeMap<Integer, ArrayList<ArrayList<String>>> hitData = new TreeMap<Integer, ArrayList<ArrayList<String>>>(); | |
506 | - TreeMap<Integer, ArrayList<ArrayList<String>>> leftData = null, | |
507 | - rightData = null; | |
533 | + TreeMap<Integer, ArrayList<ArrayList<String>>> hitData = new TreeMap<>(); | |
534 | + TreeMap<Integer, ArrayList<ArrayList<String>>> leftData = null; | |
535 | + TreeMap<Integer, ArrayList<ArrayList<String>>> rightData = null; | |
508 | 536 | if (list.left > 0) { |
509 | - leftData = new TreeMap<Integer, ArrayList<ArrayList<String>>>(); | |
537 | + leftData = new TreeMap<>(); | |
510 | 538 | } |
511 | 539 | if (list.right > 0) { |
512 | - rightData = new TreeMap<Integer, ArrayList<ArrayList<String>>>(); | |
540 | + rightData = new TreeMap<>(); | |
513 | 541 | } |
514 | 542 | for (int position = Math.max(0, |
515 | 543 | hit.startPosition - list.left); position <= (hit.endPosition |
516 | 544 | + list.right); position++) { |
517 | - ArrayList<ArrayList<String>> hitDataItem = new ArrayList<ArrayList<String>>(); | |
545 | + ArrayList<ArrayList<String>> hitDataItem = new ArrayList<>(); | |
518 | 546 | if (hit.hits.containsKey(position)) { |
519 | 547 | for (String term : hit.hits.get(position)) { |
520 | - ArrayList<String> hitDataSubItem = new ArrayList<String>(); | |
548 | + ArrayList<String> hitDataSubItem = new ArrayList<>(); | |
521 | 549 | hitDataSubItem.add(CodecUtil.termPrefix(term)); |
522 | 550 | hitDataSubItem.add(CodecUtil.termValue(term)); |
523 | 551 | hitDataItem.add(hitDataSubItem); |
524 | 552 | } |
525 | 553 | } |
526 | 554 | if (position < hit.startPosition) { |
527 | - leftData.put(position, hitDataItem); | |
555 | + if (leftData != null) { | |
556 | + leftData.put(position, hitDataItem); | |
557 | + } | |
528 | 558 | } else if (position > hit.endPosition) { |
529 | - rightData.put(position, hitDataItem); | |
559 | + if (rightData != null) { | |
560 | + rightData.put(position, hitDataItem); | |
561 | + } | |
530 | 562 | } else { |
531 | 563 | hitData.put(position, hitDataItem); |
532 | 564 | } |
... | ... | @@ -556,7 +588,7 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
556 | 588 | mtasListItemResponse.add("startPosition", tokenHit.startPosition); |
557 | 589 | mtasListItemResponse.add("endPosition", tokenHit.endPosition); |
558 | 590 | |
559 | - ArrayList<NamedList<Object>> mtasListItemResponseItemTokens = new ArrayList<NamedList<Object>>(); | |
591 | + ArrayList<NamedList<Object>> mtasListItemResponseItemTokens = new ArrayList<>(); | |
560 | 592 | for (MtasToken token : tokenHit.tokens) { |
561 | 593 | NamedList<Object> mtasListItemResponseItemToken = new SimpleOrderedMap<>(); |
562 | 594 | if (token.getId() != null) { |
... | ... | @@ -607,17 +639,17 @@ public class MtasSolrComponentList implements MtasSolrComponent<ComponentList> { |
607 | 639 | /** |
608 | 640 | * Finish stage. |
609 | 641 | * |
610 | - * @param rb the rb | |
642 | + * @param rb | |
643 | + * the rb | |
611 | 644 | */ |
612 | 645 | public void finishStage(ResponseBuilder rb) { |
613 | - if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
614 | - if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
615 | - && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
616 | - for (ShardRequest sreq : rb.finished) { | |
617 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
618 | - && sreq.params.getBool(PARAM_MTAS_LIST, false)) { | |
619 | - // nothing to do | |
620 | - } | |
646 | + if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
647 | + && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
648 | + && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
649 | + for (ShardRequest sreq : rb.finished) { | |
650 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
651 | + && sreq.params.getBool(PARAM_MTAS_LIST, false)) { | |
652 | + // nothing to do | |
621 | 653 | } |
622 | 654 | } |
623 | 655 | } |
... | ... |
src/mtas/solr/handler/component/util/MtasSolrComponentPrefix.java
... | ... | @@ -5,6 +5,8 @@ import java.util.ArrayList; |
5 | 5 | import java.util.Set; |
6 | 6 | import java.util.TreeSet; |
7 | 7 | |
8 | +import org.apache.commons.logging.Log; | |
9 | +import org.apache.commons.logging.LogFactory; | |
8 | 10 | import org.apache.solr.common.util.NamedList; |
9 | 11 | import org.apache.solr.common.util.SimpleOrderedMap; |
10 | 12 | import org.apache.solr.handler.component.ResponseBuilder; |
... | ... | @@ -20,7 +22,11 @@ import mtas.solr.handler.component.MtasSolrSearchComponent; |
20 | 22 | /** |
21 | 23 | * The Class MtasSolrComponentPrefix. |
22 | 24 | */ |
23 | -public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefix> { | |
25 | +public class MtasSolrComponentPrefix | |
26 | + implements MtasSolrComponent<ComponentPrefix> { | |
27 | + | |
28 | + /** The log. */ | |
29 | + private static Log log = LogFactory.getLog(MtasSolrComponentPrefix.class); | |
24 | 30 | |
25 | 31 | /** The search component. */ |
26 | 32 | MtasSolrSearchComponent searchComponent; |
... | ... | @@ -44,18 +50,14 @@ public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefi |
44 | 50 | this.searchComponent = searchComponent; |
45 | 51 | } |
46 | 52 | |
47 | - /** | |
48 | - * Prepare. | |
49 | - * | |
50 | - * @param rb the rb | |
51 | - * @param mtasFields the mtas fields | |
52 | - * @throws IOException Signals that an I/O exception has occurred. | |
53 | + /* (non-Javadoc) | |
54 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr.handler.component.ResponseBuilder, mtas.codec.util.CodecComponent.ComponentFields) | |
53 | 55 | */ |
54 | 56 | public void prepare(ResponseBuilder rb, ComponentFields mtasFields) |
55 | 57 | throws IOException { |
56 | 58 | Set<String> ids = MtasSolrResultUtil |
57 | 59 | .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_PREFIX); |
58 | - if (ids.size() > 0) { | |
60 | + if (!ids.isEmpty()) { | |
59 | 61 | int tmpCounter = 0; |
60 | 62 | String[] fields = new String[ids.size()]; |
61 | 63 | String[] keys = new String[ids.size()]; |
... | ... | @@ -90,45 +92,36 @@ public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefi |
90 | 92 | } |
91 | 93 | } |
92 | 94 | |
93 | - /** | |
94 | - * Modify request. | |
95 | - * | |
96 | - * @param rb the rb | |
97 | - * @param who the who | |
98 | - * @param sreq the sreq | |
95 | + /* (non-Javadoc) | |
96 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache.solr.handler.component.ResponseBuilder, org.apache.solr.handler.component.SearchComponent, org.apache.solr.handler.component.ShardRequest) | |
99 | 97 | */ |
100 | 98 | public void modifyRequest(ResponseBuilder rb, SearchComponent who, |
101 | 99 | ShardRequest sreq) { |
102 | 100 | if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { |
103 | - if (sreq.params.getBool(PARAM_MTAS_PREFIX, false)) { | |
104 | - if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
105 | - // do nothing | |
106 | - } else { | |
107 | - // remove prefix for other requests | |
108 | - Set<String> keys = MtasSolrResultUtil | |
109 | - .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_PREFIX); | |
110 | - sreq.params.remove(PARAM_MTAS_PREFIX); | |
111 | - for (String key : keys) { | |
112 | - sreq.params.remove( | |
113 | - PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_FIELD); | |
114 | - sreq.params.remove( | |
115 | - PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_KEY); | |
116 | - } | |
101 | + if (sreq.params.getBool(PARAM_MTAS_PREFIX, false) | |
102 | + && (sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) { | |
103 | + // do nothing | |
104 | + } else { | |
105 | + // remove prefix for other requests | |
106 | + Set<String> keys = MtasSolrResultUtil | |
107 | + .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_PREFIX); | |
108 | + sreq.params.remove(PARAM_MTAS_PREFIX); | |
109 | + for (String key : keys) { | |
110 | + sreq.params.remove( | |
111 | + PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_FIELD); | |
112 | + sreq.params.remove( | |
113 | + PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_KEY); | |
117 | 114 | } |
118 | 115 | } |
119 | 116 | } |
120 | 117 | } |
121 | 118 | |
122 | - /** | |
123 | - * Creates the. | |
124 | - * | |
125 | - * @param prefix the prefix | |
126 | - * @param encode the encode | |
127 | - * @return the simple ordered map | |
119 | + /* (non-Javadoc) | |
120 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.CodecComponent.BasicComponent, java.lang.Boolean) | |
128 | 121 | */ |
129 | 122 | public SimpleOrderedMap<Object> create(ComponentPrefix prefix, |
130 | 123 | Boolean encode) { |
131 | - SimpleOrderedMap<Object> mtasPrefixResponse = new SimpleOrderedMap<Object>(); | |
124 | + SimpleOrderedMap<Object> mtasPrefixResponse = new SimpleOrderedMap<>(); | |
132 | 125 | mtasPrefixResponse.add("key", prefix.key); |
133 | 126 | if (encode) { |
134 | 127 | mtasPrefixResponse.add("_encoded_singlePosition", |
... | ... | @@ -148,31 +141,29 @@ public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefi |
148 | 141 | return mtasPrefixResponse; |
149 | 142 | } |
150 | 143 | |
151 | - /** | |
152 | - * Finish stage. | |
153 | - * | |
154 | - * @param rb the rb | |
144 | + /* (non-Javadoc) | |
145 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.solr.handler.component.ResponseBuilder) | |
155 | 146 | */ |
156 | 147 | @SuppressWarnings("unchecked") |
157 | 148 | public void finishStage(ResponseBuilder rb) { |
158 | - if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) { | |
159 | - if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
160 | - && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
161 | - for (ShardRequest sreq : rb.finished) { | |
162 | - if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
163 | - && sreq.params.getBool(PARAM_MTAS_PREFIX, false)) { | |
164 | - for (ShardResponse shardResponse : sreq.responses) { | |
165 | - NamedList<Object> response = shardResponse.getSolrResponse() | |
166 | - .getResponse(); | |
167 | - try { | |
168 | - ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response | |
169 | - .findRecursive("mtas", "prefix"); | |
170 | - if (data != null) { | |
171 | - MtasSolrResultUtil.decode(data); | |
172 | - } | |
173 | - } catch (ClassCastException e) { | |
174 | - // shouldnt happen | |
149 | + if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
150 | + && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY | |
151 | + && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { | |
152 | + for (ShardRequest sreq : rb.finished) { | |
153 | + if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false) | |
154 | + && sreq.params.getBool(PARAM_MTAS_PREFIX, false)) { | |
155 | + for (ShardResponse shardResponse : sreq.responses) { | |
156 | + NamedList<Object> response = shardResponse.getSolrResponse() | |
157 | + .getResponse(); | |
158 | + try { | |
159 | + ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response | |
160 | + .findRecursive("mtas", "prefix"); | |
161 | + if (data != null) { | |
162 | + MtasSolrResultUtil.decode(data); | |
175 | 163 | } |
164 | + } catch (ClassCastException e) { | |
165 | + log.debug(e); | |
166 | + // shouldnt happen | |
176 | 167 | } |
177 | 168 | } |
178 | 169 | } |
... | ... | @@ -180,12 +171,8 @@ public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefi |
180 | 171 | } |
181 | 172 | } |
182 | 173 | |
183 | - /** | |
184 | - * Distributed process. | |
185 | - * | |
186 | - * @param rb the rb | |
187 | - * @param mtasFields the mtas fields | |
188 | - * @throws IOException Signals that an I/O exception has occurred. | |
174 | + /* (non-Javadoc) | |
175 | + * @see mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.apache.solr.handler.component.ResponseBuilder, mtas.codec.util.CodecComponent.ComponentFields) | |
189 | 176 | */ |
190 | 177 | @SuppressWarnings("unchecked") |
191 | 178 | public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields) |
... | ... | @@ -194,21 +181,23 @@ public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefi |
194 | 181 | NamedList<Object> mtasResponse = null; |
195 | 182 | try { |
196 | 183 | mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas"); |
197 | - if (mtasResponse != null) { | |
198 | - NamedList<Object> mtasResponsePrefix; | |
199 | - try { | |
200 | - mtasResponsePrefix = (NamedList<Object>) mtasResponse.get("prefix"); | |
201 | - if (mtasResponsePrefix != null) { | |
202 | - repairPrefixItems(mtasResponsePrefix); | |
203 | - MtasSolrResultUtil.rewrite(mtasResponsePrefix); | |
204 | - } | |
205 | - } catch (ClassCastException e) { | |
206 | - mtasResponsePrefix = null; | |
207 | - } | |
208 | - } | |
209 | 184 | } catch (ClassCastException e) { |
185 | + log.debug(e); | |
210 | 186 | mtasResponse = null; |
211 | 187 | } |
188 | + if (mtasResponse != null) { | |
189 | + NamedList<Object> mtasResponsePrefix; | |
190 | + try { | |
191 | + mtasResponsePrefix = (NamedList<Object>) mtasResponse.get("prefix"); | |
192 | + if (mtasResponsePrefix != null) { | |
193 | + repairPrefixItems(mtasResponsePrefix); | |
194 | + MtasSolrResultUtil.rewrite(mtasResponsePrefix); | |
195 | + } | |
196 | + } catch (ClassCastException e) { | |
197 | + log.debug(e); | |
198 | + mtasResponse.remove("prefix"); | |
199 | + } | |
200 | + } | |
212 | 201 | } |
213 | 202 | |
214 | 203 | /** |
... | ... | @@ -229,19 +218,17 @@ public class MtasSolrComponentPrefix implements MtasSolrComponent<ComponentPrefi |
229 | 218 | .get("singlePosition"); |
230 | 219 | TreeSet<String> multiplePosition = (TreeSet<String>) item |
231 | 220 | .get("multiplePosition"); |
232 | - if (singlePosition != null) { | |
233 | - if (multiplePosition != null) { | |
234 | - for (String prefix : multiplePosition) { | |
235 | - if (singlePosition.contains(prefix)) { | |
236 | - singlePosition.remove(prefix); | |
237 | - } | |
221 | + if (singlePosition != null && multiplePosition != null) { | |
222 | + for (String prefix : multiplePosition) { | |
223 | + if (singlePosition.contains(prefix)) { | |
224 | + singlePosition.remove(prefix); | |
238 | 225 | } |
239 | 226 | } |
240 | 227 | } |
241 | 228 | } |
242 | 229 | } |
243 | 230 | } catch (ClassCastException e) { |
244 | - | |
231 | + log.debug(e); | |
245 | 232 | } |
246 | 233 | } |
247 | 234 | |
... | ... |