Search in sources :

Example 36 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class ParsingFieldUpdateProcessorsTest method testParseAlternateSingleValuesBooleans.

public void testParseAlternateSingleValuesBooleans() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_b"
    assertNotNull(schema.getFieldOrNull("boolean1_b"));
    // should match dynamic field "*_b"
    assertNotNull(schema.getFieldOrNull("boolean2_b"));
    boolean[] values = { true, false };
    String[] stringValues = { "yup", "nope" };
    String[] fieldNames = { "boolean1_b", "boolean2_b" };
    SolrInputDocument d = doc(f("id", "59"));
    for (int i = 0; i < values.length; ++i) {
        d.addField(fieldNames[i], stringValues[i]);
    }
    d = processAdd("parse-boolean-alternate-single-values-no-run-processor", d);
    assertNotNull(d);
    for (int i = 0; i < values.length; ++i) {
        assertTrue(d.getFieldValue(fieldNames[i]) instanceof Boolean);
        assertEquals(values[i], d.getFieldValue(fieldNames[i]));
    }
    // Standard boolean values should not be mutated, since they're not configured
    stringValues = new String[] { "true", "false" };
    d = doc(f("id", "593"));
    for (int i = 0; i < values.length; ++i) {
        d.addField(fieldNames[i], stringValues[i]);
    }
    d = processAdd("parse-boolean-alternate-single-values-no-run-processor", d);
    assertNotNull(d);
    for (int i = 0; i < values.length; ++i) {
        assertTrue(d.getFieldValue(fieldNames[i]) instanceof String);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 37 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class ParsingFieldUpdateProcessorsTest method testParseIntRoundTrip.

public void testParseIntRoundTrip() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_i"
    assertNotNull(schema.getFieldOrNull("int1_i"));
    // should match dynamic field "*_i"
    assertNotNull(schema.getFieldOrNull("int2_i"));
    int value = 1089883491;
    String intString1 = "1089883491";
    String intString2 = "1,089,883,491";
    SolrInputDocument d = processAdd("parse-int", doc(f("id", "113"), f("int1_i", intString1), f("int2_i", intString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("int1_i") instanceof Integer);
    assertEquals(value, ((Integer) d.getFieldValue("int1_i")).intValue());
    assertTrue(d.getFieldValue("int2_i") instanceof Integer);
    assertEquals(value, ((Integer) d.getFieldValue("int2_i")).intValue());
    assertU(commit());
    assertQ(req("id:113"), "//int[@name='int1_i'][.='" + value + "']", "//int[@name='int2_i'][.='" + value + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 38 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class ParsingFieldUpdateProcessorsTest method testMixedFloats.

public void testMixedFloats() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_tf"
    assertNotNull(schema.getFieldOrNull("float_tf"));
    Map<Float, Object> mixedFloats = new HashMap<>();
    mixedFloats.put(85.0f, "85");
    mixedFloats.put(2894518.0f, "2,894,518");
    // Float-typed field value
    mixedFloats.put(2.94423E-9f, 2.94423E-9f);
    mixedFloats.put(48794721.937f, "48,794,721.937");
    SolrInputDocument d = processAdd("parse-float-no-run-processor", doc(f("id", "342"), f("float_tf", mixedFloats.values())));
    assertNotNull(d);
    for (Object o : d.getFieldValues("float_tf")) {
        assertTrue(o instanceof Float);
        mixedFloats.remove(o);
    }
    assertTrue(mixedFloats.isEmpty());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 39 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedLong.

public void testFailedParseMixedLong() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    Map<Object, Object> mixed = new HashMap<>();
    Float floatVal = 294423.0f;
    mixed.put(85L, "85");
    // Float-typed field value
    mixed.put(floatVal, floatVal);
    mixed.put(-2894518L, "-2,894,518");
    mixed.put(1879472193L, "1,879,472,193");
    SolrInputDocument d = processAdd("parse-long-no-run-processor", doc(f("id", "7204"), f("not_in_schema", mixed.values())));
    assertNotNull(d);
    boolean foundFloat = false;
    for (Object o : d.getFieldValues("not_in_schema")) {
        if (floatVal == o) {
            foundFloat = true;
        } else {
            assertTrue(o instanceof String);
        }
        mixed.values().remove(o);
    }
    assertTrue(foundFloat);
    assertTrue(mixed.isEmpty());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 40 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class ParsingFieldUpdateProcessorsTest method testParseDateRoundTrip.

public void testParseDateRoundTrip() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match "*_dt" dynamic field
    assertNotNull(schema.getFieldOrNull("date_dt"));
    String dateString = "2010-11-12T13:14:15.168Z";
    SolrInputDocument d = processAdd("parse-date", doc(f("id", "9"), f("date_dt", dateString)));
    assertNotNull(d);
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateString);
    assertTrue(d.getFieldValue("date_dt") instanceof Date);
    assertEquals(dateTime.getMillis(), ((Date) d.getFieldValue("date_dt")).getTime());
    assertU(commit());
    assertQ(req("id:9"), "//date[@name='date_dt'][.='" + dateString + "']");
}
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)

Aggregations

IndexSchema (org.apache.solr.schema.IndexSchema)109 SolrInputDocument (org.apache.solr.common.SolrInputDocument)41 SchemaField (org.apache.solr.schema.SchemaField)31 HashMap (java.util.HashMap)15 SolrException (org.apache.solr.common.SolrException)13 FieldType (org.apache.solr.schema.FieldType)13 Date (java.util.Date)12 LinkedHashMap (java.util.LinkedHashMap)12 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)12 IOException (java.io.IOException)11 NamedList (org.apache.solr.common.util.NamedList)11 ArrayList (java.util.ArrayList)10 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)10 DateTime (org.joda.time.DateTime)10 Document (org.apache.lucene.document.Document)8 SolrParams (org.apache.solr.common.params.SolrParams)8 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)8 Test (org.junit.Test)7 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)6 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)6