Search in sources :

Example 51 with SchemaField

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

the class TestFacetMethods method testNumericSingleValuedDV.

@Test
public void testNumericSingleValuedDV() {
    SchemaField field = new SchemaField("field", new TrieIntField(), DOC_VALUES, null);
    // default is FCS, can't use ENUM due to trie-field terms, FC rewrites to FCS for efficiency
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, null, 0));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 0));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 0));
    assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 0));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 0));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, null, 1));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 1));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 1));
    assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 1));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 1));
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) TrieIntField(org.apache.solr.schema.TrieIntField) Test(org.junit.Test)

Example 52 with SchemaField

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

the class TestFacetMethods method testTextSingleValuedNoDV.

@Test
public void testTextSingleValuedNoDV() {
    SchemaField field = new SchemaField("field", new StrField(), 0, null);
    // default is FC, UIF rewrites to FCS for mincount = 0
    // TODO should it rewrite to FC instead?
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, null, 0));
    assertEquals(SimpleFacets.FacetMethod.ENUM, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 0));
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 0));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 0));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 0));
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, null, 1));
    assertEquals(SimpleFacets.FacetMethod.ENUM, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.ENUM, 1));
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 1));
    assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 1));
    assertEquals(SimpleFacets.FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FCS, 1));
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) StrField(org.apache.solr.schema.StrField) Test(org.junit.Test)

Example 53 with SchemaField

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

the class TestPseudoReturnFields method testMultiValued.

public void testMultiValued() throws Exception {
    // score as psuedo field - precondition checks
    for (String name : new String[] { "score", "val_ss" }) {
        SchemaField sf = h.getCore().getLatestSchema().getFieldOrNull(name);
        assertNotNull("Test depends on a (dynamic) field mtching '" + name + "', schema was changed out from under us!", sf);
        assertTrue("Test depends on a multivalued dynamic field matching '" + name + "', schema was changed out from under us!", sf.multiValued());
    }
    // score as psuedo field
    assertJQ(req("q", "*:*", "fq", "id:42", "fl", "id,score"), "/response/docs==[{'id':'42','score':1.0}]");
    // single value int using alias that matches multivalued dynamic field
    assertJQ(req("q", "id:42", "fl", "val_ss:val_i, val2_ss:10"), "/response/docs==[{'val2_ss':10,'val_ss':1}]");
    assertJQ(req("qt", "/get", "id", "42", "fl", "val_ss:val_i, val2_ss:10"), "/doc=={'val2_ss':10,'val_ss':1}");
}
Also used : SchemaField(org.apache.solr.schema.SchemaField)

Example 54 with SchemaField

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

the class TestAddFieldRealTimeGet method test.

public void test() throws Exception {
    clearIndex();
    assertU(commit());
    String newFieldName = "newfield";
    String newFieldType = "string";
    String newFieldValue = "xyz";
    assertFailedU("Should fail due to unknown field '" + newFieldName + "'", adoc("id", "1", newFieldName, newFieldValue));
    IndexSchema schema = h.getCore().getLatestSchema();
    SchemaField newField = schema.newField(newFieldName, newFieldType, Collections.<String, Object>emptyMap());
    IndexSchema newSchema = schema.addField(newField);
    h.getCore().setLatestSchema(newSchema);
    String newFieldKeyValue = "'" + newFieldName + "':'" + newFieldValue + "'";
    assertU(adoc("id", "1", newFieldName, newFieldValue));
    assertJQ(req("q", "id:1"), "/response/numFound==0");
    assertJQ(req("qt", "/get", "id", "1", "fl", "id," + newFieldName), "=={'doc':{'id':'1'," + newFieldKeyValue + "}}");
    assertJQ(req("qt", "/get", "ids", "1", "fl", "id," + newFieldName), "=={'response':{'numFound':1,'start':0,'docs':[{'id':'1'," + newFieldKeyValue + "}]}}");
    assertU(commit());
    assertJQ(req("q", "id:1"), "/response/numFound==1");
    assertJQ(req("qt", "/get", "id", "1", "fl", "id," + newFieldName), "=={'doc':{'id':'1'," + newFieldKeyValue + "}}");
    assertJQ(req("qt", "/get", "ids", "1", "fl", "id," + newFieldName), "=={'response':{'numFound':1,'start':0,'docs':[{'id':'1'," + newFieldKeyValue + "}]}}");
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 55 with SchemaField

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

the class CursorMarkTest method buildRandomSortObjects.

private static Object[] buildRandomSortObjects(SortSpec ss) throws IOException {
    List<SchemaField> fields = ss.getSchemaFields();
    assertNotNull(fields);
    Object[] results = new Object[fields.size()];
    for (int i = 0; i < results.length; i++) {
        SchemaField sf = fields.get(i);
        if (null == sf) {
            // score or function
            results[i] = (Float) random().nextFloat() * random().nextInt();
            break;
        } else if (0 == TestUtil.nextInt(random(), 0, 7)) {
            // emulate missing value for doc
            results[i] = null;
        } else {
            final String fieldName = sf.getName();
            assertNotNull(fieldName);
            // Note: In some cases we build a human readable version of the sort value and then 
            // unmarshall it into the raw, real, sort values that are expected by the FieldTypes.
            // In other cases we just build the raw value to begin with because it's easier
            Object val = null;
            if (fieldName.equals("id")) {
                val = sf.getType().unmarshalSortValue(TestUtil.randomSimpleString(random()));
            } else if (fieldName.startsWith("str")) {
                val = sf.getType().unmarshalSortValue(TestUtil.randomRealisticUnicodeString(random()));
            } else if (fieldName.startsWith("bin")) {
                byte[] randBytes = new byte[TestUtil.nextInt(random(), 1, 50)];
                random().nextBytes(randBytes);
                val = new BytesRef(randBytes);
            } else if (fieldName.contains("int")) {
                // TrieIntField
                val = random().nextInt();
            } else if (fieldName.contains("long")) {
                // TrieLongField
                val = random().nextLong();
            } else if (fieldName.contains("float")) {
                // TrieFloatField
                val = random().nextFloat() * random().nextInt();
            } else if (fieldName.contains("double")) {
                // TrieDoubleField
                val = random().nextDouble() * random().nextInt();
            } else if (fieldName.contains("date")) {
                // TrieDateField
                val = random().nextLong();
            } else if (fieldName.startsWith("currency")) {
                val = random().nextDouble();
            } else if (fieldName.startsWith("uuid")) {
                val = sf.getType().unmarshalSortValue(UUID.randomUUID().toString());
            } else if (fieldName.startsWith("bool")) {
                val = sf.getType().unmarshalSortValue(random().nextBoolean() ? "t" : "f");
            } else if (fieldName.startsWith("enum")) {
                val = random().nextInt(CursorPagingTest.SEVERITY_ENUM_VALUES.length);
            } else if (fieldName.contains("collation")) {
                val = getRandomCollation(sf);
            } else {
                fail("fell through the rabbit hole, new field in schema? = " + fieldName);
            }
            results[i] = val;
        }
    }
    return results;
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) BytesRef(org.apache.lucene.util.BytesRef)

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