Search in sources :

Example 81 with SchemaField

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

the class TestFacetMethods method testTextMultiValuedNoDV.

@Test
public void testTextMultiValuedNoDV() {
    SchemaField field = new SchemaField("field", new StrField(), MULTIVALUED, null);
    // default is FC, can't use FCS for multivalued fields, UIF rewrites to FC for mincount = 0
    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.FCS, 0));
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 0));
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 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.FCS, 1));
    assertEquals(SimpleFacets.FacetMethod.UIF, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.UIF, 1));
    assertEquals(SimpleFacets.FacetMethod.FC, SimpleFacets.selectFacetMethod(field, SimpleFacets.FacetMethod.FC, 1));
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) StrField(org.apache.solr.schema.StrField) Test(org.junit.Test)

Example 82 with SchemaField

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

the class SimpleFacetsTest method doEmptyFacetCounts.

static void doEmptyFacetCounts(String field, String[] prefixes) throws Exception {
    SchemaField sf = h.getCore().getLatestSchema().getField(field);
    String response = JQ(req("q", "*:*"));
    Map rsp = (Map) ObjectBuilder.fromJSON(response);
    Long numFound = (Long) (((Map) rsp.get("response")).get("numFound"));
    ModifiableSolrParams params = params("q", "*:*", "rows", "0", "facet", "true", "facet.field", "{!key=myalias}" + field);
    String[] methods = { null, "fc", "enum", "fcs", "uif" };
    if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
        methods = new String[] { null, "fc", "enum", "uif" };
    }
    prefixes = prefixes == null ? new String[] { null } : prefixes;
    for (String method : methods) {
        if (method == null) {
            params.remove("facet.method");
        } else {
            params.set("facet.method", method);
        }
        for (String prefix : prefixes) {
            if (prefix == null) {
                params.remove("facet.prefix");
            } else {
                params.set("facet.prefix", prefix);
            }
            for (String missing : new String[] { null, "true" }) {
                if (missing == null) {
                    params.remove("facet.missing");
                } else {
                    params.set("facet.missing", missing);
                }
                String expected = missing == null ? "[]" : "[null," + numFound + "]";
                assertJQ(req(params), "/facet_counts/facet_fields/myalias==" + expected);
            }
        }
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 83 with SchemaField

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

the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedIntegerFacetStats.

public void testFieldStatisticsDocValuesAndMultiValuedIntegerFacetStats() throws Exception {
    SolrCore core = h.getCore();
    String fieldName = "cat_intDocValues";
    // precondition for the test
    SchemaField catDocValues = core.getLatestSchema().getField(fieldName);
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
    List<FldType> types = new ArrayList<>();
    types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
    types.add(new FldType(fieldName, ONE_ONE, new IRange(0, 0)));
    Doc d1 = createDocValuesDocument(types, fieldName, "1", -1, 3, 5);
    updateJ(toJSON(d1), null);
    Doc d2 = createDocValuesDocument(types, fieldName, "2", 3, -2, 6);
    updateJ(toJSON(d2), null);
    Doc d3 = createDocValuesDocument(types, fieldName, "3", 16, -3, 11);
    updateJ(toJSON(d3), null);
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, fieldName);
    args.put(StatsParams.STATS_FACET, fieldName);
    args.put(StatsParams.STATS_CALC_DISTINCT, "true");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQEx("can not use FieldCache on multivalued field: cat_intDocValues", req, 400);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) SchemaField(org.apache.solr.schema.SchemaField) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams)

Example 84 with SchemaField

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

the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedInteger.

public void testFieldStatisticsDocValuesAndMultiValuedInteger() throws Exception {
    SolrCore core = h.getCore();
    String fieldName = "cat_intDocValues";
    // precondition for the test
    SchemaField catDocValues = core.getLatestSchema().getField(fieldName);
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer multivalued", catDocValues.multiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues fieldtype no longer single valued", !catDocValues.getType().isMultiValued());
    assertTrue("schema no longer satisfies test requirements: cat_docValues no longer has docValues", catDocValues.hasDocValues());
    List<FldType> types = new ArrayList<>();
    types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4)));
    types.add(new FldType(fieldName, ONE_ONE, new IRange(0, 0)));
    Doc d1 = createDocValuesDocument(types, fieldName, "1", -1, 3, 5);
    updateJ(toJSON(d1), null);
    Doc d2 = createDocValuesDocument(types, fieldName, "2", 3, -2, 6);
    updateJ(toJSON(d2), null);
    Doc d3 = createDocValuesDocument(types, fieldName, "3", 16, -3, 11);
    updateJ(toJSON(d3), null);
    assertU(commit());
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "*:*");
    args.put(StatsParams.STATS, "true");
    args.put(StatsParams.STATS_FIELD, fieldName);
    args.put(StatsParams.STATS_CALC_DISTINCT, "true");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("test min/max on docValues and multiValued", req, "//lst[@name='" + fieldName + "']/double[@name='min'][.='-3.0']", "//lst[@name='" + fieldName + "']/double[@name='max'][.='16.0']", "//lst[@name='" + fieldName + "']/long[@name='count'][.='12']", "//lst[@name='" + fieldName + "']/long[@name='countDistinct'][.='9']", "//lst[@name='" + fieldName + "']/double[@name='sum'][.='38.0']", "//lst[@name='" + fieldName + "']/double[@name='mean'][.='3.1666666666666665']", "//lst[@name='" + fieldName + "']/double[@name='stddev'][.='5.638074031784151']", "//lst[@name='" + fieldName + "']/double[@name='sumOfSquares'][.='470.0']", "//lst[@name='" + fieldName + "']/long[@name='missing'][.='0']");
    assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}" + fieldName), "//lst[@name='" + fieldName + "']/long[@name='cardinality'][.='9']");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) SchemaField(org.apache.solr.schema.SchemaField) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams)

Example 85 with SchemaField

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

the class StatsComponentTest method testHllOptionsErrors.

/**
   * Test user input errors (split into it's own test to isolate ignored exceptions
   * @see #testCardinality 
   * @see #testHllOptions
   */
public void testHllOptionsErrors() throws Exception {
    String[] baseParams = new String[] { "q", "*:*", "stats", "true", "indent", "true", "rows", "0" };
    SolrCore core = h.getCore();
    SchemaField foo_s = core.getLatestSchema().getField("foo_s");
    SchemaField foo_i = core.getLatestSchema().getField("foo_i");
    ignoreException("hllPreHashed");
    for (SchemaField field : new SchemaField[] { foo_s, foo_i }) {
        // whitebox - field
        try {
            HllOptions.parseHllOptions(params("cardinality", "true", "hllPreHashed", "true"), field);
            fail("hllPreHashed should have failed for " + field.getName());
        } catch (SolrException e) {
            assertTrue("MSG: " + e.getMessage(), e.getMessage().contains("hllPreHashed is only supported with Long"));
        }
        // blackbox - field
        assertQEx("hllPreHashed " + field.getName(), "hllPreHashed is only supported with Long", req(params("stats.field", "{!cardinality=true hllPreHashed=true}" + field.getName()), baseParams), ErrorCode.BAD_REQUEST);
    }
    // whitebox - function
    try {
        HllOptions.parseHllOptions(params("cardinality", "true", "hllPreHashed", "true"), null);
        fail("hllPreHashed should have failed for function");
    } catch (SolrException e) {
        assertTrue("MSG: " + e.getMessage(), e.getMessage().contains("hllPreHashed is only supported with Long"));
    }
    // blackbox - function
    assertQEx("hllPreHashed function", "hllPreHashed is only supported with Long", req(params("stats.field", "{!func cardinality=true hllPreHashed=true}sum(foo_i,foo_l)"), baseParams), ErrorCode.BAD_REQUEST);
    ignoreException("accuracy");
    for (String invalid : new String[] { "-1", "1.1", "100" }) {
        // whitebox
        try {
            Object trash = HllOptions.parseHllOptions(params("cardinality", invalid), foo_s);
            fail("Should have failed: " + invalid);
        } catch (SolrException e) {
            assertTrue("MSG: " + e.getMessage(), e.getMessage().contains("number between 0 and 1"));
        }
        // blackbox
        assertQEx("cardinality=" + invalid, "number between 0 and 1", req(params("stats.field", "{!cardinality=" + invalid + "}foo_s"), baseParams), ErrorCode.BAD_REQUEST);
    }
    ignoreException("hllLog2m must be");
    for (int invalid : new int[] { HLL.MINIMUM_LOG2M_PARAM - 1, HLL.MAXIMUM_LOG2M_PARAM + 11 }) {
        // whitebox
        try {
            Object trash = HllOptions.parseHllOptions(params("cardinality", "true", "hllLog2m", "" + invalid), foo_s);
            fail("Should have failed: " + invalid);
        } catch (SolrException e) {
            assertTrue("MSG: " + e.getMessage(), e.getMessage().contains("hllLog2m must be"));
        }
        // blackbox
        assertQEx("hllLog2m=" + invalid, "hllLog2m must be", req(params("stats.field", "{!cardinality=true hllLog2m=" + invalid + "}foo_s"), baseParams), ErrorCode.BAD_REQUEST);
    }
    ignoreException("hllRegwidth must be");
    for (int invalid : new int[] { HLL.MINIMUM_REGWIDTH_PARAM - 1, HLL.MAXIMUM_REGWIDTH_PARAM + 1 }) {
        // whitebox
        try {
            Object trash = HllOptions.parseHllOptions(params("cardinality", "true", "hllRegwidth", "" + invalid), foo_s);
            fail("Should have failed: " + invalid);
        } catch (SolrException e) {
            assertTrue("MSG: " + e.getMessage(), e.getMessage().contains("hllRegwidth must be"));
        }
        // blackbox
        assertQEx("hllRegwidth=" + invalid, "hllRegwidth must be", req(params("stats.field", "{!cardinality=true hllRegwidth=" + invalid + "}foo_s"), baseParams), ErrorCode.BAD_REQUEST);
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) SolrCore(org.apache.solr.core.SolrCore) SolrException(org.apache.solr.common.SolrException)

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