<fields>
<field name="mongo_id" type="string" indexed="true" stored="true" required="true" />
<field name="nid" type="int" indexed="true" stored="true" required="true" />
<field name="keywords" type="text_general" indexed="true" stored="false" />
</fields>我想要得到匹配关键字的所有nid (distinct)。
$solr = new Apache_Solr_Service(SOLR_HOST, SOLR_PORT, SOLR_WEBAPP);
//How would I search here?
$results = $solr->search('search', 0, 100);编辑:
这样看起来对吗?
$solr = new Apache_Solr_Service(SOLR_HOST, SOLR_PORT, SOLR_WEBAPP);
$results = $solr->search(Apache_Solr_Service::escapePhrase($_GET['keywords']), 0, 0, array('facet' => 'true', 'facet.field' => 'nid', 'rows' => 0, 'facet.mincount' => 1));
foreach($results->facet_counts->facet_fields->nid as $nid=>$count)
{
$nids[] = (int)$nid;
}发布于 2012-03-14 05:09:48
我想你会想要使用faceting。nid上的方面
?q=search&facet=true&facet.field=nid&rows=0它将为您提供匹配的nid的列表,以及在搜索中找到每个you的次数。对于&rows=0,将只返回方面计数。
编辑:还有一件事,确保设置facet.limit=-1 (或任何其他负数)以指定所有结果,并设置facet.mincount=1以确保只返回匹配的结果。否则,它将返回计数为零的非匹配。如果您想要按计数排序(如果facet.limit小于1,则默认情况下不会),还需要添加facet.sort=count。
https://stackoverflow.com/questions/9692182
复制相似问题