2012-03-13 21 views
1
<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(不同)。Solr根據關鍵字搜索不同的「nids」

$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; 
    } 

回答

0

我想你會想用faceting。小的nid

?q=search&facet=true&facet.field=nid&rows=0 

它會給你的每次數匹配沿着該nid s的列表在搜索中找到。使用&rows=0只會返回方面計數。

編輯:還有一兩件事,一定要設置facet.limit=-1(或任何其他負數)指定所有結果,並facet.mincount=1,以確保只有匹配返回。否則,它將返回與零計數不匹配。如果要按計數排序(如果facet.limit小於1,則默認情況下不會),也可以添加facet.sort=count

+0

我的編輯看起來不錯嗎? – 2012-03-13 21:33:38

+0

我沒有使用PHP Solr服務,所以我不能肯定地說,但對於我未經訓練的眼睛,它看起來確定。 – 2012-03-13 21:39:42