Revision 57285
Added by Katerina Iatropoulou over 4 years ago
SolrUtilsTest.java | ||
---|---|---|
35 | 35 |
HttpServletRequest requestMock; |
36 | 36 |
RequestResponseHandler.Entity entity; |
37 | 37 |
List<String> refineFields = new ArrayList<String>(); |
38 |
List<String> specialFacets = new ArrayList<String>(); |
|
38 | 39 |
List<String> fieldQueries = new ArrayList<String>(); |
39 | 40 |
List<String> fieldQueriesWithComma = new ArrayList<String>(); |
40 | 41 |
CloudSolrClient mockSolrClient; |
... | ... | |
50 | 51 |
|
51 | 52 |
refineFields = Arrays.asList(new String[]{"relfunderid", "relfundinglevel0_id", "relfundinglevel1_id", "relfundinglevel2_id"}); |
52 | 53 |
|
54 |
specialFacets = Arrays.asList(new String[]{"relfundinglevel0_id", "relfundinglevel1_id"}); |
|
55 |
|
|
53 | 56 |
fieldQueries = Arrays.asList(new String[]{"(relfunderid exact ec___::EC) and (relfunderid exact wt___::WT)", |
54 | 57 |
"relfundinglevel0_id exact ec___::EC::SP1" , "(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)"}); |
55 | 58 |
|
... | ... | |
61 | 64 |
|
62 | 65 |
@Test |
63 | 66 |
public void createEprQuery() { |
64 |
String query = SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, fieldQueries); |
|
67 |
String query = SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, specialFacets, fieldQueries);
|
|
65 | 68 |
Assert.assertEquals("query=(oaftype=result)" + |
66 | 69 |
"&groupby=relfunderid,relfundinglevel0_id,relfundinglevel1_id,relfundinglevel2_id" + |
70 |
"&sf=relfundinglevel0_id,relfundinglevel1_id"+ |
|
67 | 71 |
"&fq=(relfunderid exact ec___::EC) and (relfunderid exact wt___::WT),relfundinglevel0_id exact ec___::EC::SP1," + |
68 | 72 |
"(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)", query); |
69 | 73 |
|
70 | 74 |
|
75 |
//empty refine, empty fq, empty fc |
|
76 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<>(),new ArrayList<String>()); |
|
77 |
Assert.assertEquals("query=(oaftype=result)" + |
|
78 |
"&groupby=" + |
|
79 |
"&sf="+ |
|
80 |
"&fq=", query); |
|
81 |
|
|
71 | 82 |
//empty refine, empty fq |
72 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<String>()); |
|
83 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), specialFacets,new ArrayList<String>());
|
|
73 | 84 |
Assert.assertEquals("query=(oaftype=result)" + |
74 | 85 |
"&groupby=" + |
86 |
"&sf=relfundinglevel0_id,relfundinglevel1_id"+ |
|
75 | 87 |
"&fq=", query); |
76 | 88 |
|
77 |
//empty fq |
|
78 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, new ArrayList<String>()); |
|
89 |
|
|
90 |
//empty fq, empty sf |
|
91 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, new ArrayList<>(), new ArrayList<String>()); |
|
79 | 92 |
Assert.assertEquals("query=(oaftype=result)" + |
80 | 93 |
"&groupby=relfunderid,relfundinglevel0_id,relfundinglevel1_id,relfundinglevel2_id" + |
94 |
"&sf="+ |
|
81 | 95 |
"&fq=", query); |
82 | 96 |
|
83 |
//empty refine |
|
84 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), fieldQueries); |
|
97 |
//empty refine, empty sf
|
|
98 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<>(), fieldQueries);
|
|
85 | 99 |
Assert.assertEquals("query=(oaftype=result)" + |
86 | 100 |
"&groupby=" + |
101 |
"&sf="+ |
|
87 | 102 |
"&fq=(relfunderid exact ec___::EC) and (relfunderid exact wt___::WT),relfundinglevel0_id exact ec___::EC::SP1," + |
88 | 103 |
"(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)", query); |
89 | 104 |
|
90 |
//empty query |
|
91 |
query = SearchServiceImpl.createEprQuery("", new ArrayList<String>(), new ArrayList<String>()); |
|
105 |
//empty refine, empty sf |
|
106 |
query = SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<>(), fieldQueries); |
|
107 |
Assert.assertEquals("query=(oaftype=result)" + |
|
108 |
"&groupby=" + |
|
109 |
"&sf="+ |
|
110 |
"&fq=(relfunderid exact ec___::EC) and (relfunderid exact wt___::WT),relfundinglevel0_id exact ec___::EC::SP1," + |
|
111 |
"(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)", query); |
|
112 |
|
|
113 |
//empty query, empty fc |
|
114 |
query = SearchServiceImpl.createEprQuery("", new ArrayList<String>(), new ArrayList<>(), new ArrayList<String>()); |
|
92 | 115 |
Assert.assertEquals("query=" + |
93 | 116 |
"&groupby=" + |
117 |
"&sf="+ |
|
94 | 118 |
"&fq=", query); |
95 | 119 |
|
96 | 120 |
//null values |
97 |
query = SearchServiceImpl.createEprQuery(null, null, null); |
|
121 |
query = SearchServiceImpl.createEprQuery(null, null, null,null);
|
|
98 | 122 |
Assert.assertEquals("query=" + |
99 | 123 |
"&groupby=" + |
124 |
"&sf="+ |
|
100 | 125 |
"&fq=", query); |
101 | 126 |
|
102 | 127 |
} |
... | ... | |
105 | 130 |
public void extractQueryOptions() throws IOException, CQLParseException { |
106 | 131 |
CqlTranslator cqlTranslator = new CqlTranslatorImpl(); |
107 | 132 |
|
108 |
NamedList<String> actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, fieldQueries)); |
|
133 |
NamedList<String> actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, specialFacets, fieldQueries));
|
|
109 | 134 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
110 | 135 |
Assert.assertEquals("__result", actual.get("fl")); |
111 | 136 |
Assert.assertEquals("true", actual.get("shards.tolerant")); |
... | ... | |
117 | 142 |
Assert.assertTrue(actual.getAll("facet.field").contains("relfundinglevel1_id")); |
118 | 143 |
Assert.assertTrue(actual.getAll("facet.field").contains("relfundinglevel2_id")); |
119 | 144 |
Assert.assertFalse(actual.getAll("facet.field").contains("relfundinglevel3_id")); |
145 |
|
|
146 |
Assert.assertNotNull(actual.get("f.relfundinglevel0_id.facet.limit")); |
|
147 |
Assert.assertEquals(actual.get("f.relfundinglevel0_id.facet.limit"), "-1"); |
|
148 |
Assert.assertNotNull(actual.get("f.relfundinglevel1_id.facet.limit")); |
|
149 |
Assert.assertEquals(actual.get("f.relfundinglevel1_id.facet.limit"), "-1"); |
|
150 |
Assert.assertNull(actual.get("f.relfundinglevel3_id.facet.limit")); |
|
151 |
|
|
120 | 152 |
Assert.assertEquals(fieldQueries.size(), actual.getAll("fq").size()); |
121 | 153 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("(relfunderid exact ec___::EC) and (relfunderid exact wt___::WT)"))); |
122 | 154 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("relfundinglevel0_id exact ec___::EC::SP1"))); |
123 | 155 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)"))); |
124 | 156 |
|
125 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, fieldQueriesWithComma)); |
|
157 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, specialFacets, fieldQueriesWithComma));
|
|
126 | 158 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("(relfunderid exact ec___::EC) and (relfunderid exact wt___::WT)"))); |
127 | 159 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("relfundinglevel0_id exact \"ec___::EC::SP1,ec___::EC::SP2\""))); |
128 | 160 |
|
129 |
//empty refine, empty fq |
|
130 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<String>())); |
|
161 |
//empty refine, empty fc, empty fq
|
|
162 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<>(), new ArrayList<String>()));
|
|
131 | 163 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
132 | 164 |
Assert.assertEquals("__result", actual.get("fl")); |
133 | 165 |
Assert.assertNull(actual.get("q.op")); |
... | ... | |
140 | 172 |
Assert.assertNull(actual.get("fq")); |
141 | 173 |
Assert.assertTrue(actual.getAll("fq").isEmpty()); |
142 | 174 |
|
143 |
//empty fq |
|
144 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, new ArrayList<String>())); |
|
175 |
//empty fq, empty fc
|
|
176 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, new ArrayList<>(), new ArrayList<String>()));
|
|
145 | 177 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
146 | 178 |
Assert.assertEquals("__result", actual.get("fl")); |
147 | 179 |
Assert.assertNull(actual.get("q.op")); |
... | ... | |
154 | 186 |
Assert.assertTrue(actual.getAll("facet.field").contains("relfundinglevel1_id")); |
155 | 187 |
Assert.assertTrue(actual.getAll("facet.field").contains("relfundinglevel2_id")); |
156 | 188 |
Assert.assertFalse(actual.getAll("facet.field").contains("relfundinglevel3_id")); |
189 |
Assert.assertNull(actual.get("f.relfundinglevel0_id.facet.limit")); |
|
190 |
Assert.assertNull(actual.get("f.relfundinglevel1_id.facet.limit")); |
|
157 | 191 |
Assert.assertNull(actual.get("fq")); |
158 | 192 |
Assert.assertTrue(actual.getAll("fq").isEmpty()); |
159 | 193 |
|
160 |
//null fq |
|
161 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, null)); |
|
194 |
//null fc, null fq
|
|
195 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", refineFields, null, null));
|
|
162 | 196 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
163 | 197 |
Assert.assertEquals("__result", actual.get("fl")); |
164 | 198 |
Assert.assertNull(actual.get("q.op")); |
... | ... | |
174 | 208 |
Assert.assertNull(actual.get("fq")); |
175 | 209 |
Assert.assertTrue(actual.getAll("fq").isEmpty()); |
176 | 210 |
|
177 |
//empty refine |
|
178 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), fieldQueries)); |
|
211 |
//empty refine, empty fc
|
|
212 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", new ArrayList<String>(), new ArrayList<>(), fieldQueries));
|
|
179 | 213 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
180 | 214 |
Assert.assertEquals("__result", actual.get("fl")); |
181 | 215 |
// Assert.assertEquals("AND", actual.get("q.op")); |
... | ... | |
190 | 224 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("relfundinglevel0_id exact ec___::EC::SP1"))); |
191 | 225 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)"))); |
192 | 226 |
|
193 |
//null refine |
|
194 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", null, fieldQueries)); |
|
227 |
//null refine, null fc
|
|
228 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", null, null, fieldQueries));
|
|
195 | 229 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
196 | 230 |
Assert.assertEquals("__result", actual.get("fl")); |
197 | 231 |
// Assert.assertEquals("AND", actual.get("q.op")); |
... | ... | |
206 | 240 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("relfundinglevel0_id exact ec___::EC::SP1"))); |
207 | 241 |
Assert.assertTrue(actual.getAll("fq").contains(cqlTranslator.toLucene("(relfundinglevel1_id exact ec___::EC::SP1::VALUE1) or (relfundinglevel1_id exact ec___::EC::SP1::VALUE2)"))); |
208 | 242 |
|
209 |
//null refine, null fq |
|
210 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", null, null)); |
|
243 |
//null refine, null fc, null fq
|
|
244 |
actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery("(oaftype=result)", null, null, null));
|
|
211 | 245 |
Assert.assertEquals(cqlTranslator.toLucene("(oaftype=result)"), actual.get("q")); |
212 | 246 |
Assert.assertEquals("__result", actual.get("fl")); |
213 | 247 |
Assert.assertNull(actual.get("q.op")); |
... | ... | |
223 | 257 |
|
224 | 258 |
@Test(expected=CQLParseException.class) |
225 | 259 |
public void extractQueryOptionsEmptyQuery() throws IOException, CQLParseException { |
226 |
NamedList<String> actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery(null, null, null)); |
|
260 |
NamedList<String> actual = SolrResultSetOptionsUtil.extractQueryOptions(SearchServiceImpl.createEprQuery(null, null, null, null));
|
|
227 | 261 |
} |
228 | 262 |
|
229 | 263 |
} |
Also available in: Unified diff
return facets with more than the default 100 value