Search in sources :

Example 86 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseFloatNonRootLocale.

public void testParseFloatNonRootLocale() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_f"
    assertNotNull(schema.getFieldOrNull("float_f"));
    assertNull(schema.getFieldOrNull("not_in_schema"));
    float value = 10898.83491f;
    String floatString1 = "10898,83491";
    // no-break space: U+00A0
    String floatString2 = "10 898,83491";
    SolrInputDocument d = processAdd("parse-float-french-no-run-processor", doc(f("id", "140"), f("float_f", floatString1), f("not_in_schema", floatString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("float_f") instanceof Float);
    assertEquals(value, (Float) d.getFieldValue("float_f"), EPSILON);
    assertTrue(d.getFieldValue("not_in_schema") instanceof Float);
    assertEquals(value, (Float) d.getFieldValue("not_in_schema"), EPSILON);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 87 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseDateFormats.

public void testParseDateFormats() throws Exception {
    String[] formatExamples = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "2010-01-15T00:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss,SSSZ", "2010-01-15T00:00:00,000Z", "yyyy-MM-dd'T'HH:mm:ss.SSS", "2010-01-15T00:00:00.000", "yyyy-MM-dd'T'HH:mm:ss,SSS", "2010-01-15T00:00:00,000", "yyyy-MM-dd'T'HH:mm:ssZ", "2010-01-15T00:00:00Z", "yyyy-MM-dd'T'HH:mm:ss", "2010-01-15T00:00:00", "yyyy-MM-dd'T'HH:mmZ", "2010-01-15T00:00Z", "yyyy-MM-dd'T'HH:mm", "2010-01-15T00:00", "yyyy-MM-dd HH:mm:ss.SSSZ", "2010-01-15 00:00:00.000Z", "yyyy-MM-dd HH:mm:ss,SSSZ", "2010-01-15 00:00:00,000Z", "yyyy-MM-dd HH:mm:ss.SSS", "2010-01-15 00:00:00.000", "yyyy-MM-dd HH:mm:ss,SSS", "2010-01-15 00:00:00,000", "yyyy-MM-dd HH:mm:ssZ", "2010-01-15 00:00:00Z", "yyyy-MM-dd HH:mm:ss", "2010-01-15 00:00:00", "yyyy-MM-dd HH:mmZ", "2010-01-15 00:00Z", "yyyy-MM-dd HH:mm", "2010-01-15 00:00", "yyyy-MM-dd hh:mm a", "2010-01-15 12:00 AM", "yyyy-MM-dd hh:mma", "2010-01-15 12:00AM", "yyyy-MM-dd", "2010-01-15", "EEE MMM dd HH:mm:ss Z yyyy", "Fri Jan 15 00:00:00 +0000 2010", "EEE MMM dd HH:mm:ss yyyy Z", "Fri Jan 15 00:00:00 2010 +00:00", "EEE MMM dd HH:mm:ss yyyy", "Fri Jan 15 00:00:00 2010", "EEE, dd MMM yyyy HH:mm:ss Z", "Fri, 15 Jan 2010 00:00:00 +00:00", "EEEE, dd-MMM-yy HH:mm:ss Z", "Friday, 15-Jan-10 00:00:00 +00:00", "EEEE, MMMM dd, yyyy", "Friday, January 15, 2010", "MMMM dd, yyyy", "January 15, 2010", "MMM. dd, yyyy", "Jan. 15, 2010" };
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match "*_dt" dynamic field
    assertNotNull(schema.getFieldOrNull("dateUTC_dt"));
    String dateTimePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
    DateTimeFormatter dateTimeFormatterUTC = DateTimeFormat.forPattern(dateTimePattern);
    DateTime dateTimeUTC = dateTimeFormatterUTC.parseDateTime(formatExamples[1]);
    for (int i = 0; i < formatExamples.length; i += 2) {
        String format = formatExamples[i];
        String dateString = formatExamples[i + 1];
        String id = "95" + i;
        SolrInputDocument d = processAdd("parse-date-UTC-defaultTimeZone-no-run-processor", doc(f("id", id), f("dateUTC_dt", dateString)));
        assertNotNull(d);
        assertTrue("date '" + dateString + "' with format '" + format + "' is not mutated to a Date", d.getFieldValue("dateUTC_dt") instanceof Date);
        assertEquals("date '" + dateString + "' with format '" + format + "' mismatched milliseconds", dateTimeUTC.getMillis(), ((Date) d.getFieldValue("dateUTC_dt")).getTime());
    }
}
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 88 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseTrieLongRoundTrip.

public void testParseTrieLongRoundTrip() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_tl"
    assertNotNull(schema.getFieldOrNull("long1_tl"));
    // should match dynamic field "*_tl"
    assertNotNull(schema.getFieldOrNull("long2_tl"));
    long value = 1089883491L;
    String longString1 = "1089883491";
    String longString2 = "1,089,883,491";
    SolrInputDocument d = processAdd("parse-long", doc(f("id", "113"), f("long1_tl", longString1), f("long2_tl", longString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("long1_tl") instanceof Long);
    assertEquals(value, ((Long) d.getFieldValue("long1_tl")).longValue());
    assertTrue(d.getFieldValue("long2_tl") instanceof Long);
    assertEquals(value, ((Long) d.getFieldValue("long2_tl")).longValue());
    assertU(commit());
    assertQ(req("id:113"), "//long[@name='long1_tl'][.='" + value + "']", "//long[@name='long2_tl'][.='" + value + "']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 89 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseTrieDateRoundTrip.

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

Example 90 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testIntOverflow.

public void testIntOverflow() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema1"));
    assertNull(schema.getFieldOrNull("not_in_schema2"));
    long longValue1 = (long) Integer.MAX_VALUE + 100L;
    long longValue2 = (long) Integer.MIN_VALUE - 100L;
    String longString1 = Long.toString(longValue1);
    String longString2 = Long.toString(longValue2);
    SolrInputDocument d = processAdd("parse-int-no-run-processor", doc(f("id", "282"), f("not_in_schema1", longString1), f("not_in_schema2", longString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("not_in_schema1") instanceof String);
    assertTrue(d.getFieldValue("not_in_schema2") instanceof String);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

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