use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseFloatRoundTrip.
public void testParseFloatRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_f"
assertNotNull(schema.getFieldOrNull("float1_f"));
// should match dynamic field "*_f"
assertNotNull(schema.getFieldOrNull("float2_f"));
float value = 10898.83491f;
String floatString1 = "10898.83491";
String floatString2 = "10,898.83491";
SolrInputDocument d = processAdd("parse-float", doc(f("id", "128"), f("float1_f", floatString1), f("float2_f", floatString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("float1_f") instanceof Float);
assertEquals(value, (Float) d.getFieldValue("float1_f"), EPSILON);
assertTrue(d.getFieldValue("float2_f") instanceof Float);
assertEquals(value, (Float) d.getFieldValue("float2_f"), EPSILON);
assertU(commit());
assertQ(req("id:128"), "//float[@name='float1_f'][.='" + value + "']", "//float[@name='float2_f'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseTrieFloatRoundTrip.
public void testParseTrieFloatRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_tf"
assertNotNull(schema.getFieldOrNull("float1_tf"));
// should match dynamic field "*_tf"
assertNotNull(schema.getFieldOrNull("float2_tf"));
float value = 10898.83491f;
String floatString1 = "10898.83491";
String floatString2 = "10,898.83491";
SolrInputDocument d = processAdd("parse-float", doc(f("id", "728"), f("float1_tf", floatString1), f("float2_tf", floatString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("float1_tf") instanceof Float);
assertEquals(value, (Float) d.getFieldValue("float1_tf"), EPSILON);
assertTrue(d.getFieldValue("float2_tf") instanceof Float);
assertEquals(value, (Float) d.getFieldValue("float2_tf"), EPSILON);
assertU(commit());
assertQ(req("id:728"), "//float[@name='float1_tf'][.='" + value + "']", "//float[@name='float2_tf'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseDateNonUTCdefaultTimeZoneRoundTrip.
public void testParseDateNonUTCdefaultTimeZoneRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match "*_dt" dynamic field
assertNotNull(schema.getFieldOrNull("date_dt"));
String dateStringNoTimeZone = "2010-11-12T13:14:15.168";
String dateStringUTC = dateStringNoTimeZone + "Z";
// dateStringNoTimeZone interpreted as being in timeZone America/New_York, then printed as UTC
String dateStringUSEasternTimeAsUTC = "2010-11-12T18:14:15.168Z";
SolrInputDocument d = processAdd("parse-date-non-UTC-defaultTimeZone", doc(f("id", "99"), f("dateUTC_dt", dateStringUTC), f("dateNoTimeZone_dt", dateStringNoTimeZone)));
assertNotNull(d);
String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
DateTimeFormatter dateTimeFormatterUTC = DateTimeFormat.forPattern(pattern);
DateTime dateTimeUTC = dateTimeFormatterUTC.parseDateTime(dateStringUTC);
assertTrue(d.getFieldValue("dateUTC_dt") instanceof Date);
assertTrue(d.getFieldValue("dateNoTimeZone_dt") instanceof Date);
assertEquals(dateTimeUTC.getMillis(), ((Date) d.getFieldValue("dateUTC_dt")).getTime());
assertU(commit());
assertQ(req("id:99"), "//date[@name='dateUTC_dt'][.='" + dateStringUTC + "']", "//date[@name='dateNoTimeZone_dt'][.='" + dateStringUSEasternTimeAsUTC + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class DocBuilder method addFields.
@SuppressWarnings("unchecked")
private void addFields(Entity entity, DocWrapper doc, Map<String, Object> arow, VariableResolver vr) {
for (Map.Entry<String, Object> entry : arow.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value == null)
continue;
if (key.startsWith("$"))
continue;
Set<EntityField> field = entity.getColNameVsField().get(key);
IndexSchema schema = null == reqParams.getRequest() ? null : reqParams.getRequest().getSchema();
if (field == null && schema != null) {
// This can be a dynamic field or a field which does not have an entry in data-config ( an implicit field)
SchemaField sf = schema.getFieldOrNull(key);
if (sf == null) {
sf = config.getSchemaField(key);
}
if (sf != null) {
addFieldToDoc(entry.getValue(), sf.getName(), sf.multiValued(), doc);
}
//else do nothing. if we add it it may fail
} else {
if (field != null) {
for (EntityField f : field) {
String name = f.getName();
boolean multiValued = f.isMultiValued();
boolean toWrite = f.isToWrite();
if (f.isDynamicName()) {
name = vr.replaceTokens(name);
SchemaField schemaField = config.getSchemaField(name);
if (schemaField == null) {
toWrite = false;
} else {
multiValued = schemaField.multiValued();
toWrite = true;
}
}
if (toWrite) {
addFieldToDoc(entry.getValue(), name, multiValued, doc);
}
}
}
}
}
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ResponseLogComponent method process.
@Override
public void process(ResponseBuilder rb) throws IOException {
SolrParams params = rb.req.getParams();
if (!params.getBool(COMPONENT_NAME, false))
return;
SolrIndexSearcher searcher = rb.req.getSearcher();
IndexSchema schema = searcher.getSchema();
if (schema.getUniqueKeyField() == null)
return;
ResultContext rc = (ResultContext) rb.rsp.getResponse();
DocList docs = rc.getDocList();
if (docs.hasScores()) {
processScores(rb, docs, schema, searcher);
} else {
processIds(rb, docs, schema, searcher);
}
}
Aggregations