我有一份solr索引作业。 一些工作出现多次,因为它们有多个可能的位置。 为了重复数据删除,我将我的查询结果分组为jobref。
我也有各种合作伙伴,我从中获得工作。我希望在分组后提供每个合作伙伴的工作计数。
到目前为止,我的(精简版)代码如下:
// create client(solr) instance
$client = new Solarium\Client($solr_config);
// get a select query instance
$query = $client->createSelect();
// query for all, for now
$query->setQuery('*:*');
// get the facetset component
$facetSet = $query->getFacetSet();
// create a facet field instance and set options
$facetSet->createFacetField('partners')->setField('partner');
// BUNCH OF CODE THAT ADDS FILTERQUIERIES ETC
// group jobs by jobref to avoid dupes (multiple locations)
$groupComponent = $query->getGrouping();
$groupComponent->addField('jobref');
$groupComponent->setLimit(1); // maximum number of items per group, only want the 1
$groupComponent->setNumberOfGroups(true);
// this executes the query and returns the result
$resultset = $client->select($query);
// get the grouped results
$groups = $resultset->getGrouping();
// get the facets
$facet = $resultset->getFacetSet()->getFacet('partners');
foreach ($facet as $value => $count) {
echo $value . ' [' . $count . ']<br/>';
}
$jobs = array();
// TODO: does this have to be so complicated??
foreach ($groups as $groupKey => $fieldGroup) {
$total_jobs = $fieldGroup->getNumberOfGroups();
foreach ($fieldGroup as $valueGroup) {
foreach ($valueGroup as $document) {
array_push($jobs, $document);
}
}
}
但是,我可以看到我的方面是在分组之前计算的,就像我为特定合作伙伴添加过滤器查询一样,我的方面计数高于我的总结果(分组)计数。如何在分组后计算/获取构面?
这是使用solarium php