Search in sources :

Example 56 with SchemaField

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

the class TestCodecSupport method testPostingsFormats.

public void testPostingsFormats() {
    Codec codec = h.getCore().getCodec();
    Map<String, SchemaField> fields = h.getCore().getLatestSchema().getFields();
    SchemaField schemaField = fields.get("string_direct_f");
    PerFieldPostingsFormat format = (PerFieldPostingsFormat) codec.postingsFormat();
    assertEquals("Direct", format.getPostingsFormatForField(schemaField.getName()).getName());
    schemaField = fields.get("string_standard_f");
    assertEquals(TestUtil.getDefaultPostingsFormat().getName(), format.getPostingsFormatForField(schemaField.getName()).getName());
    schemaField = fields.get("string_f");
    assertEquals(TestUtil.getDefaultPostingsFormat().getName(), format.getPostingsFormatForField(schemaField.getName()).getName());
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) Codec(org.apache.lucene.codecs.Codec) PerFieldPostingsFormat(org.apache.lucene.codecs.perfield.PerFieldPostingsFormat)

Example 57 with SchemaField

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

the class TestCodecSupport method testDocValuesFormats.

public void testDocValuesFormats() {
    Codec codec = h.getCore().getCodec();
    Map<String, SchemaField> fields = h.getCore().getLatestSchema().getFields();
    SchemaField schemaField = fields.get("string_disk_f");
    PerFieldDocValuesFormat format = (PerFieldDocValuesFormat) codec.docValuesFormat();
    assertEquals(TestUtil.getDefaultDocValuesFormat().getName(), format.getDocValuesFormatForField(schemaField.getName()).getName());
    schemaField = fields.get("string_memory_f");
    assertEquals("Memory", format.getDocValuesFormatForField(schemaField.getName()).getName());
    schemaField = fields.get("string_f");
    assertEquals(TestUtil.getDefaultDocValuesFormat().getName(), format.getDocValuesFormatForField(schemaField.getName()).getName());
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) Codec(org.apache.lucene.codecs.Codec) PerFieldDocValuesFormat(org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat)

Example 58 with SchemaField

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

the class TestMinMaxOnMultiValuedField method beforeClass.

/** Initializes core and does some sanity checking of schema */
@BeforeClass
public static void beforeClass() throws Exception {
    initCore("solrconfig-functionquery.xml", "schema11.xml");
    // sanity check the expected properties of our fields (ie: who broke the schema?)
    IndexSchema schema = h.getCore().getLatestSchema();
    for (String type : new String[] { "i", "l", "f", "d" }) {
        for (String suffix : new String[] { "", "_dv", "_ni_dv" }) {
            String f = "val_t" + type + "s" + suffix;
            SchemaField sf = schema.getField(f);
            assertTrue(f + " is not multivalued", sf.multiValued());
            assertEquals(f + " doesn't have expected docValues status", f.contains("dv"), sf.hasDocValues());
            assertEquals(f + " doesn't have expected index status", !f.contains("ni"), sf.indexed());
        }
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema) BeforeClass(org.junit.BeforeClass)

Example 59 with SchemaField

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

the class TestSort method testRandomFieldNameSorts.

public void testRandomFieldNameSorts() throws Exception {
    SolrQueryRequest req = lrf.makeRequest("q", "*:*");
    final int iters = atLeast(5000);
    // infinite loop abort when trying to generate a non-blank sort "name"
    final int nonBlankAttempts = 37;
    for (int i = 0; i < iters; i++) {
        final StringBuilder input = new StringBuilder();
        final String[] names = new String[TestUtil.nextInt(r, 1, 10)];
        final boolean[] reverse = new boolean[names.length];
        for (int j = 0; j < names.length; j++) {
            names[j] = null;
            for (int k = 0; k < nonBlankAttempts && null == names[j]; k++) {
                names[j] = TestUtil.randomRealisticUnicodeString(r, 1, 100);
                // munge anything that might make this a function
                names[j] = names[j].replaceFirst("\\{", "\\{\\{");
                names[j] = names[j].replaceFirst("\\(", "\\(\\(");
                names[j] = names[j].replaceFirst("(\\\"|\\')", "$1$1z");
                names[j] = names[j].replaceFirst("(\\d)", "$1x");
                // eliminate pesky problem chars
                names[j] = names[j].replaceAll("\\p{Cntrl}|\\p{javaWhitespace}", "");
                if (0 == names[j].length()) {
                    names[j] = null;
                }
            }
            // with luck this bad, never go to vegas
            // alternatively: if (null == names[j]) names[j] = "never_go_to_vegas";
            assertNotNull("Unable to generate a (non-blank) names[" + j + "] after " + nonBlankAttempts + " attempts", names[j]);
            reverse[j] = r.nextBoolean();
            input.append(r.nextBoolean() ? " " : "");
            input.append(names[j]);
            input.append(" ");
            input.append(reverse[j] ? "desc," : "asc,");
        }
        input.deleteCharAt(input.length() - 1);
        SortField[] sorts = null;
        List<SchemaField> fields = null;
        try {
            SortSpec spec = SortSpecParsing.parseSortSpec(input.toString(), req);
            sorts = spec.getSort().getSort();
            fields = spec.getSchemaFields();
        } catch (RuntimeException e) {
            throw new RuntimeException("Failed to parse sort: " + input, e);
        }
        assertEquals("parsed sorts had unexpected size", names.length, sorts.length);
        assertEquals("parsed sort schema fields had unexpected size", names.length, fields.size());
        for (int j = 0; j < names.length; j++) {
            assertEquals("sorts[" + j + "] had unexpected reverse: " + input, reverse[j], sorts[j].getReverse());
            final Type type = sorts[j].getType();
            if (Type.SCORE.equals(type)) {
                assertEquals("sorts[" + j + "] is (unexpectedly) type score : " + input, "score", names[j]);
            } else if (Type.DOC.equals(type)) {
                assertEquals("sorts[" + j + "] is (unexpectedly) type doc : " + input, "_docid_", names[j]);
            } else if (Type.CUSTOM.equals(type) || Type.REWRITEABLE.equals(type)) {
                fail("sorts[" + j + "] resulted in a '" + type.toString() + "', either sort parsing code is broken, or func/query " + "semantics have gotten broader and munging in this test " + "needs improved: " + input);
            } else {
                assertEquals("sorts[" + j + "] (" + type.toString() + ") had unexpected field in: " + input, names[j], sorts[j].getField());
                assertEquals("fields[" + j + "] (" + type.toString() + ") had unexpected name in: " + input, names[j], fields.get(j).getName());
            }
        }
    }
}
Also used : SortField(org.apache.lucene.search.SortField) SchemaField(org.apache.solr.schema.SchemaField) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Type(org.apache.lucene.search.SortField.Type)

Example 60 with SchemaField

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

the class TestTrieFacet method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    initCore("solrconfig-tlog.xml", "schema.xml");
    // don't break the test
    assertTrue("min value must be less then max value", MIN_VALUE < MAX_VALUE);
    assertTrue("min value must be greater then zero", 0 < MIN_VALUE);
    // sanity check no one breaks the schema out from under us...
    for (String f : M_VALUED) {
        SchemaField sf = h.getCore().getLatestSchema().getField(f);
        assertTrue("who changed the schema? test isn't valid: " + f, sf.multiValued());
    }
    for (String f : S_VALUED) {
        SchemaField sf = h.getCore().getLatestSchema().getField(f);
        assertFalse("who changed the schema? test isn't valid: " + f, sf.multiValued());
    }
    for (String f : P0) {
        SchemaField sf = h.getCore().getLatestSchema().getField(f);
        assertEquals("who changed the schema? test isn't valid: " + f, 0, assertCastFieldType(sf).getPrecisionStep());
    }
    for (String f : P8) {
        SchemaField sf = h.getCore().getLatestSchema().getField(f);
        assertEquals("who changed the schema? test isn't valid: " + f, 8, assertCastFieldType(sf).getPrecisionStep());
    }
    // we don't need a lot of docs -- at least one failure only had ~1000  
    NUM_DOCS = TestUtil.nextInt(random(), 200, 1500);
    {
        // ensure at least one doc has every valid value in the multivalued fields
        SolrInputDocument doc = sdoc("id", "0");
        for (int val = MIN_VALUE; val <= MAX_VALUE; val++) {
            for (String f : M_VALUED) {
                doc.addField(f, val);
            }
        }
        assertU(adoc(doc));
    }
    // randomized docs (note: starting at i=1)
    for (int i = 1; i < NUM_DOCS; i++) {
        SolrInputDocument doc = sdoc("id", i + "");
        if (useField()) {
            int val = TestUtil.nextInt(random(), MIN_VALUE, MAX_VALUE);
            for (String f : S_VALUED) {
                doc.addField(f, val);
            }
        }
        if (useField()) {
            int numMulti = atLeast(1);
            while (0 < numMulti--) {
                int val = TestUtil.nextInt(random(), MIN_VALUE, MAX_VALUE);
                for (String f : M_VALUED) {
                    doc.addField(f, val);
                }
            }
        }
        assertU(adoc(doc));
    }
    assertU(commit());
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BeforeClass(org.junit.BeforeClass)

Aggregations

SchemaField (org.apache.solr.schema.SchemaField)167 SolrException (org.apache.solr.common.SolrException)45 FieldType (org.apache.solr.schema.FieldType)37 ArrayList (java.util.ArrayList)36 IndexSchema (org.apache.solr.schema.IndexSchema)32 NamedList (org.apache.solr.common.util.NamedList)27 BytesRef (org.apache.lucene.util.BytesRef)20 IOException (java.io.IOException)17 Query (org.apache.lucene.search.Query)17 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)17 HashMap (java.util.HashMap)16 Document (org.apache.lucene.document.Document)16 SolrParams (org.apache.solr.common.params.SolrParams)16 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)16 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)15 IndexableField (org.apache.lucene.index.IndexableField)14 Map (java.util.Map)13 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)13 SolrDocument (org.apache.solr.common.SolrDocument)13 SolrInputDocument (org.apache.solr.common.SolrInputDocument)13