Search in sources :

Example 16 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedDate.

public void testFailedParseMixedDate() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();
    Map<Object, Object> mixed = new HashMap<>();
    String[] dateStrings = { "2020-05-13T18:47", "1989-12-14", "1682-07-22T18:33:00.000Z" };
    for (String dateString : dateStrings) {
        mixed.put(dateTimeFormatter.parseDateTime(dateString).toDate(), dateString);
    }
    Double extraDouble = 29.554d;
    // Double-typed field value
    mixed.put(extraDouble, extraDouble);
    SolrInputDocument d = processAdd("parse-date-no-run-processor", doc(f("id", "7201"), f("not_in_schema", mixed.values())));
    assertNotNull(d);
    boolean foundDouble = false;
    for (Object o : d.getFieldValues("not_in_schema")) {
        if (extraDouble == o) {
            foundDouble = true;
        } else {
            assertTrue(o instanceof String);
        }
        mixed.values().remove(o);
    }
    assertTrue(foundDouble);
    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) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 17 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseDoubleRoundTrip.

public void testParseDoubleRoundTrip() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_d"
    assertNotNull(schema.getFieldOrNull("double1_d"));
    // should match dynamic field "*_d"
    assertNotNull(schema.getFieldOrNull("double2_d"));
    double value = 10898.83491;
    String doubleString1 = "10898.83491";
    String doubleString2 = "10,898.83491";
    SolrInputDocument d = processAdd("parse-double", doc(f("id", "128"), f("double1_d", doubleString1), f("double2_d", doubleString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("double1_d") instanceof Double);
    assertEquals(value, (Double) d.getFieldValue("double1_d"), EPSILON);
    assertTrue(d.getFieldValue("double2_d") instanceof Double);
    assertEquals(value, (Double) d.getFieldValue("double2_d"), EPSILON);
    assertU(commit());
    assertQ(req("id:128"), "//double[@name='double1_d'][.='" + value + "']", "//double[@name='double2_d'][.='" + value + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 18 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseTrieDoubleRoundTrip.

public void testParseTrieDoubleRoundTrip() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_td"
    assertNotNull(schema.getFieldOrNull("double1_td"));
    // should match dynamic field "*_td"
    assertNotNull(schema.getFieldOrNull("double2_td"));
    double value = 10898.83491;
    String doubleString1 = "10898.83491";
    String doubleString2 = "10,898.83491";
    SolrInputDocument d = processAdd("parse-double", doc(f("id", "728"), f("double1_td", doubleString1), f("double2_td", doubleString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("double1_td") instanceof Double);
    assertEquals(value, (Double) d.getFieldValue("double1_td"), EPSILON);
    assertTrue(d.getFieldValue("double2_td") instanceof Double);
    assertEquals(value, (Double) d.getFieldValue("double2_td"), EPSILON);
    assertU(commit());
    assertQ(req("id:728"), "//double[@name='double1_td'][.='" + value + "']", "//double[@name='double2_td'][.='" + value + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 19 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedBoolean.

public void testFailedParseMixedBoolean() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    Map<Object, Object> mixed = new HashMap<>();
    Long longVal = 294423L;
    mixed.put(true, "true");
    // Float-typed field value
    mixed.put(longVal, longVal);
    mixed.put(false, "false");
    mixed.put(true, "true");
    SolrInputDocument d = processAdd("parse-boolean-no-run-processor", doc(f("id", "7207"), f("not_in_schema", mixed.values())));
    assertNotNull(d);
    boolean foundLong = false;
    for (Object o : d.getFieldValues("not_in_schema")) {
        if (longVal == o) {
            foundLong = true;
        } else {
            assertTrue(o instanceof String);
        }
        mixed.values().remove(o);
    }
    assertTrue(foundLong);
    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 20 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseAlternateValueBooleans.

public void testParseAlternateValueBooleans() 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"));
    // should match dynamic field "*_b"
    assertNotNull(schema.getFieldOrNull("boolean3_b"));
    // should match dynamic field "*_b"
    assertNotNull(schema.getFieldOrNull("boolean4_b"));
    // should match dynamic field "*_b"
    assertNotNull(schema.getFieldOrNull("boolean5_b"));
    assertNull(schema.getFieldOrNull("not_in_schema"));
    boolean[] values = { true, true, true, false, false, false };
    String[] stringValues = { "on", "yes", "True", "Off", "no", "FALSE" };
    String[] fieldNames = { "boolean1_b", "boolean2_b", "boolean3_b", "boolean4_b", "boolean5_b", "not_in_schema" };
    SolrInputDocument d = doc(f("id", "55"));
    for (int i = 0; i < values.length; ++i) {
        d.addField(fieldNames[i], stringValues[i]);
    }
    d = processAdd("parse-boolean-alternate-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]));
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

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