2009-11-02 43 views
1

我試圖做一個布爾搜索'sname:'。$ user-> name'。 OR sname:xxxxxx; ,我沒有得到任何結果,因爲sname:xxxxxx;工作正常。我甚至用查詢修改鉤子添加了mm = 1。有人可以指導我如何做到這一點。如何在apache solr中進行布爾搜索

這裏是我的代碼.....

$keys = ""; 
$filters = 'sname:'.$user->name.' OR sname:xxxxxx; 
//print($filters); 
$solrsort = variable_get('apachesolr_search_taxonomy_sort', 'created desc'); 
$page = isset($_GET['page']) ? $_GET['page'] : 0; 
$_GET['retain-filters'] = 1; 

try { 
//stolen from search.module (search_data) 
$data = apachesolr_search_execute($keys, $filters, $solrsort, 'search/apachesolr_search', $page); 
$results = theme('search_results', $data, $type); 
} catch (Exception $e){ 
watchdog('apachesolr', t('Error running search')); 
} 

function reports_apachesolr_modify_query(&$query, &$params, $caller) { 
// I only want to see articles by the admin! 
$params['mm'] = 1; 
} 

進階感謝。

回答

1

$ user對象在某些地方不可用,因此它取決於您從哪裏調用它。您需要全局調用它。將以下內容添加到代碼的頂部。

$keys = ""; 
global $user; //Add this line 
$filters = 'sname:'.$user->name.' OR sname:xxxxxx'; 

另請注意,您錯過了xxxxxx後的結束引號。我在上面的代碼中添加了它。

+1

感謝ü的回答,但問題是不與用戶對象,問題是使用Apache Solr實現的dismax查詢生成器。 – pmarreddy

+0

Aww無賴。我們擔心我對Apache Solr語法不太瞭解,所以我不能真正幫助。 – theunraveler

0

您是否嘗試刪除第二個sname:?我SOLR過濾器看起來像:

(fname:carrie OR carol) 
AND 
(lname:miller OR jones)