Search in sources :

Example 56 with IndexSchema

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

the class TestConfig method testDefaults.

// If defaults change, add test methods to cover each version
@Test
public void testDefaults() throws Exception {
    int numDefaultsTested = 0;
    int numNullDefaults = 0;
    SolrConfig sc = new SolrConfig(new SolrResourceLoader(TEST_PATH().resolve("collection1")), "solrconfig-defaults.xml", null);
    SolrIndexConfig sic = sc.indexConfig;
    ++numDefaultsTested;
    assertEquals("default useCompoundFile", false, sic.useCompoundFile);
    ++numDefaultsTested;
    assertEquals("default maxBufferedDocs", -1, sic.maxBufferedDocs);
    ++numDefaultsTested;
    assertEquals("default ramBufferSizeMB", 100.0D, sic.ramBufferSizeMB, 0.0D);
    ++numDefaultsTested;
    assertEquals("default writeLockTimeout", -1, sic.writeLockTimeout);
    ++numDefaultsTested;
    assertEquals("default LockType", DirectoryFactory.LOCK_TYPE_NATIVE, sic.lockType);
    ++numDefaultsTested;
    assertEquals("default infoStream", InfoStream.NO_OUTPUT, sic.infoStream);
    ++numDefaultsTested;
    assertNotNull("default metrics", sic.metricsInfo);
    ++numDefaultsTested;
    ++numNullDefaults;
    assertNull("default mergePolicyFactoryInfo", sic.mergePolicyFactoryInfo);
    ++numDefaultsTested;
    ++numNullDefaults;
    assertNull("default mergeSchedulerInfo", sic.mergeSchedulerInfo);
    ++numDefaultsTested;
    ++numNullDefaults;
    assertNull("default mergedSegmentWarmerInfo", sic.mergedSegmentWarmerInfo);
    IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig);
    IndexWriterConfig iwc = sic.toIndexWriterConfig(h.getCore());
    assertNotNull("null mp", iwc.getMergePolicy());
    assertTrue("mp is not TieredMergePolicy", iwc.getMergePolicy() instanceof TieredMergePolicy);
    assertNotNull("null ms", iwc.getMergeScheduler());
    assertTrue("ms is not CMS", iwc.getMergeScheduler() instanceof ConcurrentMergeScheduler);
    assertNull("non-null mergedSegmentWarmer", iwc.getMergedSegmentWarmer());
    final int numDefaultsMapped = sic.toMap(new LinkedHashMap<>()).size();
    assertEquals("numDefaultsTested vs. numDefaultsMapped+numNullDefaults =" + sic.toMap(new LinkedHashMap<>()).keySet(), numDefaultsTested, numDefaultsMapped + numNullDefaults);
}
Also used : TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) SolrIndexConfig(org.apache.solr.update.SolrIndexConfig) IndexSchema(org.apache.solr.schema.IndexSchema) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 57 with IndexSchema

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

the class UninvertDocValuesMergePolicyTest method implUpdateSchemaField.

private static void implUpdateSchemaField(TestHarness h, String fieldName, IntUnaryOperator propertiesModifier) {
    try (SolrCore core = h.getCoreInc()) {
        // Add docvalues to the field type
        IndexSchema schema = core.getLatestSchema();
        SchemaField oldSchemaField = schema.getField(fieldName);
        SchemaField newSchemaField = new SchemaField(fieldName, oldSchemaField.getType(), propertiesModifier.applyAsInt(oldSchemaField.getProperties()), oldSchemaField.getDefaultValue());
        schema.getFields().put(fieldName, newSchemaField);
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) SolrCore(org.apache.solr.core.SolrCore) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 58 with IndexSchema

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

the class LargeFieldTest method initManagedSchemaCore.

@BeforeClass
public static void initManagedSchemaCore() throws Exception {
    // This testing approach means no schema file or per-test temp solr-home!
    System.setProperty("managed.schema.mutable", "true");
    System.setProperty("managed.schema.resourceName", "schema-one-field-no-dynamic-field-unique-key.xml");
    System.setProperty("enable.update.log", "false");
    System.setProperty("documentCache.enabled", "true");
    System.setProperty("enableLazyFieldLoading", "true");
    initCore("solrconfig-managed-schema.xml", "ignoredSchemaName");
    // TODO SOLR-10229 will make this easier
    // don't write to test resource dir
    boolean PERSIST_FALSE = false;
    IndexSchema schema = h.getCore().getLatestSchema();
    schema = schema.addFieldTypes(Collections.singletonList(// redundant; TODO improve api
    schema.newFieldType(// redundant; TODO improve api
    "textType", // redundant; TODO improve api
    "solr.TextField", map("name", "textType", "class", "solr.TextField", "analyzer", map("class", "org.apache.lucene.analysis.standard.StandardAnalyzer")))), PERSIST_FALSE);
    schema = schema.addFields(Arrays.asList(schema.newField(LAZY_FIELD, "textType", map()), schema.newField(BIG_FIELD, "textType", map("large", true))), Collections.emptyMap(), PERSIST_FALSE);
    h.getCore().setLatestSchema(schema);
}
Also used : IndexSchema(org.apache.solr.schema.IndexSchema) BeforeClass(org.junit.BeforeClass)

Example 59 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseDoubleNonRootLocale.

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

Example 60 with IndexSchema

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

the class ParsingFieldUpdateProcessorsTest method testParseDateExplicitTypeClassSelector.

public void testParseDateExplicitTypeClassSelector() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNotNull(schema.getFieldOrNull("date_dt"));
    String dateString = "2010-11-12T13:14:15.168Z";
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateString);
    SolrInputDocument d;
    if (schema.getField("date_dt").getType().isPointField()) {
        d = processAdd("parse-date-explicit-typeclass-point-selector-no-run-processor", doc(f("id", "77"), f("date_dt", dateString)));
    } else {
        d = processAdd("parse-date-explicit-typeclass-selector-no-run-processor", doc(f("id", "77"), f("date_dt", dateString)));
    }
    assertNotNull(d);
    assertTrue(d.getFieldValue("date_dt") instanceof Date);
    assertEquals(dateTime.getMillis(), ((Date) d.getFieldValue("date_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)

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