本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.addFilterQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.addFilterQuery方法的具體用法?Java SolrQuery.addFilterQuery怎麽用?Java SolrQuery.addFilterQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.addFilterQuery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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 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());
}
示例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: buildMergedSolrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Builds SOLR query.
*
* Automatically builds JOIN-Query if content search fields are used in query.
* @param sortBy sort criteria
* @param not true, if all conditions should be negated
* @param and AND or OR connective between conditions
* @param table conditions per "content" or "metadata"
* @param maxHits maximum hits
*/
@SuppressWarnings("rawtypes")
public static SolrQuery buildMergedSolrQuery(List<MCRSortBy> sortBy, boolean not, boolean and,
HashMap<String, List<MCRCondition>> table, int maxHits) {
List<MCRCondition> queryConditions = table.get("metadata");
MCRCondition combined = buildSubCondition(queryConditions, and, not);
SolrQuery solrRequestQuery = getSolrQuery(combined, sortBy, maxHits);
for (Map.Entry<String, List<MCRCondition>> mapEntry : table.entrySet()) {
if (!mapEntry.getKey().equals("metadata")) {
MCRCondition combinedFilterQuery = buildSubCondition(mapEntry.getValue(), and, not);
SolrQuery filterQuery = getSolrQuery(combinedFilterQuery, sortBy, maxHits);
solrRequestQuery.addFilterQuery(MCRSolrConstants.JOIN_PATTERN + filterQuery.getQuery());
}
}
return solrRequestQuery;
}
示例4: createDocumentQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public SolrQuery createDocumentQuery(String docId) {
// make a query to look up a specific document by its ID
final SolrQuery query = getDefaultDocumentQuery();
// we can use the 'fast' request handler here, document ranking is of no interest
query.setRequestHandler(FacetConstants.SOLR_REQUEST_HANDLER_FAST);
// consider all documents
query.setQuery(SOLR_SEARCH_ALL);
// filter by ID
// check for ID value in both 'id' and 'self link' fields, both ought to
// be unique and self link use to be ID in old VLO, so this should keep old
// URL's valid with a minimal likelihood of clashes
final ImmutableMap<String, String> idOrQueryMap = ImmutableMap.<String, String>builder()
.put(FacetConstants.FIELD_ID, docId)
.put(FacetConstants.FIELD_SELF_LINK, docId)
.build();
query.addFilterQuery(createFilterOrQuery(idOrQueryMap));
// one result max
query.setRows(1);
return query;
}
示例5: stream
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void stream(EventFilter eventFilter, int count, int offset, EventStreamer eventStreamer) {
SolrQuery solrQuery = new SolrQuery(ALL_DOCS_QUERY);
solrQuery.setStart(offset);
solrQuery.setRows(count);
solrQuery.set(SORT, SORT_CRON_ASC);
for (EventFilterElement eachElement : eventFilter) {
solrQuery.addFilterQuery(this.createFilterQuery(eachElement));
}
try {
this.solrClient.queryAndStreamResponse(solrQuery, new EventStreamCallback(eventStreamer));
} catch (SolrServerException | IOException e) {
String message = "Failed to stream events.";
this.logger.error(message, e);
throw EventStoreException.retrieveFailed(message, e);
}
}
示例6: getBaseQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Get select query and populate the start/rows/fq parameters.
*
* @param start
* Offset at which Solr should being returning documents.
* @param rows
* How many rows Solr should return.
* @return Solr query.
*/
private SolrQuery getBaseQuery(int start, int rows) {
SolrQuery query = new SolrQuery("*:*");
query.setStart(start);
query.setRows(rows);
// Add filters.
for (Entry<String, String> filter : filters.entrySet()) {
if (StringUtils.equals(filter.getValue(), LABEL_EMPTY)) {
// Empty value needs a special syntax.
query.addFilterQuery("-" + filter.getKey() + ":[* TO *]");
} else {
// Colons in value need to be escaped to avoid a syntax error.
query.addFilterQuery(filter.getKey() + ":" + filter.getValue().replace(":", "\\:"));
}
}
return query;
}
示例7: addFilterQueries
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static void addFilterQueries(SolrQuery solrQuery, Collection<String> queryFilters) {
if (queryFilters != null) {
for(String filter : queryFilters) {
solrQuery.addFilterQuery(filter);
}
}
}
示例8: retrieve
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private EventPage retrieve(EventFilter eventFilter, int count, String cursorMark, String sort) {
SolrQuery solrQuery = new SolrQuery(ALL_DOCS_QUERY);
solrQuery.setRows(count);
solrQuery.set(CURSOR_MARK_PARAM, cursorMark);
solrQuery.set(SORT, sort);
for (EventFilterElement eachElement : eventFilter) {
solrQuery.addFilterQuery(this.createFilterQuery(eachElement));
}
try {
EventPage result = new EventPage();
QueryResponse response = this.solrClient.query(solrQuery);
for (SolrDocument eachSolrDocument : response.getResults()) {
result.addEvent(this.createEvent(eachSolrDocument));
}
result.setNextCursorMark(response.getNextCursorMark());
result.setTotalCount(response.getResults().getNumFound());
return result;
} catch (SolrServerException | IOException | SolrException e) {
String message = "Failed to retrieve events.";
this.logger.error(message, e);
throw EventStoreException.retrieveFailed(message, e);
}
}
示例9: 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;
}
示例10: addPropertyFilter
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Adds a filter based on a {@link ConversationMeta#getProperty(String)}
* @param solrQuery the Solr query to add the FilterQuery
* @param fieldName the name of the field
* @param fieldValues the field values
*/
protected void addPropertyFilter(SolrQuery solrQuery, String fieldName, List<String> fieldValues) {
if (fieldValues == null || fieldValues.isEmpty()) {
solrQuery.addFilterQuery("-" + getMetaField(fieldName) + ":*");
} else {
final String filterVal = fieldValues.stream()
.map(ClientUtils::escapeQueryChars)
.reduce((a, b) -> a + " OR " + b)
.orElse("");
solrQuery.addFilterQuery(
getMetaField(fieldName) + ":(" + filterVal + ")");
}
}
示例11: convertRuleToSearch
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@VisibleForTesting
public SolrQuery convertRuleToSearch(CdxRule rule, String notLastIndexed) {
// URL complexity first
List<String> urlQueries = new ArrayList<>();
for (String url : rule.getUrlPatterns()) {
if (!url.trim().isEmpty()) {
urlQueries.add(urlSearch(url));
}
}
if (urlQueries.isEmpty()) {
urlQueries.add("*:*");
}
SolrQuery query = createQuery("(" + StringUtils.join(urlQueries, ") OR (") + ")");
// Filter out stuff we have touched already this run
query.addFilterQuery(notLastIndexed);
// Filter for Embargo
if (rule.getPeriod() != null && !rule.getPeriod().isZero()) {
// TODAY +/- embargo period
ZonedDateTime today = ZonedDateTime.ofInstant(CdxRestrictionService.TODAY.toInstant(), TZ);
Date embargoStart = Date.from(today.minus(rule.getPeriod()).toInstant());
query.addFilterQuery(SolrEnum.DATE + ":[" + format.format(embargoStart) + " TO *]");
}
// Filter for Capture date
if (rule.getCaptured() != null && rule.getCaptured().hasData()) {
query.addFilterQuery(SolrEnum.DATE + ":[" + format.format(rule.getCaptured().start)
+ " TO " + format.format(rule.getCaptured().end) + "]");
}
// Worth noting we don't filter for access date because it is one of the
// deciding data points in whether or not to run this query at all.
return query;
}
示例12: attachActiveFacetFilters
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Restricts the query by adding active facet filters.
*
* @param query
* @param namedFacetMap
* @param searchCriteria
*/
protected void attachActiveFacetFilters(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap,
ProductSearchCriteria searchCriteria) {
for (Entry<String, String[]> entry : searchCriteria.getFilterCriteria().entrySet()) {
String solrKey = null;
for (Entry<String, SearchFacetDTO> dtoEntry : namedFacetMap.entrySet()) {
if (dtoEntry.getValue().getFacet().getField().getAbbreviation().equals(entry.getKey())) {
solrKey = dtoEntry.getKey();
dtoEntry.getValue().setActive(true);
}
}
if (solrKey != null) {
String solrTag = getSolrFieldTag(shs.getGlobalFacetTagField(), "tag");
String[] selectedValues = entry.getValue().clone();
for (int i = 0; i < selectedValues.length; i++) {
if (selectedValues[i].contains("range[")) {
String rangeValue = selectedValues[i].substring(selectedValues[i].indexOf('[') + 1,
selectedValues[i].indexOf(']'));
String[] rangeValues = StringUtils.split(rangeValue, ':');
if (rangeValues[1].equals("null")) {
rangeValues[1] = "*";
}
selectedValues[i] = solrKey + ":[" + rangeValues[0] + " TO " + rangeValues[1] + "]";
} else {
selectedValues[i] = solrKey + ":\"" + selectedValues[i] + "\"";
}
}
String valueString = StringUtils.join(selectedValues, " OR ");
StringBuilder sb = new StringBuilder();
sb.append(solrTag).append("(").append(valueString).append(")");
query.addFilterQuery(sb.toString());
}
}
}
示例13: getSuggestion
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Suggestion getSuggestion(SuggestionInput input) {
TimeTracker timeTracker = new TimeTracker();
SolrQuery solrQuery = new SolrQuery(ALL_DOCS_QUERY);
solrQuery.setRows(0);
if (!StringUtils.isBlank(input.getText())) {
solrQuery.addFilterQuery(FIELD_TOKENIZED_SEARCH_FIELD + ":" + escapeSolr(input.getText()) + "*");
}
addFilterQuery(solrQuery, FIELD_PROPERTY_ID, input.getPropertyId());
addFilterQuery(solrQuery, FIELD_SPACE, input.getSpaceId());
addFilterQuery(solrQuery, FIELD_SYSTEM, input.getSystemId());
solrQuery.setFacetMinCount(1);
solrQuery.addFacetField(FIELD_GLOBAL_AGENT_ID);
try {
Suggestion result = new Suggestion();
QueryResponse response = this.solrClient.query(solrQuery);
FacetField globalAgentIdFacetField = response.getFacetField(FIELD_GLOBAL_AGENT_ID);
for (Count eachValue : globalAgentIdFacetField.getValues()) {
String globalAgentId = eachValue.getName();
result.addAgentDescription(this.getAgentDescription(globalAgentId));
}
result.setExecutionTime(timeTracker.getElapsed(MILLISECONDS));
return result;
} catch (SolrException | SolrServerException | IOException e) {
throw new DataRetrievalException("Failed to create suggestions", e);
}
}
示例14: getReports
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Reports getReports(int start, int count, String sort) {
this.logger.debug("Retrieving {} reports from {}, sorted by '{}'.", count, start, sort);
SolrQuery solrQuery = new SolrQuery("*:*");
solrQuery.addFilterQuery(FILTER_REPORT);
solrQuery.addFilterQuery(FILTER_UNDELETED);
solrQuery.addFilterQuery(FILTER_TIP_OF_BRANCH);
SolrQueryHelper.addSort(solrQuery, sort, this.getFieldDefinitions());
SolrQueryHelper.setRange(solrQuery, start, count);
try {
List<Report> reports = new ArrayList<>();
QueryResponse queryResponse = this.solrClient.query(solrQuery);
SolrDocumentList results = queryResponse.getResults();
for (SolrDocument eachSolrDocument : results) {
reports.add(createReport(eachSolrDocument));
}
return Reports.create(reports, start, Math.toIntExact(results.getNumFound()));
} catch (SolrServerException | IOException e) {
throw new DataRetrievalException("Could not retrieve reports.", e);
}
}
示例15: attachActiveFacetFilters
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void attachActiveFacetFilters(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap,
SearchCriteria searchCriteria) {
if (searchCriteria.getFilterCriteria() != null) {
for (Entry<String, String[]> entry : searchCriteria.getFilterCriteria().entrySet()) {
String solrKey = null;
for (Entry<String, SearchFacetDTO> dtoEntry : namedFacetMap.entrySet()) {
if (dtoEntry.getValue().getFacet().getField().getAbbreviation().equals(entry.getKey())) {
solrKey = dtoEntry.getKey();
dtoEntry.getValue().setActive(true);
}
}
if (solrKey != null) {
String[] selectedValues = entry.getValue().clone();
for (int i = 0; i < selectedValues.length; i++) {
if (selectedValues[i].contains("range[")) {
String rangeValue = selectedValues[i].substring(selectedValues[i].indexOf('[') + 1,
selectedValues[i].indexOf(']'));
String[] rangeValues = StringUtils.split(rangeValue, ':');
BigDecimal minValue = new BigDecimal(rangeValues[0]);
BigDecimal maxValue = null;
if (!rangeValues[1].equals("null")) {
maxValue = new BigDecimal(rangeValues[1]);
}
selectedValues[i] = getSolrRangeString(solrKey, minValue, maxValue);
} else {
selectedValues[i] = solrKey + ":\"" + scrubFacetValue(selectedValues[i]) + "\"";
}
}
String valueString = StringUtils.join(selectedValues, " OR ");
query.addFilterQuery(valueString);
}
}
}
}