use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class TestSearcherReuse method test.
public void test() throws Exception {
// seed some docs & segments
int numDocs = atLeast(1);
for (int i = 1; i <= numDocs; i++) {
// NOTE: starting at "1", we'll use id=0 later
assertU(adoc("id", "" + i));
if (random().nextBoolean()) {
assertU(commit());
}
}
// with random merge policies, a regular commit can cause a segment to be flushed that can kick off a background merge
// that can cause a later commit to actually see changes and open a new searcher. This should not be possible with optimize
assertU(optimize());
// seed a single query into the cache
assertQ(req("*:*"), "//*[@numFound='" + numDocs + "']");
final SolrQueryRequest baseReq = req("q", "foo");
try {
// we make no index changes in this block, so the searcher should always be the same
// NOTE: we *have* to call getSearcher() in advance, it's a delayed binding
final SolrIndexSearcher expectedSearcher = getMainSearcher(baseReq);
assertU(commit());
assertSearcherHasNotChanged(expectedSearcher);
assertU(commit("openSearcher", "true"));
assertSearcherHasNotChanged(expectedSearcher);
assertU(commit("softCommit", "true"));
assertSearcherHasNotChanged(expectedSearcher);
assertU(commit("softCommit", "true", "openSearcher", "true"));
assertSearcherHasNotChanged(expectedSearcher);
assertU(delQ("id:match_no_documents"));
assertU(commit("softCommit", "true", "openSearcher", "true"));
assertSearcherHasNotChanged(expectedSearcher);
// no doc has this id, yet
assertU(delI("0"));
assertU(commit("softCommit", "true", "openSearcher", "true"));
assertSearcherHasNotChanged(expectedSearcher);
} finally {
baseReq.close();
}
// now do a variety of things that *should* always guarantee a new searcher
SolrQueryRequest beforeReq;
beforeReq = req("q", "foo");
try {
// NOTE: we *have* to call getSearcher() in advance: delayed binding
SolrIndexSearcher before = getMainSearcher(beforeReq);
assertU(delI("1"));
assertU(commit());
assertSearcherHasChanged(before);
} finally {
beforeReq.close();
}
beforeReq = req("q", "foo");
try {
// NOTE: we *have* to call getSearcher() in advance: delayed binding
SolrIndexSearcher before = getMainSearcher(beforeReq);
assertU(adoc("id", "0"));
assertU(commit());
assertSearcherHasChanged(before);
} finally {
beforeReq.close();
}
beforeReq = req("q", "foo");
try {
// NOTE: we *have* to call getSearcher() in advance: delayed binding
SolrIndexSearcher before = getMainSearcher(beforeReq);
assertU(delQ("id:[0 TO 5]"));
assertU(commit());
assertSearcherHasChanged(before);
} finally {
beforeReq.close();
}
beforeReq = req("q", "foo");
try {
// NOTE: we *have* to call getSearcher() in advance: delayed binding
SolrIndexSearcher before = getMainSearcher(beforeReq);
// create a new field & add it.
assertTrue("schema not mutable", beforeReq.getSchema().isMutable());
ManagedIndexSchema oldSchema = (ManagedIndexSchema) beforeReq.getSchema();
SchemaField newField = oldSchema.newField("hoss", "string", Collections.<String, Object>emptyMap());
IndexSchema newSchema = oldSchema.addField(newField);
h.getCore().setLatestSchema(newSchema);
// sanity check, later asserts assume this
assertNotSame(oldSchema, newSchema);
// the schema has changed - but nothing has requested a new Searcher yet
assertSearcherHasNotChanged(before);
// only now should we get a new searcher...
assertU(commit("softCommit", "true", "openSearcher", "true"));
assertSearcherHasChanged(before);
// sanity that opening the new searcher was useful to get new schema...
SolrQueryRequest afterReq = req("q", "foo");
try {
assertSame(newSchema, afterReq.getSchema());
assertSame(newSchema, getMainSearcher(afterReq).getSchema());
} finally {
afterReq.close();
}
} finally {
beforeReq.close();
}
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class TestSolr4Spatial method testSpatialConfig.
@Test
public void testSpatialConfig() throws Exception {
try (SolrCore core = h.getCoreInc()) {
IndexSchema schema = core.getLatestSchema();
// BBox Config
// Make sure the subfields are not stored
SchemaField sub = schema.getField("bbox" + BBoxStrategy.SUFFIX_MINX);
assertFalse(sub.stored());
// Make sure solr field type is also not stored
BBoxField bbox = (BBoxField) schema.getField("bbox").getType();
BBoxStrategy strategy = bbox.getStrategy("bbox");
assertFalse(strategy.getFieldType().stored());
}
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValued.
// SOLR-6024
public void testFieldStatisticsDocValuesAndMultiValued() throws Exception {
SolrCore core = h.getCore();
// precondition for the test
SchemaField catDocValues = core.getLatestSchema().getField("cat_docValues");
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("cat_docValues", new IRange(2, 2), new SVal('a', 'z', 1, 30)));
Doc d1 = createDoc(types);
d1.getValues("id").set(0, "1");
d1.getValues("cat_docValues").set(0, "test");
d1.getValues("cat_docValues").set(1, "testtw");
updateJ(toJSON(d1), null);
Doc d2 = createDoc(types);
d2.getValues("id").set(0, "2");
d2.getValues("cat_docValues").set(0, "test");
d2.getValues("cat_docValues").set(1, "testtt");
updateJ(toJSON(d2), null);
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "cat_docValues");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test min/max on docValues and multiValued", req, "//lst[@name='cat_docValues']/str[@name='min'][.='test']", "//lst[@name='cat_docValues']/str[@name='max'][.='testtw']");
assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}cat_docValues"), "//lst[@name='cat_docValues']/long[@name='cardinality'][.='3']");
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class StatsComponentTest method testFieldStatisticsDocValuesAndMultiValuedDouble.
public void testFieldStatisticsDocValuesAndMultiValuedDouble() throws Exception {
SolrCore core = h.getCore();
String fieldName = "cat_floatDocValues";
// 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 FVal(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());
final SolrParams baseParams = params(CommonParams.Q, "*:*", "indent", "true", StatsParams.STATS, "true");
SolrQueryRequest req1 = req(baseParams, StatsParams.STATS_CALC_DISTINCT, "true", StatsParams.STATS_FIELD, fieldName);
SolrQueryRequest req2 = req(baseParams, StatsParams.STATS_FIELD, "{!min=true, max=true, count=true, sum=true, mean=true, stddev=true, sumOfSquares=true, missing=true, calcdistinct=true}" + fieldName);
SolrQueryRequest req3 = req(baseParams, StatsParams.STATS_FIELD, "{!min=true, max=true, count=true, sum=true, mean=true, stddev=true, sumOfSquares=true, missing=true, countDistinct=true, distinctValues=true}" + fieldName);
for (SolrQueryRequest req : new SolrQueryRequest[] { req1, req2, req3 }) {
assertQ("test status on docValues and multiValued: " + req.toString(), 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 + "']/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']", "//lst[@name='" + fieldName + "']/long[@name='countDistinct'][.='9']", // always comes along with countDistinct
"count(//lst[@name='" + fieldName + "']/arr[@name='distinctValues']/float)=9", // if new default stats are added, this will break - update test to assert values for each
"count(//lst[@name='" + fieldName + "']/*)=10");
}
assertQ("cardinality", req("q", "*:*", "stats", "true", "stats.field", "{!cardinality=true}" + fieldName), "//lst[@name='" + fieldName + "']/long[@name='cardinality'][.='9']");
}
use of org.apache.solr.schema.SchemaField in project lucene-solr by apache.
the class StatsComponentTest method testStatsFacetMultivaluedErrorHandling.
public void testStatsFacetMultivaluedErrorHandling() throws Exception {
SolrCore core = h.getCore();
SchemaField foo_ss = core.getLatestSchema().getField("foo_ss");
assertU(adoc("id", "1", "active_i", "1", "foo_ss", "aa"));
assertU(commit());
assertU(adoc("id", "2", "active_i", "1", "foo_ss", "bb"));
assertU(adoc("id", "3", "active_i", "5", "foo_ss", "aa"));
assertU(commit());
assertTrue("schema no longer satisfies test requirements: foo_ss no longer multivalued", foo_ss.multiValued());
assertTrue("schema no longer satisfies test requirements: foo_ss's fieldtype no longer single valued", !foo_ss.getType().isMultiValued());
assertQEx("no failure trying to get stats facet on foo_ss", req("q", "*:*", "stats", "true", "stats.field", "active_i", "stats.facet", "foo_ss"), 400);
}
Aggregations