Search in sources :

Example 21 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseDateExplicitNotInSchemaSelector.

public void testParseDateExplicitNotInSchemaSelector() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    String dateString = "2010-11-12T13:14:15.168Z";
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateString);
    SolrInputDocument d = processAdd("parse-date-explicit-not-in-schema-selector-no-run-processor", doc(f("id", "88"), f("not_in_schema", dateString)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("not_in_schema") instanceof Date);
    assertEquals(dateTime.getMillis(), ((Date) d.getFieldValue("not_in_schema")).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 22 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseUSPacificDate.

public void testParseUSPacificDate() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    // Interpreted as 00:00 US Pacific Daylight Time = UTC+07:00
    String dateString = "8/9/2010";
    String dateStringUTC = "2010-08-09T07:00:00.000Z";
    SolrInputDocument d = processAdd("US-Pacific-parse-date-no-run-processor", doc(f("id", "288"), f("not_in_schema", dateString)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("not_in_schema") instanceof Date);
    assertEquals(dateStringUTC, (new DateTime(((Date) d.getFieldValue("not_in_schema")).getTime(), DateTimeZone.UTC)).toString());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 23 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedFloat.

public void testFailedParseMixedFloat() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    Map<Object, Object> mixed = new HashMap<>();
    Long longVal = 294423L;
    mixed.put(85L, "85");
    // Float-typed field value
    mixed.put(longVal, longVal);
    mixed.put(-2894518L, "-2,894,518");
    mixed.put(1879472193L, "1,879,472,193");
    SolrInputDocument d = processAdd("parse-float-no-run-processor", doc(f("id", "7205"), 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 24 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseFrenchDate.

public void testParseFrenchDate() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    String frenchDateString = "le vendredi 15 janvier 2010";
    String dateString = "2010-01-15T00:00:00.000Z";
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateString);
    SolrInputDocument d = processAdd("parse-french-date-UTC-defaultTimeZone-no-run-processor", doc(f("id", "88"), f("not_in_schema", frenchDateString)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("not_in_schema") instanceof Date);
    assertEquals(dateTime.getMillis(), ((Date) d.getFieldValue("not_in_schema")).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 25 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedDouble.

public void testFailedParseMixedDouble() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull(schema.getFieldOrNull("not_in_schema"));
    Map<Object, Object> mixed = new HashMap<>();
    Long longVal = 294423L;
    mixed.put(85, "85.0");
    // Float-typed field value
    mixed.put(longVal, longVal);
    mixed.put(-2894.518, "-2,894.518");
    mixed.put(187947.2193, "187,947.2193");
    SolrInputDocument d = processAdd("parse-double-no-run-processor", doc(f("id", "7206"), 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)

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