use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class TestFacetMethods method testNumericSingleValuedDV.
@Test
public void testNumericSingleValuedDV() {
SchemaField field = new SchemaField("field", new TrieIntField(), DOC_VALUES, null);
// default is FCS, can't use ENUM due to trie-field terms, FC rewrites to FCS for efficiency
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, null, 0));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 0));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 0));
assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 0));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 0));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, null, 1));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 1));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 1));
assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 1));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 1));
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class TestFacetMethods method testTextSingleValuedNoDV.
@Test
public void testTextSingleValuedNoDV() {
SchemaField field = new SchemaField("field", new StrField(), 0, null);
// default is FC, UIF rewrites to FCS for mincount = 0
// TODO should it rewrite to FC instead?
assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, null, 0));
assertEquals(SimpleFacets.FacetMethod.ENUM, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 0));
assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 0));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 0));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 0));
assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, null, 1));
assertEquals(SimpleFacets.FacetMethod.ENUM, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 1));
assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 1));
assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 1));
assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 1));
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class TestPseudoReturnFields method testMultiValued.
public void testMultiValued() throws Exception {
// score as psuedo field - precondition checks
for (String name : new String[] { "score", "val_ss" }) {
SchemaField sf = h.getCore().getLatestSchema().getFieldOrNull(name);
assertNotNull("Test depends on a (dynamic) field mtching '" + name + "', schema was changed out from under us!", sf);
assertTrue("Test depends on a multivalued dynamic field matching '" + name + "', schema was changed out from under us!", sf.multiValued());
}
// score as psuedo field
assertJQ(req("q", "*:*", "fq", "id:42", "fl", "id,score"), "/response/docs==[{'id':'42','score':1.0}]");
// single value int using alias that matches multivalued dynamic field
assertJQ(req("q", "id:42", "fl", "val_ss:val_i, val2_ss:10"), "/response/docs==[{'val2_ss':10,'val_ss':1}]");
assertJQ(req("qt", "/get", "id", "42", "fl", "val_ss:val_i, val2_ss:10"), "/doc=={'val2_ss':10,'val_ss':1}");
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class TestAddFieldRealTimeGet method test.
public void test() throws Exception {
clearIndex();
assertU(commit());
String newFieldName = "newfield";
String newFieldType = "string";
String newFieldValue = "xyz";
assertFailedU("Should fail due to unknown field '" + newFieldName + "'", adoc("id", "1", newFieldName, newFieldValue));
IndexSchema schema = h.getCore().getLatestSchema();
SchemaField newField = schema.newField(newFieldName, newFieldType, Collections.<String, Object>emptyMap());
IndexSchema newSchema = schema.addField(newField);
h.getCore().setLatestSchema(newSchema);
String newFieldKeyValue = "'" + newFieldName + "':'" + newFieldValue + "'";
assertU(adoc("id", "1", newFieldName, newFieldValue));
assertJQ(req("q", "id:1"), "/response/numFound==0");
assertJQ(req("qt", "/get", "id", "1", "fl", "id," + newFieldName), "=={'doc':{'id':'1'," + newFieldKeyValue + "}}");
assertJQ(req("qt", "/get", "ids", "1", "fl", "id," + newFieldName), "=={'response':{'numFound':1,'start':0,'docs':[{'id':'1'," + newFieldKeyValue + "}]}}");
assertU(commit());
assertJQ(req("q", "id:1"), "/response/numFound==1");
assertJQ(req("qt", "/get", "id", "1", "fl", "id," + newFieldName), "=={'doc':{'id':'1'," + newFieldKeyValue + "}}");
assertJQ(req("qt", "/get", "ids", "1", "fl", "id," + newFieldName), "=={'response':{'numFound':1,'start':0,'docs':[{'id':'1'," + newFieldKeyValue + "}]}}");
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class CursorMarkTest method buildRandomSortObjects.
private static Object[] buildRandomSortObjects(SortSpec ss) throws IOException {
List<SchemaField> fields = ss.getSchemaFields();
assertNotNull(fields);
Object[] results = new Object[fields.size()];
for (int i = 0; i < results.length; i++) {
SchemaField sf = fields.get(i);
if (null == sf) {
// score or function
results[i] = (Float) random().nextFloat() * random().nextInt();
break;
} else if (0 == TestUtil.nextInt(random(), 0, 7)) {
// emulate missing value for doc
results[i] = null;
} else {
final String fieldName = sf.getName();
assertNotNull(fieldName);
// Note: In some cases we build a human readable version of the sort value and then
// unmarshall it into the raw, real, sort values that are expected by the FieldTypes.
// In other cases we just build the raw value to begin with because it's easier
Object val = null;
if (fieldName.equals("id")) {
val = sf.getType().unmarshalSortValue(TestUtil.randomSimpleString(random()));
} else if (fieldName.startsWith("str")) {
val = sf.getType().unmarshalSortValue(TestUtil.randomRealisticUnicodeString(random()));
} else if (fieldName.startsWith("bin")) {
byte[] randBytes = new byte[TestUtil.nextInt(random(), 1, 50)];
random().nextBytes(randBytes);
val = new BytesRef(randBytes);
} else if (fieldName.contains("int")) {
// TrieIntField
val = random().nextInt();
} else if (fieldName.contains("long")) {
// TrieLongField
val = random().nextLong();
} else if (fieldName.contains("float")) {
// TrieFloatField
val = random().nextFloat() * random().nextInt();
} else if (fieldName.contains("double")) {
// TrieDoubleField
val = random().nextDouble() * random().nextInt();
} else if (fieldName.contains("date")) {
// TrieDateField
val = random().nextLong();
} else if (fieldName.startsWith("currency")) {
val = random().nextDouble();
} else if (fieldName.startsWith("uuid")) {
val = sf.getType().unmarshalSortValue(UUID.randomUUID().toString());
} else if (fieldName.startsWith("bool")) {
val = sf.getType().unmarshalSortValue(random().nextBoolean() ? "t" : "f");
} else if (fieldName.startsWith("enum")) {
val = random().nextInt(CursorPagingTest.SEVERITY_ENUM_VALUES.length);
} else if (fieldName.contains("collation")) {
val = getRandomCollation(sf);
} else {
fail("fell through the rabbit hole, new field in schema? = " + fieldName);
}
results[i] = val;
}
}
return results;
}
Aggregations