本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.addFacetField方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.addFacetField方法的具體用法?Java SolrQuery.addFacetField怎麽用?Java SolrQuery.addFacetField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.addFacetField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Creates a list with all available values for the given field (minus any blacklisted values).
*
* @return
* @throws SolrServerException
* @should return all values
*/
public List<String> getSets(String field) throws SolrServerException {
List<String> ret = new ArrayList<>();
SolrQuery query = new SolrQuery();
query.setQuery(field + ":* " + DataManager.getInstance().getConfiguration().getCollectionBlacklistFilterSuffix());
query.setStart(0);
query.setRows(0);
query.addFacetField(field);
logger.trace("Set query: {}", query.getQuery());
QueryResponse resp = server.query(query);
FacetField facetField = resp.getFacetField(field);
if (facetField != null) {
for (Count count : facetField.getValues()) {
if (count.getCount() == 0) {
continue;
}
ret.add(count.getName());
}
}
Collections.sort(ret);
logger.trace("{} terms found for {}", ret.size(), field);
return ret;
}
示例2: obtainCollectionCounts
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private List<VloReport.CollectionCount> obtainCollectionCounts(SolrServer solrServer) throws SolrServerException {
final SolrQuery query = new SolrQuery();
query.setRows(0);
query.setFacet(true);
query.addFacetField(FacetConstants.FIELD_COLLECTION);
query.setFacetLimit(Integer.MAX_VALUE);
final QueryResponse result = solrServer.query(query);
final FacetField collectionField = result.getFacetField(FacetConstants.FIELD_COLLECTION);
logger.debug("Collection field: {}", collectionField.getValues());
final List<VloReport.CollectionCount> counts
= collectionField.getValues().stream().map((count) -> {
VloReport.CollectionCount collectionCount = new VloReport.CollectionCount();
collectionCount.setCollection(count.getName());
collectionCount.setCount(count.getCount());
return collectionCount;
}).collect(Collectors.toList());
return counts;
}
示例3: attachFacets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Notifies solr about which facets you want it to determine results and counts for
*
* @param query
* @param namedFacetMap
*/
protected void attachFacets(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap) {
query.setFacet(true);
for (Entry<String, SearchFacetDTO> entry : namedFacetMap.entrySet()) {
SearchFacetDTO dto = entry.getValue();
String facetTagField = entry.getValue().isActive() ? shs.getGlobalFacetTagField() : entry.getKey();
// Clone the list - we don't want to remove these facets from the DB
List<SearchFacetRange> facetRanges = new ArrayList<SearchFacetRange>(dto.getFacet().getSearchFacetRanges());
if (extensionManager != null) {
extensionManager.getProxy().filterSearchFacetRanges(dto, facetRanges);
}
if (facetRanges != null && facetRanges.size() > 0) {
for (SearchFacetRange range : facetRanges) {
query.addFacetQuery(getSolrTaggedFieldString(entry.getKey(), facetTagField, "ex", range));
}
} else {
query.addFacetField(getSolrTaggedFieldString(entry.getKey(), facetTagField, "ex", null));
}
}
}
示例4: attachFacets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void attachFacets(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap) {
query.setFacet(true);
for (Entry<String, SearchFacetDTO> entry : namedFacetMap.entrySet()) {
SearchFacetDTO dto = entry.getValue();
// Clone the list - we don't want to remove these facets from the DB
List<SearchFacetRange> facetRanges = new ArrayList<SearchFacetRange>(dto.getFacet().getSearchFacetRanges());
if (extensionManager != null) {
extensionManager.getProxy().filterSearchFacetRanges(dto, facetRanges);
}
if (facetRanges != null && facetRanges.size() > 0) {
for (SearchFacetRange range : facetRanges) {
query.addFacetQuery(getSolrTaggedFieldString(entry.getKey(), "key", range));
}
} else {
query.addFacetField(getSolrTaggedFieldString(entry.getKey(), "key", null));
}
}
}
示例5: testGetFacets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Test of getFacets method, of class SearchResultsDaoImpl.
*
* @throws java.lang.Exception
*/
@Test
public void testGetFacets() throws Exception {
final SolrQuery query = new SolrQuery();
query.setRows(10);
query.setStart(0);
query.setFields(FIELD_NAME, FIELD_ID, FIELD_DESCRIPTION);
query.setQuery(null);
query.setFacet(true);
query.setFacetMinCount(1);
query.addFacetField(FIELD_COLLECTION, FIELD_COUNTRY);
List<FacetField> facetFields = instance.getFacets(query);
assertNotNull(facetFields);
assertEquals(2, facetFields.size());
// 1 collection
assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf(
Matchers.<FacetField>hasProperty("name", equalTo(FIELD_COLLECTION)),
Matchers.<FacetField>hasProperty("valueCount", equalTo(1)))));
// 2 countries
assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf(
Matchers.<FacetField>hasProperty("name", equalTo(FIELD_COUNTRY)),
Matchers.<FacetField>hasProperty("valueCount", equalTo(2)))));
}
示例6: addFacetParameters
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void addFacetParameters(SolrQuery query) {
query.setFacet(true);
query.addFacetField(facetFieldExtractor.getRandomFacetField());
query.setFacetMinCount(facetMinCount);
query.setFacetLimit(facetLimit);
if(facetMethod != null && !"".equals(facetMethod)) {
query.add("facet.method", facetMethod);
}
}
示例7: appendFacetingOnFields
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void appendFacetingOnFields(SolrQuery solrQuery, FacetQuery query) {
FacetOptions facetOptions = query.getFacetOptions();
solrQuery.addFacetField(convertFieldListToStringArray(facetOptions.getFacetOnFields()));
if (facetOptions.hasFacetPrefix()) {
solrQuery.setFacetPrefix(facetOptions.getFacetPrefix());
}
for (FacetOptions.FieldWithFacetParameters parametrizedField : facetOptions.getFieldsWithParameters()) {
addPerFieldFacetParameters(solrQuery, parametrizedField);
if (parametrizedField.getSort() != null && FacetOptions.FacetSort.INDEX.equals(parametrizedField.getSort())) {
addFieldSpecificParameterToSolrQuery(solrQuery, parametrizedField, new FacetParameter(FacetParams.FACET_SORT,
FacetParams.FACET_SORT_INDEX));
}
}
}
示例8: modifySolrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected void modifySolrQuery(SolrQuery qry, RenderTask task) {
qry.setFacet(true);
qry.setRows(0);
qry.setFacetMinCount(1);
qry.addFacetField(this.facetField);
}
示例9: getIndexAndJdsPatientCounts
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Map<String, Integer> getIndexAndJdsPatientCounts() throws SolrServerException {
SolrQuery qry = new SolrQuery("*:*");
qry.setRows(0);
qry.addFacetField("pid");
qry.setFacetLimit(-1); // Default is 100;
try {
QueryResponse resp = solrServer.query(qry);
FacetField ff = resp.getFacetField("pid");
int solrPidCount = ff.getValues().size();
int jdsPidCount = patientDao.count();
Map<String, Integer> rslt = new HashMap<>();
rslt.put("solrPidCount",solrPidCount);
rslt.put("jdsPidCount",jdsPidCount);
return rslt;
} catch(SolrServerException e) {
// Short-term handling when embedded SolrServer is not initializing fast enough;
// Long-term plan is to have a dedicated SolrServer.
if(e.getMessage().toLowerCase().contains("server refused connection")) {
if(solrServerInitRetry++<5) {
try {
log.warn("SOLR server refused connection when trying to get PID count; Retry #"+solrServerInitRetry);
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return getIndexAndJdsPatientCounts();
}
}
}
return null;
}
示例10: testSOLRPatient
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void testSOLRPatient(SolrServer solr, Map<String, Object> src, FrameTask task) throws FrameExecException {
String pid = (String) src.get("pid");
SolrQuery q = new SolrQuery("*:*");
q.addFilterQuery("pid:"+pid);
q.addFacetField("domain");
q.setFacetMinCount(0);
q.setRows(0);
// System.out.println("\n\nSRC:" + src);
try {
QueryResponse resp = solr.query(q);
FacetField facet = resp.getFacetField("domain");
for (FacetField.Count count : facet.getValues()) {
// compensate for JDS/SOLR domain name miss-matches
String name = count.getName();
if (!src.containsKey(name) && domainMap.containsKey(name)) {
name = domainMap.get(name);
}
if (name == null) continue; // skip some items for now.
// get the counts for each system
int o1 = (src.get(name) == null) ? -1 : (Integer) src.get(name);
long o2 = count.getCount();
if (o1 != o2) {
// add an error message action if they do not match
String msg = String.format(MSG, pid, count.getName(), o1, o2);
task.addAction(new FrameAction.RefDataAction(Table.buildRow("error", msg, "class", null, "resolutions", null)));
}
// TODO: if a key in one count does not exist in the other, throw an error too
}
} catch (Exception ex) {
throw new FrameExecException(this, "Error running SOLR Query", ex);
}
}
示例11: getEventPropertyNames
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public Set<String> getEventPropertyNames(String... globalAgentIds) {
SolrQuery solrQuery = new SolrQuery(ALL_DOCS_QUERY);
solrQuery.setRows(0);
StringBuilder globalAgentIdFilterQuery = new StringBuilder();
globalAgentIdFilterQuery.append(FIELD_GLOBAL_AGENT_ID);
globalAgentIdFilterQuery.append(":(");
for (String eachGlobalAgentId : globalAgentIds) {
globalAgentIdFilterQuery.append(escapeSolr(eachGlobalAgentId));
globalAgentIdFilterQuery.append(" OR ");
}
globalAgentIdFilterQuery.setLength(globalAgentIdFilterQuery.length() - 4);
globalAgentIdFilterQuery.append(')');
solrQuery.addFilterQuery(globalAgentIdFilterQuery.toString());
solrQuery.setFacet(true);
solrQuery.setFacetMinCount(1);
solrQuery.addFacetField(FIELD_PROPERTY_ID);
try {
QueryResponse response = this.solrClient.query(solrQuery);
Set<String> result = new TreeSet<>();
for (Count eachCount : response.getFacetField(FIELD_PROPERTY_ID).getValues()) {
result.add(eachCount.getName());
}
return result;
} catch (SolrException | SolrServerException | IOException e) {
throw new DataRetrievalException("Failed to retrieve event property names", e);
}
}
示例12: 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);
}
}
示例13: loadAgentDescription
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private AgentDescription loadAgentDescription(String globalAgentId) throws SolrServerException, IOException {
SolrQuery query = new SolrQuery(ALL_DOCS_QUERY);
query.setRows(0);
query.setFilterQueries(FIELD_GLOBAL_AGENT_ID + ":\"" + globalAgentId + "\"");
query.setFacetMinCount(1);
query.addFacetField(FIELD_SPACE, FIELD_SYSTEM, FIELD_PROPERTY_ID);
QueryResponse response = this.solrClient.query(query);
AgentDescription result = new AgentDescription();
result.setGlobalId(globalAgentId);
result.setName(IdHelper.getAgentId(globalAgentId));
result.setSpace(this.getFirstFacetValue(response, FIELD_SPACE));
result.setSystem(this.getFirstFacetValue(response, FIELD_SYSTEM));
List<PropertyDescription> propertyDescriptions = new ArrayList<>();
FacetField facetField = response.getFacetField(FIELD_PROPERTY_ID);
for (Count eachValue : facetField.getValues()) {
propertyDescriptions.add(createPropertyDescription(eachValue.getName()));
}
Collections.sort(propertyDescriptions);
result.setPropertyDescriptions(propertyDescriptions);
return result;
}
示例14: getRemoteFacets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Get a list of remote facets keyed by field name.
*
* @param fields
* Fields.
* @return List of facets keyed by field name.
* @throws SophieException
* If facets could not be fetched.
*/
private Map<String, FacetField> getRemoteFacets(List<FieldInfo> fields) throws SophieException {
// Prepare query.
SolrQuery query = getBaseQuery(0, 0);
query.setFacet(true);
query.setFacetSort("index");
query.setFacetLimit(FACET_LIMIT);
query.setFacetMissing(true);
// For each field, determine whether Solr can generate a facet (fq works
// only on indexed fields). If yes, then list that field in the query.
for (FieldInfo field : fields) {
if (SolrUtils.getFlags(field).contains(FieldFlag.INDEXED)) {
query.addFacetField(field.getName());
}
}
// Send query.
Map<String, FacetField> facets = new HashMap<String, FacetField>();
try {
for (FacetField facet : Sophie.client.query(query).getFacetFields()) {
facets.put(facet.getName(), facet);
}
} catch (SolrServerException | IOException | SolrException e) {
throw new SophieException("Unable to fetch remote facets", e);
}
// Return facets keyed by field name.
return facets;
}
示例15: categoriesAvailable
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId,
String facetPrefix, boolean displayproducts, int viewIndex, int viewSize, List<String> queryFilters, Boolean excludeVariants, String core) {
// create the data model
Map<String, Object> result = new HashMap<>();
HttpSolrClient client = null;
QueryResponse returnMap = new QueryResponse();
try {
// do the basic query
client = SolrUtil.getHttpSolrClient(core);
// create Query Object
String query = "inStock[1 TO *]";
if (categoryId != null)
query += " +cat:"+ SolrExprUtil.escapeTermFull(categoryId);
else if (productId != null)
query += " +productId:" + SolrExprUtil.escapeTermFull(productId);
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(query);
if (catalogId != null)
solrQuery.addFilterQuery("+catalog:" + SolrExprUtil.escapeTermFull(catalogId));
if (excludeVariants == null) excludeVariants = SolrProductSearch.excludeVariantsDefault;
if (excludeVariants)
SolrProductUtil.addExcludeVariantsFilter(solrQuery);
if (displayproducts) {
if (viewSize > -1) {
solrQuery.setRows(viewSize);
} else
solrQuery.setRows(50000);
if (viewIndex > -1) {
// 2016-04-01: This must be calculated
//solrQuery.setStart(viewIndex);
if (viewSize > 0) {
solrQuery.setStart(viewSize * viewIndex);
}
}
} else {
solrQuery.setFields("cat");
solrQuery.setRows(0);
}
if(UtilValidate.isNotEmpty(facetPrefix)){
solrQuery.setFacetPrefix(facetPrefix);
}
solrQuery.setFacetMinCount(0);
solrQuery.setFacet(true);
solrQuery.addFacetField("cat");
solrQuery.setFacetLimit(-1);
if (Debug.verboseOn()) Debug.logVerbose("solr: solrQuery: " + solrQuery, module);
returnMap = client.query(solrQuery,METHOD.POST);
result.put("rows", returnMap);
result.put("numFound", returnMap.getResults().getNumFound());
} catch (Exception e) {
Debug.logError(e.getMessage(), module);
}
return result;
}