本文整理汇总了Java中org.apache.solr.client.solrj.response.FacetField.Count类的典型用法代码示例。如果您正苦于以下问题:Java Count类的具体用法?Java Count怎么用?Java Count使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Count类属于org.apache.solr.client.solrj.response.FacetField包,在下文中一共展示了Count类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSets
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的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: matches
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
/**
*
* @param count count (name + count) to check
* @param converter optional converter to apply to value before comparison
* @return true IFF the {@link Count#getCount() } is more than {@link #getMinimalOccurence()
* } {@link Count#getName() } contains {@link #getName() } (case
* insensitive)
*/
@Override
public boolean matches(Count count, IConverter<String> converter) {
if (count.getCount() >= minimalOccurence) {
if (namePattern == null) {
// no pattern to compare to, always matches
return true;
} else {
// convert value if converter is provided
final String value;
if (converter == null) {
value = count.getName();
} else {
value = converter.convertToString(count.getName(), null);
}
return namePattern.matcher(value).find();
}
} else {
// too few occurences, no match
return false;
}
}
示例3: removeSelectedValsFromResponse
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的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: populateItem
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
@Override
protected void populateItem(Item<Count> item) {
//model for actual value
final PropertyModel<String> valueModel = new PropertyModel<>(item.getModel(), "name");
//checkbox
final Component selector = createValueCheckbox("selector", valueModel.getObject());
item.add(selector);
//label
item.add(new WebMarkupContainer("label")
//child label
.add(new FieldValueLabel("name", valueModel, fieldNameModel))
//count label
.add(new Label("count", new PropertyModel<String>(item.getModel(), "count")))
//reference to checkbox
.add(new AttributeModifier("for", selector.getMarkupId()))
.add(new AttributeAppender("class", valueModel, " "))
);
//description as tooltip (title)
final IModel<FieldValueDescriptor> descriptorModel = new MapValueModel<>(descriptorsModel, valueModel);
final IModel<String> descriptionModel = new PropertyModel<>(descriptorModel, "description");
item.add(new AttributeModifier("title", descriptionModel));
}
示例5: addFacetValue
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
/**
* Adds an individual facet value selection link to a dataview item
*
* @param item item to add link to
*/
private void addFacetValue(String id, final ListItem<Count> item) {
item.setDefaultModel(new CompoundPropertyModel<>(item.getModel()));
// link to select an individual facet value
final Link selectLink = new IndicatingAjaxFallbackLink(id) {
@Override
public void onClick(AjaxRequestTarget target) {
// reset filter
((NameAndCountFieldValuesFilter) filterModel.getObject()).setName(null);
// call callback
onValuesSelected(
// for now only single values can be selected
Collections.singleton(item.getModelObject().getName()),
target);
}
};
item.add(selectLink);
// 'name' field from Count (name of value)
selectLink.add(new FieldValueLabel("name", fieldNameModel));
// 'count' field from Count (document count for value)
selectLink.add(new Label("count"));
}
示例6: compare
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
@Override
public int compare(Count arg0, Count arg1) {
if (lowPriorityValues.contains(arg0.getName())) {
if (!lowPriorityValues.contains(arg1.getName())) {
//arg0 is low priority, arg1 is not -> move arg0 to back
return 1;
}
} else if (lowPriorityValues.contains(arg1.getName())) {
//arg0 is not low priority but arg1 is -> move arg1 to back
return -1;
}
// arg0 and arg1 are either both low priority or neither of them are,
// so fall back to secondary comparator (assuming a compound)
return 0;
}
示例7: testRestrictedSearch
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的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());
}
}
}
示例8: extractFacetGroups
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的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;
}
示例9: getFaceting
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
private static Faceting getFaceting( List<FacetField> facetFields) {
Faceting faceting = new Faceting();
faceting.setListFacets(new ArrayList<ListFacets>());
if (facetFields != null) {
for (int i = 0; i < facetFields.size(); i++) {
if (facetFields.get(i).getValueCount() > 1) {
ListFacets list = new ListFacets();
list.setFacets(new ArrayList<Facet>());
list.setHeader(facetFields.get(i).getName());
for (Count c : facetFields.get(i).getValues()) {
Facet f = new Facet();
f.setTitle(c.getName());
f.setCount(c.getCount());
list.getFacets().add(f);
}
faceting.getListFacets().add(list);
}
}
}
return faceting;
}
示例10: writeToFile
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
public void writeToFile(String fileName, String currentUser,
List<Count> userOccurences, Double weightDividor) {
//
// try {
// File file = new File(PATH + "/" + fileName + "_user_sim.csv");
// FileWriter fw = new FileWriter(file, true);
//
// for (Count userOccurence : userOccurences) {
// if ( ! userOccurence.getName().equals(currentUser)) {
// fw.write(currentUser + ";" + userOccurence.getName() + ";" + (userOccurence.getCount() / weightDividor ) + ";" + "\n");
// }
// }
//
// fw.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
}
示例11: getGeneIds
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
/**
* @since 2015/08/18
* @return
* @throws SolrServerException
*/
public List<String> getGeneIds ()
throws SolrServerException{
List<String> geneIds = new ArrayList<>();
SolrQuery q = new SolrQuery()
.setQuery("*:*")
.setRows(0)
.setFacet(true)
.addFacetField(ChannelDTO.GENE_ID)
.setFacetMinCount(1)
.setFacetLimit(-1);
QueryResponse res = solr.query(q);
if (res.getFacetField(ChannelDTO.GENE_ID).getValues() != null){
for (Count count : res.getFacetField(ChannelDTO.GENE_ID).getValues()){
geneIds.add(count.getName());
}
}
return geneIds;
}
示例12: getSpecies
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
/**
* @since 2015/08/13
* @return List of species and number of images for each of them
* @throws SolrServerException
*/
public List<SpeciesData> getSpecies()
throws SolrServerException{
List<SpeciesData> result = new ArrayList<>();
SolrQuery q = new SolrQuery()
.setQuery("*:*")
.setRows(0)
.setFacet(true)
.addFacetField(ImageDTO.TAXON)
.setFacetMinCount(1)
.setFacetLimit(-1);
QueryResponse res = solr.query(q);
for (Count count : res.getFacetField(ImageDTO.TAXON).getValues()){
SpeciesData species = new SpeciesData();
species.setName(count.getName());
species.setNumberOfImages(count.getCount());
result.add(species);
}
return result;
}
示例13: getRangeMap
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
private Map<String, Range> getRangeMap(ElaborateSearchParameters sp, QueryResponse response) {
Map<String, Range> map = Maps.newHashMap();
for (RangeField rangeField : sp.getRanges()) {
Set<Integer> values = Sets.newHashSet();
List<String> rangeFields = ImmutableList.of(rangeField.lowerField, rangeField.upperField);
for (String facetFieldName : rangeFields) {
FacetField facetField = response.getFacetField(facetFieldName);
for (Count count : facetField.getValues()) {
values.add(Integer.valueOf(count.getName()));
}
}
if (!values.isEmpty()) {
List<Integer> list = Lists.newArrayList(values);
Collections.sort(list);
Range r = new Range(list.get(0), list.get(list.size() - 1));
map.put(rangeField.name, r);
}
}
return map;
}
示例14: convertFacet
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的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;
}
示例15: extractFacets
import org.apache.solr.client.solrj.response.FacetField.Count; //导入依赖的package包/类
private Map<String, List<FacetEntry>> extractFacets(QueryResponse response, FacetStyle facetStyle) {
Map<String, List<FacetEntry>> facets = new HashMap<>();
for (String name : config.getFacetFields()) {
FacetField fld = response.getFacetField(name);
if (fld != null && !fld.getValues().isEmpty()) {
List<FacetEntry> facetValues = new ArrayList<>();
for (Count count : fld.getValues()) {
facetValues.add(new FacetEntry(count.getName(), count.getCount()));
}
facets.put(name, facetValues);
}
}
// And extract the facet tree, if there is one
if (facetStyle != FacetStyle.NONE) {
List<Object> facetTree = findFacetTree(response, EFO_URI_FIELD);
if (facetTree != null && !facetTree.isEmpty()) {
facets.put(EFO_URI_FIELD + "_hierarchy", extractFacetTreeFromNamedList(facetTree));
}
}
return facets;
}