use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestBulkSchemaAPI method testSimilarityParser.
public void testSimilarityParser() throws Exception {
RestTestHarness harness = restTestHarness;
final float k1 = 2.25f;
final float b = 0.33f;
String fieldTypeName = "MySimilarityField";
String fieldName = "similarityTestField";
String payload = "{\n" + " 'add-field-type' : {" + " 'name' : '" + fieldTypeName + "',\n" + " 'class':'solr.TextField',\n" + " 'analyzer' : {'tokenizer':{'class':'solr.WhitespaceTokenizerFactory'}},\n" + " 'similarity' : {'class':'org.apache.solr.search.similarities.BM25SimilarityFactory', 'k1':" + k1 + ", 'b':" + b + " }\n" + " },\n" + " 'add-field' : {\n" + " 'name':'" + fieldName + "',\n" + " 'type': 'MySimilarityField',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + "}\n";
String response = harness.post("/schema?wt=json&indent=on", json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNull(response, map.get("errors"));
Map fields = getObj(harness, fieldName, "fields");
assertNotNull("field " + fieldName + " not created", fields);
assertFieldSimilarity(fieldName, BM25Similarity.class, sim -> assertEquals("Unexpected k1", k1, sim.getK1(), .001), sim -> assertEquals("Unexpected b", b, sim.getB(), .001));
final String independenceMeasure = "Saturated";
final boolean discountOverlaps = false;
payload = "{\n" + " 'replace-field-type' : {" + " 'name' : '" + fieldTypeName + "',\n" + " 'class':'solr.TextField',\n" + " 'analyzer' : {'tokenizer':{'class':'solr.WhitespaceTokenizerFactory'}},\n" + " 'similarity' : {\n" + " 'class':'org.apache.solr.search.similarities.DFISimilarityFactory',\n" + " 'independenceMeasure':'" + independenceMeasure + "',\n" + " 'discountOverlaps':" + discountOverlaps + "\n" + " }\n" + " }\n" + "}\n";
response = harness.post("/schema?wt=json&indent=on", json(payload));
map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNull(response, map.get("errors"));
fields = getObj(harness, fieldName, "fields");
assertNotNull("field " + fieldName + " not created", fields);
assertFieldSimilarity(fieldName, DFISimilarity.class, sim -> assertEquals("Unexpected independenceMeasure", independenceMeasure, sim.getIndependence().toString()), sim -> assertEquals("Unexpected discountedOverlaps", discountOverlaps, sim.getDiscountOverlaps()));
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestBulkSchemaAPI method testMultipleAddFieldWithErrors.
public void testMultipleAddFieldWithErrors() throws Exception {
String payload = "{\n" + " 'add-field' : {\n" + " 'name':'a1',\n" + " 'type': 'string1',\n" + " 'stored':true,\n" + " 'indexed':false\n" + " },\n" + " 'add-field' : {\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + " }";
String response = restTestHarness.post("/schema?wt=json", json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
List l = (List) map.get("errors");
assertNotNull("No errors", l);
List errorList = (List) ((Map) l.get(0)).get("errorMessages");
assertEquals(1, errorList.size());
assertTrue(((String) errorList.get(0)).contains("Field 'a1': Field type 'string1' not found.\n"));
errorList = (List) ((Map) l.get(1)).get("errorMessages");
assertEquals(1, errorList.size());
assertTrue(((String) errorList.get(0)).contains("is a required field"));
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestBulkSchemaAPI method testAddIllegalFields.
public void testAddIllegalFields() throws Exception {
RestTestHarness harness = restTestHarness;
// 1. Make sure you can't create a new field with an asterisk in its name
String newFieldName = "asterisk*";
String payload = "{\n" + " 'add-field' : {\n" + " 'name':'" + newFieldName + "',\n" + " 'type':'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + "}";
String response = harness.post("/schema?wt=json", json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNotNull(response, map.get("errors"));
map = getObj(harness, newFieldName, "fields");
assertNull(newFieldName + " illegal dynamic field should not have been added to schema", map);
// 2. Make sure you get an error when you try to create a field that already exists
// Make sure 'wdf_nocase' field exists
newFieldName = "wdf_nocase";
Map m = getObj(harness, newFieldName, "fields");
assertNotNull("'" + newFieldName + "' field does not exist in the schema", m);
payload = "{\n" + " 'add-field' : {\n" + " 'name':'" + newFieldName + "',\n" + " 'type':'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + "}";
response = harness.post("/schema?wt=json", json(payload));
map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNotNull(response, map.get("errors"));
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestBulkSchemaAPI method testAddFieldWithExistingCatchallDynamicField.
public void testAddFieldWithExistingCatchallDynamicField() throws Exception {
RestTestHarness harness = restTestHarness;
String newFieldName = "NewField1";
Map map = getObj(harness, newFieldName, "fields");
assertNull("Field '" + newFieldName + "' already exists in the schema", map);
map = getObj(harness, "*", "dynamicFields");
assertNull("'*' dynamic field already exists in the schema", map);
map = getObj(harness, "string", "fieldTypes");
assertNotNull("'boolean' field type does not exist in the schema", map);
map = getObj(harness, "boolean", "fieldTypes");
assertNotNull("'boolean' field type does not exist in the schema", map);
String payload = "{\n" + " 'add-dynamic-field' : {\n" + " 'name':'*',\n" + " 'type':'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + "}";
String response = harness.post("/schema?wt=json", json(payload));
map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNull(response, map.get("errors"));
map = getObj(harness, "*", "dynamicFields");
assertNotNull("Dynamic field '*' is not in the schema", map);
payload = "{\n" + " 'add-field' : {\n" + " 'name':'" + newFieldName + "',\n" + " 'type':'boolean',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + " }";
response = harness.post("/schema?wt=json", json(payload));
map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNull(response, map.get("errors"));
map = getObj(harness, newFieldName, "fields");
assertNotNull("Field '" + newFieldName + "' is not in the schema", map);
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestConfigReload method getAsMap.
private Map getAsMap(String uri) throws Exception {
HttpGet get = new HttpGet(uri);
HttpEntity entity = null;
try {
entity = cloudClient.getLbClient().getHttpClient().execute(get).getEntity();
String response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
return (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
} finally {
EntityUtils.consumeQuietly(entity);
}
}
Aggregations