本文整理汇总了Java中org.apache.solr.client.solrj.response.QueryResponse.getFacetField方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResponse.getFacetField方法的具体用法?Java QueryResponse.getFacetField怎么用?Java QueryResponse.getFacetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.response.QueryResponse
的用法示例。
在下文中一共展示了QueryResponse.getFacetField方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSets
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的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.response.QueryResponse; //导入方法依赖的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: getIndexAndJdsPatientCounts
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的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;
}
示例4: testSOLRPatient
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的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);
}
}
示例5: getSuggestion
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的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);
}
}
示例6: getFirstFacetValue
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的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();
}
示例7: loadAgentDescription
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的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;
}
示例8: testFaceting
import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
@Test
public void testFaceting() throws Exception
{
SolrServer server = getSolrServer();
// Empty the database...
server.deleteByQuery( "*:*" );// delete everything!
server.commit();
assertNumFound( "*:*", 0 ); // make sure it got in
ArrayList<SolrInputDocument> docs = new ArrayList<>(10);
for( int i=1; i<=10; i++ ) {
SolrInputDocument doc = new SolrInputDocument();
doc.setField( "id", i+"", 1.0f );
if( (i%2)==0 ) {
doc.addField( "features", "two" );
}
if( (i%3)==0 ) {
doc.addField( "features", "three" );
}
if( (i%4)==0 ) {
doc.addField( "features", "four" );
}
if( (i%5)==0 ) {
doc.addField( "features", "five" );
}
docs.add( doc );
}
server.add( docs );
server.commit();
SolrQuery query = new SolrQuery( "*:*" );
query.remove( FacetParams.FACET_FIELD );
query.addFacetField( "features" );
query.setFacetMinCount( 0 );
query.setFacet( true );
query.setRows( 0 );
QueryResponse rsp = server.query( query );
assertEquals( docs.size(), rsp.getResults().getNumFound() );
List<FacetField> facets = rsp.getFacetFields();
assertEquals( 1, facets.size() );
FacetField ff = facets.get( 0 );
assertEquals( "features", ff.getName() );
// System.out.println( "111: "+ff.getValues() );
// check all counts
assertEquals( "[two (5), three (3), five (2), four (2)]", ff.getValues().toString() );
// should be the same facets with minCount=0
query.setFilterQueries( "features:two" );
rsp = server.query( query );
ff = rsp.getFacetField( "features" );
assertEquals( "[two (5), four (2), five (1), three (1)]", ff.getValues().toString() );
// with minCount > 3
query.setFacetMinCount( 4 );
rsp = server.query( query );
ff = rsp.getFacetField( "features" );
assertEquals( "[two (5)]", ff.getValues().toString() );
// with minCount > 3
query.setFacetMinCount( -1 );
rsp = server.query( query );
ff = rsp.getFacetField( "features" );
// System.out.println( rsp.getResults().getNumFound() + " :::: 444: "+ff.getValues() );
}