本文整理汇总了Java中org.apache.solr.client.solrj.request.QueryRequest类的典型用法代码示例。如果您正苦于以下问题:Java QueryRequest类的具体用法?Java QueryRequest怎么用?Java QueryRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryRequest类属于org.apache.solr.client.solrj.request包,在下文中一共展示了QueryRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listRuntimeDependencies
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException {
ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/file");
request.setResponseParser(new InputStreamResponseParser("json"));
NamedList o = client.request(request, collectionName);
LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8");
List<String> returnValues = Streams.stream(it).collect(Collectors.toList());
//if file not exists (a little hacky..)
if(returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) {
logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually.");
return Collections.emptyList();
};
return returnValues;
}
示例2: createAlias
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
private void createAlias(String alias, String collections)
throws SolrServerException, IOException {
SolrServer server = createNewSolrServer("",
getBaseUrl((HttpSolrServer) clients.get(0)));
if (random().nextBoolean()) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("collections", collections);
params.set("name", alias);
params.set("action", CollectionAction.CREATEALIAS.toString());
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
server.request(request);
} else {
CollectionAdminRequest.CreateAlias.createAlias(alias, collections, server);
}
server.shutdown();
}
示例3: buildSolrRequest
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
@Override
protected QueryRequest buildSolrRequest(ComponentConfiguration conf, Template intent, Conversation conversation, long offset, int pageSize, MultiValueMap<String, String> queryParams) {
final ConversationMltQuery mltQuery = buildQuery(conf, intent, conversation);
if (mltQuery == null) {
return null;
}
final SolrQuery solrQuery = new SolrQuery();
solrQuery.addField("*").addField("score");
solrQuery.addFilterQuery(String.format("%s:%s", FIELD_TYPE, TYPE_MESSAGE));
solrQuery.addFilterQuery(String.format("%s:0",FIELD_MESSAGE_IDX));
solrQuery.addSort("score", SolrQuery.ORDER.desc).addSort(FIELD_VOTE, SolrQuery.ORDER.desc);
// #39 - paging
solrQuery.setStart((int) offset);
solrQuery.setRows(pageSize);
//since #46 the client field is used to filter for the current user
addClientFilter(solrQuery, conversation);
addPropertyFilters(solrQuery, conversation, conf);
return new ConversationMltRequest(solrQuery, mltQuery.getContent());
}
示例4: buildSolrRequest
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
@Override
protected QueryRequest buildSolrRequest(ComponentConfiguration conf, Template intent, Conversation conversation, long offset, int pageSize, MultiValueMap<String, String> queryParams) {
final ConversationSearchQuery searchQuery = buildQuery(conf, intent, conversation);
if (searchQuery == null) {
return null;
}
// TODO: build the real request.
final SolrQuery solrQuery = new SolrQuery(searchQuery.getKeyword().stream().reduce((s, s2) -> s + " OR " + s2).orElse("*:*"));
solrQuery.addField("*").addField("score");
solrQuery.set(CommonParams.DF, "text");
solrQuery.addFilterQuery(String.format("%s:%s",FIELD_TYPE, TYPE_MESSAGE));
solrQuery.addSort("score", SolrQuery.ORDER.desc).addSort("vote", SolrQuery.ORDER.desc);
// #39 - paging
solrQuery.setStart((int) offset);
solrQuery.setRows(pageSize);
//since #46 the client field is used to filter for the current user
addClientFilter(solrQuery, conversation);
addPropertyFilters(solrQuery, conversation, conf);
return new QueryRequest(solrQuery);
}
示例5: runQuery
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
/**
* Verwendung des Standard Query Parsers, der nur ein Index durchsucht (standardmäßig soll im Feld fulltext_stemmed
* gesucht werden)
*
* @param queryString Suchanfrage
*/
private void runQuery(String queryString) {
SolrQuery query = new SolrQuery();
query.setQuery(queryString);
// TODO Standardsuchfeld definieren mittels Query-Parameter df
query.set("fl", "*,score"); // Feldliste im Resultat (* bedeutet, dass alle Felder zurückgegeben werden, die als stored="true" markiert sind)
query.setRows(10);
QueryRequest req = new QueryRequest(query);
req.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
QueryResponse response = null;
try {
response = req.process(solrClient);
} catch (SolrServerException|IOException e) {
// do something reasonable
System.err.println(e);
}
printRanking(response);
}
示例6: printStats
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
/**
* Gibt für das übergebene Indexfeld die drei Indexterme aus, die die größte Document Frequency haben.
* Es werden hierbei aber nur Indexterme betrachtet, die mit einem Buchstaben beginnen.
*
* @param indexFieldName Feldname des Indexfelds
*/
private void printStats(String indexFieldName) {
System.out.println("- - - - - Field Statistics for Index Field " + indexFieldName + " - - - - -");
SolrQuery query = new SolrQuery();
query.setRequestHandler("/terms");
query.setTermsLimit(3);
query.setTermsSortString(TermsParams.TERMS_SORT_COUNT);
query.addTermsField(indexFieldName);
query.setTermsRegex("^[a-zA-Z].*");
QueryRequest request = new QueryRequest(query);
request.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
try {
List<TermsResponse.Term> terms = request.process(solrClient).getTermsResponse().getTerms(indexFieldName);
if (terms != null) {
for (TermsResponse.Term term : terms) {
System.out.println(term.getTerm() + " (df = " + term.getFrequency() + ")");
}
}
} catch (SolrServerException|IOException e) {
System.err.println("Fehler bei der Term-Lookup im Dictionary");
}
}
示例7: testSpellCheckResponse
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
@Test
public void testSpellCheckResponse() throws Exception {
getSolrServer();
server.deleteByQuery("*:*");
server.commit(true, true);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "111");
doc.setField(field, "Samsung");
server.add(doc);
server.commit(true, true);
SolrQuery query = new SolrQuery("*:*");
query.set(CommonParams.QT, "/spell");
query.set("spellcheck", true);
query.set(SpellingParams.SPELLCHECK_Q, "samsang");
QueryRequest request = new QueryRequest(query);
SpellCheckResponse response = request.process(server).getSpellCheckResponse();
Assert.assertEquals("samsung", response.getFirstSuggestion("samsang"));
}
示例8: getNumRequests
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
private Long getNumRequests(HttpSolrServer solrServer) throws
SolrServerException, IOException {
HttpSolrServer server = new HttpSolrServer(solrServer.getBaseURL());
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/admin/mbeans");
params.set("stats", "true");
params.set("key", "org.apache.solr.handler.StandardRequestHandler");
params.set("cat", "QUERYHANDLER");
// use generic request to avoid extra processing of queries
QueryRequest req = new QueryRequest(params);
NamedList<Object> resp = server.request(req);
NamedList mbeans = (NamedList) resp.get("solr-mbeans");
NamedList queryHandler = (NamedList) mbeans.get("QUERYHANDLER");
NamedList select = (NamedList) queryHandler.get("org.apache.solr.handler.StandardRequestHandler");
NamedList stats = (NamedList) select.get("stats");
return (Long) stats.get("requests");
}
示例9: invokeCollectionApi
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
protected NamedList<Object> invokeCollectionApi(String... args) throws SolrServerException, IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
SolrRequest request = new QueryRequest(params);
for (int i = 0; i < args.length - 1; i+=2) {
params.add(args[i], args[i+1]);
}
request.setPath("/admin/collections");
String baseUrl = ((HttpSolrServer) shardToJetty.get(SHARD1).get(0).client.solrClient)
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
HttpSolrServer baseServer = new HttpSolrServer(baseUrl);
baseServer.setConnectionTimeout(15000);
baseServer.setSoTimeout(60000 * 5);
NamedList r = baseServer.request(request);
baseServer.shutdown();
return r;
}
示例10: getLatestVersion
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
/**
* Gets the latest commit version and generation from the master
*/
@SuppressWarnings("unchecked")
NamedList getLatestVersion() throws IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(COMMAND, CMD_INDEX_VERSION);
params.set(CommonParams.WT, "javabin");
params.set(CommonParams.QT, "/replication");
QueryRequest req = new QueryRequest(params);
HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX modify to use shardhandler
NamedList rsp;
try {
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
rsp = server.request(req);
} catch (SolrServerException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e);
} finally {
server.shutdown();
}
return rsp;
}
示例11: getDetails
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
NamedList getDetails() throws IOException, SolrServerException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(COMMAND, CMD_DETAILS);
params.set("slave", false);
params.set(CommonParams.QT, "/replication");
HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX use shardhandler
NamedList rsp;
try {
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
QueryRequest request = new QueryRequest(params);
rsp = server.request(request);
} finally {
server.shutdown();
}
return rsp;
}
示例12: testQtUpdateFails
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
/** SOLR-3161
* Technically stream.body isn't remote streaming, but there wasn't a better place for this test method. */
@Test(expected = SolrException.class)
public void testQtUpdateFails() throws SolrServerException {
SolrQuery query = new SolrQuery();
query.setQuery( "*:*" );//for anything
query.add("echoHandler","true");
//sneaky sneaky
query.add("qt","/update");
query.add("stream.body","<delete><query>*:*</query></delete>");
QueryRequest queryRequest = new QueryRequest(query) {
@Override
public String getPath() { //don't let superclass substitute qt for the path
return "/select";
}
};
QueryResponse rsp = queryRequest.process(getSolrServer());
//!! should *fail* above for security purposes
String handler = (String) rsp.getHeader().get("handler");
System.out.println(handler);
}
示例13: assertVersions
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
private void assertVersions(SolrServer client1, SolrServer client2) throws Exception {
NamedList<Object> details = getDetails(client1);
ArrayList<NamedList<Object>> commits = (ArrayList<NamedList<Object>>) details.get("commits");
Long maxVersionClient1 = getVersion(client1);
Long maxVersionClient2 = getVersion(client2);
if (maxVersionClient1 > 0 && maxVersionClient2 > 0) {
assertEquals(maxVersionClient1, maxVersionClient2);
}
// check vs /replication?command=indexversion call
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/replication");
params.set("_trace", "assertVersions");
params.set("command", "indexversion");
QueryRequest req = new QueryRequest(params);
NamedList<Object> resp = client1.request(req);
Long version = (Long) resp.get("indexversion");
assertEquals(maxVersionClient1, version);
// check vs /replication?command=indexversion call
resp = client2.request(req);
version = (Long) resp.get("indexversion");
assertEquals(maxVersionClient2, version);
}
示例14: listCollection
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
private void listCollection() throws IOException, SolrServerException {
CloudSolrServer client = createCloudClient(null);
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.LIST.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
List<String> collections = (List<String>) rsp.get("collections");
assertTrue("control_collection was not found in list", collections.contains("control_collection"));
assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1));
} finally {
//remove collections
client.shutdown();
}
}
示例15: clusterStatusNoCollection
import org.apache.solr.client.solrj.request.QueryRequest; //导入依赖的package包/类
private void clusterStatusNoCollection() throws Exception {
CloudSolrServer client = createCloudClient(null);
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(COLLECTION_NAME1));
assertEquals(4, collections.size());
List<String> liveNodes = (List<String>) cluster.get("live_nodes");
assertNotNull("Live nodes should not be null", liveNodes);
assertFalse(liveNodes.isEmpty());
} finally {
//remove collections
client.shutdown();
}
}