Search in sources :

Example 61 with IndexSchema

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 + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 62 with IndexSchema

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 + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 63 with IndexSchema

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 + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 64 with IndexSchema

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);
                    }
                }
            }
        }
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema) EntityField(org.apache.solr.handler.dataimport.config.EntityField)

Example 65 with IndexSchema

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);
    }
}
Also used : ResultContext(org.apache.solr.response.ResultContext) SolrParams(org.apache.solr.common.params.SolrParams) IndexSchema(org.apache.solr.schema.IndexSchema) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) DocList(org.apache.solr.search.DocList)

Aggregations

IndexSchema (org.apache.solr.schema.IndexSchema)116 SolrInputDocument (org.apache.solr.common.SolrInputDocument)42 SchemaField (org.apache.solr.schema.SchemaField)34 HashMap (java.util.HashMap)16 SolrException (org.apache.solr.common.SolrException)15 IOException (java.io.IOException)14 FieldType (org.apache.solr.schema.FieldType)14 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)13 Date (java.util.Date)12 LinkedHashMap (java.util.LinkedHashMap)12 NamedList (org.apache.solr.common.util.NamedList)12 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)12 ArrayList (java.util.ArrayList)11 Document (org.apache.lucene.document.Document)11 SolrParams (org.apache.solr.common.params.SolrParams)11 DateTime (org.joda.time.DateTime)10 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)9 SolrConfig (org.apache.solr.core.SolrConfig)8 Test (org.junit.Test)7