use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class SolrExampleTests method testMultiContentStreamRequest.
@Test
public void testMultiContentStreamRequest() throws Exception {
SolrClient client = getSolrClient();
// delete everything!
client.deleteByQuery("*:*");
client.commit();
QueryResponse rsp = client.query(new SolrQuery("*:*"));
Assert.assertEquals(0, rsp.getResults().getNumFound());
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
// 2
up.addFile(getFile("solrj/docs1.xml"), "application/xml");
// 3
up.addFile(getFile("solrj/docs2.xml"), "application/xml");
up.setParam("a", "ሴ");
up.setParam(CommonParams.HEADER_ECHO_PARAMS, CommonParams.EchoParamStyle.ALL.toString());
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
NamedList<Object> result = client.request(up);
Assert.assertEquals("ሴ", ((NamedList) ((NamedList) result.get("responseHeader")).get("params")).get("a"));
assertNotNull("Couldn't upload xml files", result);
rsp = client.query(new SolrQuery("*:*"));
Assert.assertEquals(5, rsp.getResults().getNumFound());
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class SolrExampleTests method testExampleConfig.
/**
* query the example
*/
@Test
public void testExampleConfig() throws Exception {
SolrClient client = getSolrClient();
// Empty the database...
// delete everything!
client.deleteByQuery("*:*");
// Now add something...
SolrInputDocument doc = new SolrInputDocument();
String docID = "1112211111";
doc.addField("id", docID);
doc.addField("name", "my name!");
Assert.assertEquals(null, doc.getField("foo"));
Assert.assertTrue(doc.getField("name").getValue() != null);
UpdateResponse upres = client.add(doc);
// System.out.println( "ADD:"+upres.getResponse() );
Assert.assertEquals(0, upres.getStatus());
upres = client.commit(true, true);
// System.out.println( "COMMIT:"+upres.getResponse() );
Assert.assertEquals(0, upres.getStatus());
upres = client.optimize(true, true);
// System.out.println( "OPTIMIZE:"+upres.getResponse() );
Assert.assertEquals(0, upres.getStatus());
SolrQuery query = new SolrQuery();
query.setQuery("id:" + docID);
QueryResponse response = client.query(query);
Assert.assertEquals(docID, response.getResults().get(0).getFieldValue("id"));
// Now add a few docs for facet testing...
List<SolrInputDocument> docs = new ArrayList<>();
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField("id", "2");
doc2.addField("inStock", true);
doc2.addField("price", 2);
doc2.addField("timestamp_dt", new java.util.Date());
docs.add(doc2);
SolrInputDocument doc3 = new SolrInputDocument();
doc3.addField("id", "3");
doc3.addField("inStock", false);
doc3.addField("price", 3);
doc3.addField("timestamp_dt", new java.util.Date());
docs.add(doc3);
SolrInputDocument doc4 = new SolrInputDocument();
doc4.addField("id", "4");
doc4.addField("inStock", true);
doc4.addField("price", 4);
doc4.addField("timestamp_dt", new java.util.Date());
docs.add(doc4);
SolrInputDocument doc5 = new SolrInputDocument();
doc5.addField("id", "5");
doc5.addField("inStock", false);
doc5.addField("price", 5);
doc5.addField("timestamp_dt", new java.util.Date());
docs.add(doc5);
upres = client.add(docs);
// System.out.println( "ADD:"+upres.getResponse() );
Assert.assertEquals(0, upres.getStatus());
upres = client.commit(true, true);
// System.out.println( "COMMIT:"+upres.getResponse() );
Assert.assertEquals(0, upres.getStatus());
upres = client.optimize(true, true);
// System.out.println( "OPTIMIZE:"+upres.getResponse() );
Assert.assertEquals(0, upres.getStatus());
query = new SolrQuery("*:*");
query.addFacetQuery("price:[* TO 2]");
query.addFacetQuery("price:[2 TO 4]");
query.addFacetQuery("price:[5 TO *]");
query.addFacetField("inStock");
query.addFacetField("price");
query.addFacetField("timestamp_dt");
query.removeFilterQuery("inStock:true");
response = client.query(query);
Assert.assertEquals(0, response.getStatus());
Assert.assertEquals(5, response.getResults().getNumFound());
Assert.assertEquals(3, response.getFacetQuery().size());
Assert.assertEquals(2, response.getFacetField("inStock").getValueCount());
Assert.assertEquals(4, response.getFacetField("price").getValueCount());
// test a second query, test making a copy of the main query
SolrQuery query2 = query.getCopy();
query2.addFilterQuery("inStock:true");
Assert.assertFalse(query.getFilterQueries() == query2.getFilterQueries());
response = client.query(query2);
Assert.assertEquals(1, query2.getFilterQueries().length);
Assert.assertEquals(0, response.getStatus());
Assert.assertEquals(2, response.getResults().getNumFound());
for (SolrDocument outDoc : response.getResults()) {
assertEquals(true, outDoc.getFieldValue("inStock"));
}
// sanity check round tripping of params...
query = new SolrQuery("foo");
query.addFilterQuery("{!field f=inStock}true");
query.addFilterQuery("{!term f=name}hoss");
query.addFacetQuery("price:[* TO 2]");
query.addFacetQuery("price:[2 TO 4]");
response = client.query(query);
assertTrue("echoed params are not a NamedList: " + response.getResponseHeader().get("params").getClass(), response.getResponseHeader().get("params") instanceof NamedList);
NamedList echo = (NamedList) response.getResponseHeader().get("params");
List values = null;
assertEquals("foo", echo.get("q"));
assertTrue("echoed fq is not a List: " + echo.get("fq").getClass(), echo.get("fq") instanceof List);
values = (List) echo.get("fq");
Assert.assertEquals(2, values.size());
Assert.assertEquals("{!field f=inStock}true", values.get(0));
Assert.assertEquals("{!term f=name}hoss", values.get(1));
assertTrue("echoed facet.query is not a List: " + echo.get("facet.query").getClass(), echo.get("facet.query") instanceof List);
values = (List) echo.get("facet.query");
Assert.assertEquals(2, values.size());
Assert.assertEquals("price:[* TO 2]", values.get(0));
Assert.assertEquals("price:[2 TO 4]", values.get(1));
if (jetty != null) {
// check system wide system handler + "/admin/info/system"
String url = jetty.getBaseUrl().toString();
try (HttpSolrClient adminClient = getHttpSolrClient(url)) {
SolrQuery q = new SolrQuery();
q.set("qt", "/admin/info/system");
QueryResponse rsp = adminClient.query(q);
assertNotNull(rsp.getResponse().get("mode"));
assertNotNull(rsp.getResponse().get("lucene"));
}
}
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class SolrExampleTests method testAugmentFields.
@Test
public void testAugmentFields() throws Exception {
SolrClient client = getSolrClient();
// Empty the database...
// delete everything!
client.deleteByQuery("*:*");
// Now add something...
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "111");
doc.addField("name", "doc1");
doc.addField("price", 11);
client.add(doc);
// make sure this gets in first
client.commit();
doc = new SolrInputDocument();
doc.addField("id", "222");
doc.addField("name", "doc2");
doc.addField("price", 22);
client.add(doc);
client.commit();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.set(CommonParams.FL, "id,price,[docid],[explain style=nl],score,aaa:[value v=aaa],ten:[value v=10 t=int]");
query.addSort(new SolrQuery.SortClause("price", SolrQuery.ORDER.asc));
QueryResponse rsp = client.query(query);
SolrDocumentList out = rsp.getResults();
assertEquals(2, out.getNumFound());
SolrDocument out1 = out.get(0);
SolrDocument out2 = out.get(1);
assertEquals("111", out1.getFieldValue("id"));
assertEquals("222", out2.getFieldValue("id"));
assertEquals(1.0f, out1.getFieldValue("score"));
assertEquals(1.0f, out2.getFieldValue("score"));
// check that the docid is one bigger
int id1 = (Integer) out1.getFieldValue("[docid]");
int id2 = (Integer) out2.getFieldValue("[docid]");
assertTrue("should be bigger [" + id1 + "," + id2 + "]", id2 > id1);
// The score from explain should be the same as the score
NamedList explain = (NamedList) out1.getFieldValue("[explain]");
assertEquals(out1.get("score"), explain.get("value"));
// Augmented _value_ with alias
assertEquals("aaa", out1.get("aaa"));
assertEquals(10, ((Integer) out1.get("ten")).intValue());
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class AnlysisResponseBaseTest method testBuildTokenInfo.
/**
* Tests the {@link AnalysisResponseBase#buildTokenInfo(org.apache.solr.common.util.NamedList)} method.
*/
@Test
public void testBuildTokenInfo() throws Exception {
NamedList tokenNL = new NamedList();
tokenNL.add("text", "JUMPING");
tokenNL.add("type", "word");
tokenNL.add("start", 0);
tokenNL.add("end", 7);
tokenNL.add("position", 1);
AnalysisResponseBase response = new AnalysisResponseBase();
AnalysisResponseBase.TokenInfo tokenInfo = response.buildTokenInfo(tokenNL);
assertEquals("JUMPING", tokenInfo.getText());
assertEquals(null, tokenInfo.getRawText());
assertEquals("word", tokenInfo.getType());
assertEquals(0, tokenInfo.getStart());
assertEquals(7, tokenInfo.getEnd());
assertEquals(1, tokenInfo.getPosition());
assertFalse(tokenInfo.isMatch());
tokenNL.add("rawText", "JUMPING1");
tokenNL.add("match", true);
tokenInfo = response.buildTokenInfo(tokenNL);
assertEquals("JUMPING", tokenInfo.getText());
assertEquals("JUMPING1", tokenInfo.getRawText());
assertEquals("word", tokenInfo.getType());
assertEquals(0, tokenInfo.getStart());
assertEquals(7, tokenInfo.getEnd());
assertEquals(1, tokenInfo.getPosition());
assertTrue(tokenInfo.isMatch());
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class AnlysisResponseBaseTest method testBuildPhases.
/**
* Tests the {@link AnalysisResponseBase#buildPhases(org.apache.solr.common.util.NamedList)} )} method.
*/
@Test
public void testBuildPhases() throws Exception {
final AnalysisResponseBase.TokenInfo tokenInfo = new AnalysisResponseBase.TokenInfo("text", null, "type", 0, 3, 1, false);
NamedList nl = new NamedList();
nl.add("Tokenizer", buildFakeTokenInfoList(6));
nl.add("Filter1", buildFakeTokenInfoList(5));
nl.add("Filter2", buildFakeTokenInfoList(4));
nl.add("Filter3", buildFakeTokenInfoList(3));
AnalysisResponseBase response = new AnalysisResponseBase() {
@Override
protected TokenInfo buildTokenInfo(NamedList tokenNL) {
return tokenInfo;
}
};
List<AnalysisResponseBase.AnalysisPhase> phases = response.buildPhases(nl);
assertEquals(4, phases.size());
assertPhase(phases.get(0), "Tokenizer", 6, tokenInfo);
assertPhase(phases.get(1), "Filter1", 5, tokenInfo);
assertPhase(phases.get(2), "Filter2", 4, tokenInfo);
assertPhase(phases.get(3), "Filter3", 3, tokenInfo);
}
Aggregations