use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class SpellCheckCollatorTest method testZeroTries.
@Test
public void testZeroTries() throws Exception {
SolrCore core = h.getCore();
SearchComponent speller = core.getSearchComponent("spellcheck");
assertTrue("speller is null and it shouldn't be", speller != null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10");
params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0");
params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2");
params.add(CommonParams.Q, "lowerfilt:(+fauth)");
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
NamedList collationList = (NamedList) spellCheck.get("collations");
List<?> collations = (List<?>) collationList.getAll("collation");
assertTrue(collations.size() == 2);
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class ReplicaListTransformerTest method testTransform.
@Test
public void testTransform() throws Exception {
final String regex = ".*" + random().nextInt(10) + ".*";
final ReplicaListTransformer transformer;
if (random().nextBoolean()) {
transformer = new ToyMatchingReplicaListTransformer(regex);
} else {
transformer = new HttpShardHandlerFactory() {
@Override
protected ReplicaListTransformer getReplicaListTransformer(final SolrQueryRequest req) {
final SolrParams params = req.getParams();
if (params.getBool("toyNoTransform", false)) {
return new ToyNoOpReplicaListTransformer();
}
final String regex = params.get("toyRegEx");
if (regex != null) {
return new ToyMatchingReplicaListTransformer(regex);
}
return super.getReplicaListTransformer(req);
}
}.getReplicaListTransformer(new LocalSolrQueryRequest(null, new ModifiableSolrParams().add("toyRegEx", regex)));
}
final List<Replica> inputs = new ArrayList<>();
final List<Replica> expectedTransformed = new ArrayList<>();
final List<String> urls = createRandomUrls();
for (int ii = 0; ii < urls.size(); ++ii) {
final String name = "replica" + (ii + 1);
final String url = urls.get(ii);
final Map<String, Object> propMap = new HashMap<String, Object>();
propMap.put("base_url", url);
// a skeleton replica, good enough for this test's purposes
final Replica replica = new Replica(name, propMap);
inputs.add(replica);
if (url.matches(regex)) {
expectedTransformed.add(replica);
}
}
final List<Replica> actualTransformed = new ArrayList<>(inputs);
transformer.transform(actualTransformed);
assertEquals(expectedTransformed.size(), actualTransformed.size());
for (int ii = 0; ii < expectedTransformed.size(); ++ii) {
assertEquals("mismatch for ii=" + ii, expectedTransformed.get(ii), actualTransformed.get(ii));
}
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedIntegerFacetStats.
public void testFieldStatisticsDocValuesAndMultiValuedIntegerFacetStats() throws Exception {
SolrCore core = h.getCore();
String fieldName = "cat_intDocValues";
// precondition for the test
SchemaField catDocValues = core.getLatestSchema().getField(fieldName);
assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
List<FldType> types = new ArrayList<>();
types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
types.add(new FldType(fieldName, ONE_ONE, new IRange(0, 0)));
Doc d1 = createDocValuesDocument(types, fieldName, "1", -1, 3, 5);
updateJ(toJSON(d1), null);
Doc d2 = createDocValuesDocument(types, fieldName, "2", 3, -2, 6);
updateJ(toJSON(d2), null);
Doc d3 = createDocValuesDocument(types, fieldName, "3", 16, -3, 11);
updateJ(toJSON(d3), null);
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, fieldName);
args.put(StatsParams.STATS_FACET, fieldName);
args.put(StatsParams.STATS_CALC_DISTINCT, "true");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQEx("can not use FieldCache on multivalued field: cat_intDocValues", req, 400);
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedInteger.
public void testFieldStatisticsDocValuesAndMultiValuedInteger() throws Exception {
SolrCore core = h.getCore();
String fieldName = "cat_intDocValues";
// precondition for the test
SchemaField catDocValues = core.getLatestSchema().getField(fieldName);
assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
List<FldType> types = new ArrayList<>();
types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
types.add(new FldType(fieldName, ONE_ONE, new IRange(0, 0)));
Doc d1 = createDocValuesDocument(types, fieldName, "1", -1, 3, 5);
updateJ(toJSON(d1), null);
Doc d2 = createDocValuesDocument(types, fieldName, "2", 3, -2, 6);
updateJ(toJSON(d2), null);
Doc d3 = createDocValuesDocument(types, fieldName, "3", 16, -3, 11);
updateJ(toJSON(d3), null);
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, fieldName);
args.put(StatsParams.STATS_CALC_DISTINCT, "true");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test min/max on docValues and multiValued", req, "//lst[@name='" + fieldName + "']/double[@name='min'][.='-3.0']", "//lst[@name='" + fieldName + "']/double[@name='max'][.='16.0']", "//lst[@name='" + fieldName + "']/long[@name='count'][.='12']", "//lst[@name='" + fieldName + "']/long[@name='countDistinct'][.='9']", "//lst[@name='" + fieldName + "']/double[@name='sum'][.='38.0']", "//lst[@name='" + fieldName + "']/double[@name='mean'][.='3.1666666666666665']", "//lst[@name='" + fieldName + "']/double[@name='stddev'][.='5.638074031784151']", "//lst[@name='" + fieldName + "']/double[@name='sumOfSquares'][.='470.0']", "//lst[@name='" + fieldName + "']/long[@name='missing'][.='0']");
assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}" + fieldName), "//lst[@name='" + fieldName + "']/long[@name='cardinality'][.='9']");
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class StatsComponentTest method testStatsExcludeFilterQuery.
//SOLR-3177
public void testStatsExcludeFilterQuery() throws Exception {
SolrCore core = h.getCore();
assertU(adoc("id", "1"));
assertU(adoc("id", "2"));
assertU(adoc("id", "3"));
assertU(adoc("id", "4"));
assertU(commit());
Map<String, String> args = new HashMap<String, String>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "{!ex=id}id");
args.put("fq", "{!tag=id}id:[2 TO 3]");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test exluding filter query", req, "//lst[@name='id']/double[@name='min'][.='1.0']", "//lst[@name='id']/double[@name='max'][.='4.0']");
args = new HashMap<String, String>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "{!key=id2}id");
args.put("fq", "{!tag=id}id:[2 TO 3]");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test rename field", req, "//lst[@name='id2']/double[@name='min'][.='2.0']", "//lst[@name='id2']/double[@name='max'][.='3.0']");
}
Aggregations