本文整理汇总了Java中org.apache.solr.client.solrj.response.FacetField.getValues方法的典型用法代码示例。如果您正苦于以下问题:Java FacetField.getValues方法的具体用法?Java FacetField.getValues怎么用?Java FacetField.getValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.response.FacetField
的用法示例。
在下文中一共展示了FacetField.getValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSets
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的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: processFacetResults
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
/**
* Add any faceting results to the result builder.
*
* @param resultsBuilder query result builder
* @param facetFields faceting results
*/
protected void processFacetResults(QueryResults.Builder<QR> resultsBuilder, List<FacetField> facetFields) {
if (facetFields != null) {
for (FacetField facetField : facetFields) {
String fieldName = facetField.getName();
List<FacetCount> facetCounts = new ArrayList<>();
for (FacetField.Count count : facetField.getValues()) {
facetCounts.add(new FacetCount(count.getName(), count.getCount()));
}
FacetResult facetResult = new FacetResult(fieldName, facetCounts);
resultsBuilder.addFacetResult(facetResult);
}
}
}
示例3: removeSelectedValsFromResponse
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
private List<FacetField> removeSelectedValsFromResponse(QueryFacetsSelection query, List<FacetField> response){
List<FacetField> cleanedFacets = new ArrayList<>();
//for each facet from response
for(FacetField facet: response){
FacetSelection facetSelection = query.getSelectionValues(facet.getName());
if(facetSelection == null){
cleanedFacets.add(facet);
continue;
}else{
Collection<String> selectedValues = facetSelection.getValues();
FacetField _newFacetField = new FacetField(facet.getName(), facet.getName(), facet.getEnd());
//for each value from facet check if is selected and if not add it to the new response
for(Count val: facet.getValues()){
if(!selectedValues.contains(val.getName()))
_newFacetField.add(val.getName(), val.getCount());
}
cleanedFacets.add(_newFacetField);
}
}
return cleanedFacets;
}
示例4: removeSelected
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
private FacetField removeSelected(FacetField facetField, FacetSelection selection) {
FacetField filtered = new FacetField(facetField.getName());
if (selection != null
&& selection.getSelectionType() == FacetSelectionType.AND) {
//we want to exclude the selected option(s) in case of an AND selection
for (FacetField.Count value : facetField.getValues()) {
final String valueName = value.getName();
if (selection.getValues().contains(valueName)
//exclude negative value selectors
//(not such a great solution, added to make availability facet checkboxes work)
&& selection.getQualifier(valueName) != FacetSelectionValueQualifier.NOT
) {
continue;
} else {
filtered.add(valueName, value.getCount());
}
}
return filtered;
} else {
return facetField;
}
}
示例5: testRestrictedSearch
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
/**
*
*/
@Test
public final void testRestrictedSearch() throws Exception {
Map<String, String> selectedFacets = new HashMap<String, String>();
selectedFacets.put("taxon.distribution_TDWG_0_ss", "AUSTRALASIA");
Page<SearchableObject> results = getSearchableObjectDao().search("taxon.scientific_name_t:Aus", null, null, null,
new String[] {"taxon.distribution_TDWG_0_ss" , "taxon.distribution_TDWG_1_ss"}, null, selectedFacets, null, null);
assertEquals("There should be 2 taxa matching Aus found in AUSTRALASIA", new Integer(2), (Integer)results.getSize());
for(String facetName : results.getFacetNames()) {
logger.debug(facetName);
FacetField facet = results.getFacetField(facetName);
for(Count count : facet.getValues()) {
logger.debug("\t" + count.getName() + " " + count.getCount());
}
}
}
示例6: convertFacet
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
/**
* Returns a list of facetinfo with counts.
* @param field
* @param title
* @param type
*/
protected FacetCount convertFacet(FacetField field, String title, FacetType type) {
if (field != null) {
FacetCount facetCount = new FacetCount()//
.setName(field.getName())//
.setTitle(title)//
.setType(type);
List<Count> counts = field.getValues();
if (counts != null) {
for (Count count : counts) {
FacetCount.Option option = new FacetCount.Option()//
.setName(count.getName())//
.setCount(count.getCount());
facetCount.addOption(option);
}
}
return facetCount;
}
return null;
}
示例7: extractFacetGroups
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
/** Extract facet values from solrResponse into something sendable
*
* @param facetFields
* @return
*/
private List<FacetGroup> extractFacetGroups(List<FacetField> facetFields) {
List<FacetGroup> facets = new ArrayList<FacetGroup>();
for (FacetField facetField : facetFields) {
FacetGroup group = new FacetGroup();
group.setName(facetField.getName());
group.setCount(facetField.getValueCount());
for (Count element : facetField.getValues()) {
Facet f = new Facet();
f.setName(element.getName());
f.setCount(element.getCount());
if (group.getFacets() == null) {
List<Facet> facet = new ArrayList<Facet>();
facet.add(f);
group.setFacets(facet);
} else {
group.getFacets().add(f);
}
}
facets.add(group);
}
return facets;
}
示例8: getPickableValues
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
public List<String> getPickableValues(Field field, String solrServer) throws ReportingException {
if (!fields.contains(field)) {
throw new IllegalArgumentException("This report doesn't contain the specified field " + field);
}
if (field.getValuesMode() != Field.ValuesMode.PICK) {
throw new IllegalArgumentException("This field isn't pickable " + field);
}
List<String> result = new ArrayList<>();
HttpSolrServer solr = new HttpSolrServer(solrServer);
SolrQuery query = toPickableValuesQuery(field.getName());
try {
QueryResponse response = solr.query(query);
FacetField facetField = response.getFacetField(field.getName());
List<FacetField.Count> values = facetField.getValues();
for (FacetField.Count value : values) {
result.add(value.getName());
}
Collections.sort(result);
} catch (SolrServerException e) {
throw new ReportingException("Could not determine pickable values", e);
}
return result;
}
示例9: setFacets
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
/**
* Helper method that takes Solr response and extracts the facets results.
* The facets are converted to a list of Facets understood by the search API.
* The result of this method can be a empty list.
*
* @param queryResponse that contains the facets information returned by Solr
* @return the List of facets retrieved from the Solr response
*/
private void setFacets(SearchResponse<NameUsageSearchResult, NameUsageSearchParameter> response, final QueryResponse queryResponse) {
List<Facet<NameUsageSearchParameter>> facets = Lists.newArrayList();
if (queryResponse.getFacetFields() != null) {
List<FacetField> facetFields = queryResponse.getFacetFields();
for (final FacetField facetField : facetFields) {
NameUsageSearchParameter facetParam = SolrMapping.FACET_MAPPING.inverse().get(facetField.getName());
Facet<NameUsageSearchParameter> facet = new Facet<NameUsageSearchParameter>(facetParam);
List<Facet.Count> counts = Lists.newArrayList();
if (facetField.getValues() != null) {
for (final FacetField.Count count : facetField.getValues()) {
String value = SolrMapping.interpretSolrValue(facetParam, count.getName());
counts.add(new Facet.Count(value, count.getCount()));
}
}
facet.setCounts(counts);
facets.add(facet);
}
}
response.setFacets(facets);
}
示例10: extractAvailableFilters
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
private Map<String, FacetList> extractAvailableFilters(QueryResponse response) {
Map<String, FacetList> facets = new HashMap<String, FacetList>();
if (response.getFacetFields() != null) {
for (FacetField ff : response.getFacetFields()) {
String field = ff.getName();
List<Facet> facetList = new ArrayList<Facet>(ff.getValueCount());
for (Count c : ff.getValues()) {
if (c.getCount() > 0) {
Facet f = new Facet(ff.getName(), c.getName(), c.getCount());
facetList.add(f);
}
}
facets.put(ff.getName(), new FacetList(field, getFacetLabel(field), facetList));
}
}
return facets;
}
示例11: setFacets
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
private void setFacets(List<FacetField> facetFields) {
if(facetFields == null) {
return;
}
DefaultListModel model = new DefaultListModel();
int i = 0;
for(FacetField facet:facetFields) {
for(Count count:facet.getValues()) {
model.add(i++, facet.getName() + ":" + count.getName() + "(" + count.getCount() + ")");
}
}
jListFacets.setModel(model);
}
示例12: testSOLRPatient
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的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);
}
}
示例13: getSuggestion
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的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: getFirstFacetValue
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的package包/类
private String getFirstFacetValue(QueryResponse response, String fieldName) {
FacetField facetField = response.getFacetField(fieldName);
if (facetField == null) {
return null;
}
List<Count> values = facetField.getValues();
if (values == null || values.isEmpty()) {
return null;
}
return values.get(0).getName();
}
示例15: loadAgentDescription
import org.apache.solr.client.solrj.response.FacetField; //导入方法依赖的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;
}