use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestWordDelimiterFilterFactory method testCustomTypes.
@Test
public void testCustomTypes() throws Exception {
String testText = "I borrowed $5,400.00 at 25% interest-rate";
ResourceLoader loader = new SolrResourceLoader(TEST_PATH().resolve("collection1"));
Map<String, String> args = new HashMap<>();
args.put("luceneMatchVersion", Version.LATEST.toString());
args.put("generateWordParts", "1");
args.put("generateNumberParts", "1");
args.put("catenateWords", "1");
args.put("catenateNumbers", "1");
args.put("catenateAll", "0");
args.put("splitOnCaseChange", "1");
/* default behavior */
WordDelimiterFilterFactory factoryDefault = new WordDelimiterFilterFactory(args);
factoryDefault.inform(loader);
TokenStream ts = factoryDefault.create(whitespaceMockTokenizer(testText));
BaseTokenStreamTestCase.assertTokenStreamContents(ts, new String[] { "I", "borrowed", "5", "540000", "400", "00", "at", "25", "interest", "interestrate", "rate" });
ts = factoryDefault.create(whitespaceMockTokenizer("foobar"));
BaseTokenStreamTestCase.assertTokenStreamContents(ts, new String[] { "foo", "foobar", "bar" });
/* custom behavior */
args = new HashMap<>();
// use a custom type mapping
args.put("luceneMatchVersion", Version.LATEST.toString());
args.put("generateWordParts", "1");
args.put("generateNumberParts", "1");
args.put("catenateWords", "1");
args.put("catenateNumbers", "1");
args.put("catenateAll", "0");
args.put("splitOnCaseChange", "1");
args.put("types", "wdftypes.txt");
WordDelimiterFilterFactory factoryCustom = new WordDelimiterFilterFactory(args);
factoryCustom.inform(loader);
ts = factoryCustom.create(whitespaceMockTokenizer(testText));
BaseTokenStreamTestCase.assertTokenStreamContents(ts, new String[] { "I", "borrowed", "$5,400.00", "at", "25%", "interest", "interestrate", "rate" });
/* test custom behavior with a char > 0x7F, because we had to make a larger byte[] */
ts = factoryCustom.create(whitespaceMockTokenizer("foobar"));
BaseTokenStreamTestCase.assertTokenStreamContents(ts, new String[] { "foobar" });
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestClusteringResponse method testClusteringResponse.
@Test
public void testClusteringResponse() throws Exception {
XMLResponseParser parser = new XMLResponseParser();
/*Load a simple XML with the clustering response encoded in an XML format*/
InputStream is = new SolrResourceLoader().openResource("solrj/sampleClusteringResponse.xml");
assertNotNull(is);
Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
NamedList<Object> response = parser.processResponse(in);
in.close();
QueryResponse qr = new QueryResponse(response, null);
ClusteringResponse clusteringResponse = qr.getClusteringResponse();
List<Cluster> clusters = clusteringResponse.getClusters();
Assert.assertEquals(4, clusters.size());
checkCluster(clusters.get(0), Arrays.asList("label1"), Arrays.asList("id1", "id2", "id3"), 0.6d, false);
checkCluster(clusters.get(1), Arrays.asList("label2"), Arrays.asList("id5", "id6"), 0.93d, false);
checkCluster(clusters.get(2), Arrays.asList("label3"), Arrays.asList("id7", "id8"), 1.26d, false);
checkCluster(clusters.get(3), Arrays.asList("label4"), Arrays.asList("id9"), 0d, true);
List<Cluster> sub = clusters.get(0).getSubclusters();
checkCluster(sub.get(0), Arrays.asList("label1.sub1"), Arrays.asList("id1", "id2"), 0.0d, false);
checkCluster(sub.get(1), Arrays.asList("label1.sub2"), Arrays.asList("id2"), 0.0d, false);
assertEquals(sub.size(), 2);
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class QueryResponseTest method testRangeFacets.
@Test
public void testRangeFacets() throws Exception {
XMLResponseParser parser = new XMLResponseParser();
InputStream is = new SolrResourceLoader().openResource("solrj/sampleRangeFacetResponse.xml");
assertNotNull(is);
Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
NamedList<Object> response = parser.processResponse(in);
in.close();
QueryResponse qr = new QueryResponse(response, null);
Assert.assertNotNull(qr);
int counter = 0;
RangeFacet.Numeric price = null;
RangeFacet.Date manufacturedateDt = null;
for (RangeFacet r : qr.getFacetRanges()) {
assertNotNull(r);
if ("price".equals(r.getName())) {
price = (RangeFacet.Numeric) r;
} else if ("manufacturedate_dt".equals(r.getName())) {
manufacturedateDt = (RangeFacet.Date) r;
}
counter++;
}
assertEquals(2, counter);
assertNotNull(price);
assertNotNull(manufacturedateDt);
assertEquals(0.0F, price.getStart());
assertEquals(5.0F, price.getEnd());
assertEquals(1.0F, price.getGap());
assertEquals("0.0", price.getCounts().get(0).getValue());
assertEquals(3, price.getCounts().get(0).getCount());
assertEquals("1.0", price.getCounts().get(1).getValue());
assertEquals(0, price.getCounts().get(1).getCount());
assertEquals("2.0", price.getCounts().get(2).getValue());
assertEquals(0, price.getCounts().get(2).getCount());
assertEquals("3.0", price.getCounts().get(3).getValue());
assertEquals(0, price.getCounts().get(3).getCount());
assertEquals("4.0", price.getCounts().get(4).getValue());
assertEquals(0, price.getCounts().get(4).getCount());
assertEquals(new Date(Instant.parse("2005-02-13T15:26:37Z").toEpochMilli()), manufacturedateDt.getStart());
assertEquals(new Date(Instant.parse("2008-02-13T15:26:37Z").toEpochMilli()), manufacturedateDt.getEnd());
assertEquals("+1YEAR", manufacturedateDt.getGap());
assertEquals("2005-02-13T15:26:37Z", manufacturedateDt.getCounts().get(0).getValue());
assertEquals(4, manufacturedateDt.getCounts().get(0).getCount());
assertEquals("2006-02-13T15:26:37Z", manufacturedateDt.getCounts().get(1).getValue());
assertEquals(7, manufacturedateDt.getCounts().get(1).getCount());
assertEquals("2007-02-13T15:26:37Z", manufacturedateDt.getCounts().get(2).getValue());
assertEquals(0, manufacturedateDt.getCounts().get(2).getCount());
assertEquals(90, manufacturedateDt.getBefore());
assertEquals(1, manufacturedateDt.getAfter());
assertEquals(11, manufacturedateDt.getBetween());
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestManagedResourceStorage method testZkBasedJsonStorage.
/**
* Runs persisted managed resource creation and update tests on Zookeeper storage.
*/
@Test
public void testZkBasedJsonStorage() throws Exception {
// test using ZooKeeper
assertTrue("Not using ZooKeeper", h.getCoreContainer().isZooKeeperAware());
SolrZkClient zkClient = h.getCoreContainer().getZkController().getZkClient();
SolrResourceLoader loader = new SolrResourceLoader(Paths.get("./"));
// Solr unit tests can only write to their working directory due to
// a custom Java Security Manager installed in the test environment
NamedList<String> initArgs = new NamedList<>();
try {
ZooKeeperStorageIO zkStorageIO = new ZooKeeperStorageIO(zkClient, "/test");
zkStorageIO.configure(loader, initArgs);
doStorageTests(loader, zkStorageIO);
} finally {
loader.close();
}
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestManagedResourceStorage method testFileBasedJsonStorage.
/**
* Runs persisted managed resource creation and update tests on JSON storage.
*/
@Test
public void testFileBasedJsonStorage() throws Exception {
File instanceDir = createTempDir("json-storage").toFile();
SolrResourceLoader loader = new SolrResourceLoader(instanceDir.toPath());
try {
NamedList<String> initArgs = new NamedList<>();
String managedDir = instanceDir.getAbsolutePath() + File.separator + "managed";
initArgs.add(ManagedResourceStorage.STORAGE_DIR_INIT_ARG, managedDir);
FileStorageIO fileStorageIO = new FileStorageIO();
fileStorageIO.configure(loader, initArgs);
doStorageTests(loader, fileStorageIO);
} finally {
loader.close();
}
}
Aggregations