本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.set方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.set方法的具體用法?Java SolrQuery.set怎麽用?Java SolrQuery.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRuntimeLib
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
SearchServer server = testSearchServer.getSearchServer();
SolrClient client = (SolrClient) server.getBackend();
SolrInputDocument document = new SolrInputDocument();
document.setField("_id_", "1");
document.setField("_type_", "doc");
document.setField("dynamic_multi_facet_string_f1", "test");
document.setField("dynamic_multi_facet_string_f2", "hello");
client.add(document);
client.commit();
SolrQuery query = new SolrQuery("t");
query.setRequestHandler("/suggester");
query.set("suggestion.df", "facets");
query.set("suggestion.field", "dynamic_multi_facet_string_f1");
QueryResponse response = client.query(query);
assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
示例2: buildSolrRequest
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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);
}
示例3: getHeader
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Optional<Header> getHeader(String mcrId) {
SolrQuery query = getBaseQuery(CommonParams.FQ);
query.set(CommonParams.Q, "id:" + MCRSolrUtils.escapeSearchValue(mcrId));
query.setRows(1);
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
try {
QueryResponse response = solrClient.query(query);
SolrDocumentList results = response.getResults();
if (!results.isEmpty()) {
return Optional.of(toHeader(results.get(0), getSetResolver(results)));
}
} catch (Exception exc) {
LOGGER.error("Unable to handle solr request", exc);
}
return Optional.empty();
}
示例4: solrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
SolrQuery query = getBaseQuery(CommonParams.Q);
// set support
if (this.set != null) {
String setId = this.set.getSetId();
MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
setConfig.getHandler().apply(this.set, query);
}
// from & until
if (this.from != null || this.until != null) {
String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
query.add(CommonParams.FQ, fromUntilCondition);
}
// cursor
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
query.set(CommonParams.SORT, "id asc");
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
QueryResponse response = solrClient.query(query);
Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}
示例5: getIdentifierOfFirst
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* @param q the query to execute (in solr syntax)
* @return the identifier of the first document matching the query
* @throws SolrServerException
* @throws IOException
*/
public static String getIdentifierOfFirst(String q) throws SolrServerException, IOException {
if (q == null || q.length() == 0) {
throw new IllegalArgumentException("The query string must not be null");
}
SolrQuery solrQuery = new SolrQuery(q);
solrQuery.set("rows", 1);
QueryResponse queryResponse;
queryResponse = MCRSolrClientFactory.getSolrClient().query(solrQuery);
if (queryResponse.getResults().getNumFound() == 0) {
return null;
}
return queryResponse.getResults().get(0).get("id").toString();
}
示例6: runQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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);
}
示例7: suggest
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected void suggest(PatientSearch search, FrameTask task) throws FrameException {
SolrQuery query = new SolrQuery("stop_code_name: \"" + ClientUtils.escapeQueryChars(search.getOriginalQueryStr()) + "\"");
query.addFilterQuery("domain:encounter");
query.set(GroupParams.GROUP, true);
query.set(GroupParams.GROUP_FIELD, "stop_code_name");
QueryResponse resp = execSolrQuery(query, task);
GroupResponse group = resp.getGroupResponse();
if (group != null && group.getValues().get(0) != null) {
GroupCommand cmd = group.getValues().get(0);
for (Group grp : cmd.getValues()) {
String val = grp.getGroupValue();
SuggestItem item = new SuggestItem(val, val, "Stop Code");
item.setCategory("Encounters/Visits");
task.addAction(item);
}
}
}
示例8: configureQueryForDocuments
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void configureQueryForDocuments(SolrQuery query) {
query.addFilterQuery("domain:document");
query.addSort("reference_date_time", ORDER.desc);
query.addField(Document.SOLR_LOCAL_TITLE_FIELD);
query.addField(Document.SOLR_DOC_DEF_UID_FIELD);
query.addField(Document.SOLR_DOCUMENT_STATUS_FIELD);
query.addField(Document.SOLR_AUTHOR_UID_FIELD);
query.addField(Document.SOLR_SIGNER_UID_FIELD);
query.addField(Document.SOLR_COSIGNER_UID_FIELD);
query.addField((Document.SOLR_ATTENDING_UID_FIELD));
query.addField(Document.SOLR_IS_INTERDISCIPLINARY_FIELD);
query.addField(Document.SOLR_INTERDISCIPLINARY_TYPE_FIELD);
query.addField(SearchService.PHRASE);
query.set(GroupParams.GROUP, true);
query.set(GroupParams.GROUP_FIELD, Document.SOLR_LOCAL_TITLE_FIELD);
query.setHighlight(true);
query.addHighlightField("body").addHighlightField("subject");
query.setHighlightFragsize(45);
query.setHighlightSnippets(5);
}
示例9: restoreSolr5Index
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Performs Solr restoration.
*
* @param properties properties containing arguments to execute the restoration.
*/
private static void restoreSolr5Index (Properties properties) throws
IOException, SolrServerException
{
String solrHome = properties.getProperty ("dhus.solr.home");
String coreName = properties.getProperty ("dhus.solr.core.name");
final String name = properties.getProperty ("dhus.solr.backup.name");
final String location = properties.getProperty (
"dhus.solr.backup.location");
if (solrHome == null || coreName == null || name == null ||
location == null)
{
throw new UnsupportedOperationException ();
}
System.setProperty ("solr.solr.home", solrHome);
CoreContainer core = new CoreContainer (solrHome);
EmbeddedSolrServer server = new EmbeddedSolrServer (core, coreName);
try
{
server.getCoreContainer ().load ();
SolrQuery query = new SolrQuery();
query.setRequestHandler("/replication");
query.set("command", "restore");
query.set("name", name);
query.set("location", location);
server.query(query);
LOGGER.info("SolR indexes restored.");
}
finally
{
server.close();
}
}
示例10: initMlt
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public SolrQuery initMlt(SolrQuery query, String lang){
query.set(MoreLikeThisParams.MLT,true);
query.set(MoreLikeThisParams.BOOST, boost);
query.set(MoreLikeThisParams.INTERESTING_TERMS, interstingTerms ?
MoreLikeThisParams.TermStyle.DETAILS.name() :
MoreLikeThisParams.TermStyle.NONE.name());
query.set(MoreLikeThisParams.MIN_DOC_FREQ,minDocFreq);
query.set(MoreLikeThisParams.MIN_TERM_FREQ, minTermFreq);
query.set(MoreLikeThisParams.MIN_WORD_LEN, minWordLength);
query.set(MoreLikeThisParams.MAX_QUERY_TERMS, maxTerms);
if(filterQuery != null){
query.addFilterQuery(filterQuery);
}
return query;
}
示例11: getBaseQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getBaseQuery(String restrictionField) {
String configPrefix = this.identify.getConfigPrefix();
SolrQuery query = new SolrQuery();
// query
String restriction = getConfig().getString(configPrefix + "Search.Restriction", null);
if (restriction != null) {
query.set(restrictionField, restriction);
}
String[] requiredFields = Stream.concat(Stream.of("id", getModifiedField()), getRequiredFieldNames().stream())
.toArray(String[]::new);
query.setFields(requiredFields);
// request handler
query.setRequestHandler(getConfig().getString(configPrefix + "Search.RequestHandler", "/select"));
return query;
}
示例12: getNumFound
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Convenience method for retrieving the result count for a given solr query.
*
* @param q the query to execute (in solr syntax)
*
* @return the amount of documents matching the given query
*/
public static long getNumFound(String q) throws SolrServerException, IOException {
if (q == null || q.length() == 0) {
throw new IllegalArgumentException("The query string must not be null");
}
SolrQuery solrQuery = new SolrQuery(q);
solrQuery.set("rows", 0);
QueryResponse queryResponse;
queryResponse = MCRSolrClientFactory.getSolrClient().query(solrQuery);
return queryResponse.getResults().getNumFound();
}
示例13: runQueryOnMultipleFields
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Verwendung des DisMax Query Parsers, um eine feldübergreifende Suche zu ermöglichen
*
* Unterschiedliche Gewichtung der Suchfelder gemäß Aufgabenstellung
*
* Boosting auf Basis der Anzahl der Downloads in den letzten 30 Tagen (Log-gewichtet)
*
* @param queryString Suchanfrage
*/
private void runQueryOnMultipleFields(String queryString) {
SolrQuery query = new SolrQuery();
query.setQuery(queryString);
// TODO DisMax Query Parser verwenden und geeignete Parameter setzen
query.set("defType", "TODO");
query.set("qf", "TODO");
query.set("bf", "TODO");
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);
}
示例14: getQueryParams
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getQueryParams(BoundedSolrSource source) {
String query = source.spec.getQuery();
if (query == null) {
query = "*:*";
}
SolrQuery solrQuery = new SolrQuery(query);
solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
solrQuery.setRows(source.spec.getBatchSize());
solrQuery.addSort(uniqueKey, SolrQuery.ORDER.asc);
if (source.replica != null) {
solrQuery.setDistrib(false);
}
return solrQuery;
}
示例15: search
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Default query to fetch the top 10 documents that match the query request.
*
* @param queryString
* @return
*/
public QueryResponse search(String queryString, int rows, int start) {
SolrQuery query = new SolrQuery();
query.set("q", queryString);
query.setRows(rows);
query.setStart(start);
QueryResponse resp = null;
try {
resp = solrServer.query(query);
} catch (SolrServerException e) {
log.warn("Search failed with exception", e);
}
return resp;
}