use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class BasicFunctionalityTest method testLazyField.
@Test
public void testLazyField() throws IOException {
assertU(adoc("id", "7777", "title", "keyword", "test_hlt", mkstr(10000), "test_hlt", mkstr(20000), "test_hlt", mkstr(30000), "test_hlt", mkstr(40000)));
assertU(commit());
SolrCore core = h.getCore();
// initial request
SolrQueryRequest req = req("q", "id:7777", "fl", "id,title");
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
DocList dl = ((ResultContext) rsp.getResponse()).getDocList();
DocIterator di = dl.iterator();
Document d1 = req.getSearcher().doc(di.nextDoc());
IndexableField[] values1 = null;
// ensure fl field is non lazy, and non-fl field is lazy
assertFalse(d1.getField("title") instanceof LazyDocument.LazyField);
assertFalse(d1.getField("id") instanceof LazyDocument.LazyField);
values1 = d1.getFields("test_hlt");
assertEquals(4, values1.length);
for (int i = 0; i < values1.length; i++) {
assertTrue(values1[i] instanceof LazyDocument.LazyField);
LazyDocument.LazyField f = (LazyDocument.LazyField) values1[i];
assertFalse(f.hasBeenLoaded());
}
req.close();
// followup request, different fl
req = req("q", "id:7777", "fl", "id,test_hlt");
rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
dl = ((ResultContext) rsp.getResponse()).getDocList();
di = dl.iterator();
Document d2 = req.getSearcher().doc(di.nextDoc());
// ensure same doc, same lazy field now
assertTrue("Doc was not cached", d1 == d2);
IndexableField[] values2 = d2.getFields("test_hlt");
assertEquals(values1.length, values2.length);
for (int i = 0; i < values1.length; i++) {
assertSame("LazyField wasn't reused", values1[i], values2[i]);
LazyDocument.LazyField f = (LazyDocument.LazyField) values1[i];
// still not a real boy, no response writer in play
assertFalse(f.hasBeenLoaded());
}
// actuallize one value
assertNotNull(values2[0].stringValue());
for (int i = 0; i < values2.length; i++) {
// now all values for this field should be loaded & cached
LazyDocument.LazyField f = (LazyDocument.LazyField) values2[i];
assertTrue(f.hasBeenLoaded());
}
req.close();
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class AbstractCurrencyFieldTest method testMockExchangeRateProvider.
@Test
public void testMockExchangeRateProvider() throws Exception {
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
SchemaField amount = schema.getField("mock_amount");
// A few tests on the provider directly
ExchangeRateProvider p = ((CurrencyField) amount.getType()).getProvider();
Set<String> availableCurrencies = p.listAvailableCurrencies();
assert (availableCurrencies.size() == 3);
assert (p.reload() == true);
assert (p.getExchangeRate("USD", "EUR") == 0.8);
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class CopyFieldTest method testCopyFieldFunctionality.
@Test
public void testCopyFieldFunctionality() {
SolrCore core = h.getCore();
assertU(adoc("id", "5", "title", "test copy field", "text_en", "this is a simple test of the copy field functionality"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "text_en:simple");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("Make sure they got in", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']");
args = new HashMap<>();
args.put(CommonParams.Q, "highlight:simple");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic source", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']", "//result/doc[1]/arr[@name='highlight']/str[.='this is a simple test of ']");
args = new HashMap<>();
args.put(CommonParams.Q, "text_en:functionality");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("Make sure they got in", req, "//*[@numFound='1']");
args = new HashMap<>();
args.put(CommonParams.Q, "highlight:functionality");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic source", req, "//*[@numFound='0']");
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class DocValuesTest method testDocValues.
@Test
public void testDocValues() throws IOException {
assertU(adoc("id", "1"));
assertU(commit());
try (SolrCore core = h.getCoreInc()) {
final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
final SolrIndexSearcher searcher = searcherRef.get();
try {
final LeafReader reader = searcher.getSlowAtomicReader();
assertEquals(1, reader.numDocs());
final FieldInfos infos = reader.getFieldInfos();
assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("floatdv").getDocValuesType());
assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("intdv").getDocValuesType());
assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("doubledv").getDocValuesType());
assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("longdv").getDocValuesType());
assertEquals(DocValuesType.SORTED, infos.fieldInfo("stringdv").getDocValuesType());
assertEquals(DocValuesType.SORTED, infos.fieldInfo("booldv").getDocValuesType());
NumericDocValues dvs = reader.getNumericDocValues("floatdv");
assertEquals(0, dvs.nextDoc());
assertEquals((long) Float.floatToIntBits(1), dvs.longValue());
dvs = reader.getNumericDocValues("intdv");
assertEquals(0, dvs.nextDoc());
assertEquals(2L, dvs.longValue());
dvs = reader.getNumericDocValues("doubledv");
assertEquals(0, dvs.nextDoc());
assertEquals(Double.doubleToLongBits(3), dvs.longValue());
dvs = reader.getNumericDocValues("longdv");
assertEquals(0, dvs.nextDoc());
assertEquals(4L, dvs.longValue());
SortedDocValues sdv = reader.getSortedDocValues("stringdv");
assertEquals(0, sdv.nextDoc());
assertEquals("solr", sdv.binaryValue().utf8ToString());
sdv = reader.getSortedDocValues("booldv");
assertEquals(0, sdv.nextDoc());
assertEquals("T", sdv.binaryValue().utf8ToString());
final IndexSchema schema = core.getLatestSchema();
final SchemaField floatDv = schema.getField("floatdv");
final SchemaField intDv = schema.getField("intdv");
final SchemaField doubleDv = schema.getField("doubledv");
final SchemaField longDv = schema.getField("longdv");
final SchemaField boolDv = schema.getField("booldv");
FunctionValues values = floatDv.getType().getValueSource(floatDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
assertEquals(1f, values.floatVal(0), 0f);
assertEquals(1f, values.objectVal(0));
values = intDv.getType().getValueSource(intDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
assertEquals(2, values.intVal(0));
assertEquals(2, values.objectVal(0));
values = doubleDv.getType().getValueSource(doubleDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
assertEquals(3d, values.doubleVal(0), 0d);
assertEquals(3d, values.objectVal(0));
values = longDv.getType().getValueSource(longDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
assertEquals(4L, values.longVal(0));
assertEquals(4L, values.objectVal(0));
values = boolDv.getType().getValueSource(boolDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
assertEquals("true", values.strVal(0));
assertEquals(true, values.objectVal(0));
// check reversibility of created fields
tstToObj(schema.getField("floatdv"), -1.5f);
tstToObj(schema.getField("floatdvs"), -1.5f);
tstToObj(schema.getField("doubledv"), -1.5d);
tstToObj(schema.getField("doubledvs"), -1.5d);
tstToObj(schema.getField("intdv"), -7);
tstToObj(schema.getField("intdvs"), -7);
tstToObj(schema.getField("longdv"), -11L);
tstToObj(schema.getField("longdvs"), -11L);
tstToObj(schema.getField("datedv"), new Date(1000));
tstToObj(schema.getField("datedvs"), new Date(1000));
tstToObj(schema.getField("stringdv"), "foo");
tstToObj(schema.getField("stringdvs"), "foo");
tstToObj(schema.getField("booldv"), true);
tstToObj(schema.getField("booldvs"), true);
} finally {
searcherRef.decref();
}
}
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class TestIndexSearcher method testUseColdSearcher.
public void testUseColdSearcher() throws Exception {
MockSearchComponent.registerFirstSearcherListener = false;
MockSearchComponent.registerNewSearcherListener = false;
MockSearchComponent.registerSlowSearcherListener = true;
final AtomicBoolean querySucceeded = new AtomicBoolean(false);
SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
SlowSearcherListener.latch = new CountDownLatch(1);
CoreContainer cores = h.getCoreContainer();
CoreDescriptor cd = h.getCore().getCoreDescriptor();
final SolrCore newCore;
boolean coreCreated = false;
try {
System.setProperty("tests.solr.useColdSearcher", "true");
// Create a new core, this should call all the firstSearcherListeners
newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
coreCreated = true;
//validate that the new core was created with the correct solrconfig
assertNotNull(newCore.getSearchComponent("mock"));
assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
assertTrue(newCore.getSolrConfig().useColdSearcher);
Thread t = new Thread() {
public void run() {
try {
doQuery(newCore);
querySucceeded.set(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
;
};
t.start();
// validate that the query runs before the searcher warmer finishes
for (int i = 0; i <= 1000; i++) {
if (querySucceeded.get()) {
break;
}
if (i == 1000) {
fail("Query didn't succeed after 10 secoonds");
}
Thread.sleep(10);
}
assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
} finally {
System.getProperties().remove("tests.solr.useColdSearcher");
if (coreCreated) {
SlowSearcherListener.latch.countDown();
cores.unload("core1");
}
}
}
Aggregations