Search in sources :

Example 91 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseLongRoundTrip.

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

Example 92 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseLongNonRootLocale.

public void testParseLongNonRootLocale() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    // should match dynamic field "*_l"
    assertNotNull(schema.getFieldOrNull("long_l"));
    assertNull(schema.getFieldOrNull("not_in_schema"));
    long value = 1089883491L;
    String longString1 = "1089883491";
    // no-break space U+00A0
    String longString2 = "1 089 883 491";
    SolrInputDocument d = processAdd("parse-long-russian-no-run-processor", doc(f("id", "113"), f("long_l", longString1), f("not_in_schema", longString2)));
    assertNotNull(d);
    assertTrue(d.getFieldValue("long_l") instanceof Long);
    assertEquals(value, ((Long) d.getFieldValue("long_l")).longValue());
    assertTrue(d.getFieldValue("not_in_schema") instanceof Long);
    assertEquals(value, ((Long) d.getFieldValue("not_in_schema")).longValue());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 93 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedInt.

public void testFailedParseMixedInt() 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(85, "85");
    // Float-typed field value
    mixed.put(floatVal, floatVal);
    mixed.put(-2894518, "-2,894,518");
    mixed.put(1879472193, "1,879,472,193");
    SolrInputDocument d = processAdd("parse-int-no-run-processor", doc(f("id", "7202"), 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 94 with IndexSchema

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

the class LukeRequestHandlerTest method testCatchAllCopyField.

public void testCatchAllCopyField() throws Exception {
    deleteCore();
    initCore("solrconfig.xml", "schema-copyfield-test.xml");
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNull("'*' should not be (or match) a dynamic field", schema.getDynamicPattern("*"));
    boolean foundCatchAllCopyField = false;
    for (IndexSchema.DynamicCopy dcf : schema.getDynamicCopyFields()) {
        foundCatchAllCopyField = dcf.getRegex().equals("*") && dcf.getDestFieldName().equals("catchall_t");
        if (foundCatchAllCopyField) {
            break;
        }
    }
    assertTrue("<copyField source=\"*\" dest=\"catchall_t\"/> is missing from the schema", foundCatchAllCopyField);
    SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on");
    String xml = h.query(req);
    String result = TestHarness.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']");
    assertNull(xml, result);
    // Put back the configuration expected by the rest of the tests in this suite
    deleteCore();
    initCore("solrconfig.xml", "schema12.xml");
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 95 with IndexSchema

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

the class CursorMarkTest method testRoundTripParsing.

public void testRoundTripParsing() throws IOException {
    // for any valid SortSpec, and any legal values, we should be able to round 
    // trip serialize the totem and get the same values back.
    final Collection<String> allFieldNames = getAllFieldNames();
    final SolrQueryRequest req = req();
    final IndexSchema schema = req.getSchema();
    final int numRandomSorts = atLeast(50);
    final int numRandomValIters = atLeast(10);
    for (int i = 0; i < numRandomSorts; i++) {
        final SortSpec ss = SortSpecParsing.parseSortSpec(CursorPagingTest.buildRandomSort(allFieldNames), req);
        final CursorMark totemIn = new CursorMark(schema, ss);
        final CursorMark totemOut = new CursorMark(schema, ss);
        // trivial case: regardless of sort, "*" should be valid and roundtrippable
        totemIn.parseSerializedTotem(CURSOR_MARK_START);
        assertEquals(CURSOR_MARK_START, totemIn.getSerializedTotem());
        // values should be null (and still roundtrippable)
        assertNull(totemIn.getSortValues());
        totemOut.setSortValues(null);
        assertEquals(CURSOR_MARK_START, totemOut.getSerializedTotem());
        for (int j = 0; j < numRandomValIters; j++) {
            final Object[] inValues = buildRandomSortObjects(ss);
            totemIn.setSortValues(Arrays.<Object>asList(inValues));
            totemOut.parseSerializedTotem(totemIn.getSerializedTotem());
            final List<Object> out = totemOut.getSortValues();
            assertNotNull(out);
            final Object[] outValues = out.toArray();
            assertArrayEquals(inValues, outValues);
        }
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) 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