2
我正在測試彈性和彈性搜索。我正在嘗試爲我的查詢添加一個過濾器,該過濾器只返回城市位置的結果。它正在返回空。我試着按用戶名過濾,等等,它總是返回空的,所以看起來我的理解並不完全正確。這裏是我的代碼進行分析,地圖,然後用過濾彈性過濾器不工作
$elasticaIndex = $elasticaClient->getIndex('users');
// Create the index new
$elasticaIndex->create(
array(
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('lowercase', 'lb_ngram')
),
'searchAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('standard', 'lowercase', 'lb_ngram')
)
),
'filter' => array(
'lb_ngram' => array(
"max_gram" => 10,
"min_gram" => 1,
"type" => "nGram"
)
)
)
), true
);
//Create a type
$elasticaType = $elasticaIndex->getType('profile');
// Set mapping
$mapping->setProperties(array(
//'id' => array('type' => 'integer', 'include_in_all' => FALSE),
'firstName' => array('type' => 'string', 'include_in_all' => TRUE),
'lastName' => array('type' => 'string', 'include_in_all' => TRUE),
'username' => array('type' => 'string', 'include_in_all' => TRUE),
'bio' => array('type' => 'string', 'include_in_all' => TRUE),
'thumbnail' => array('type' => 'string', 'include_in_all' => FALSE),
'location' => array('type' => 'string', 'include_in_all' => TRUE),
));
搜索.....然後搜索,我下面
$elasticaQueryString = new Elastica\Query\QueryString();
//'And' or 'Or' default : 'Or'
$elasticaQueryString->setDefaultOperator('AND');
$elasticaQueryString->setQuery($term);
// Create the actual search object with some data.
$elasticaQuery = new Elastica\Query();
$elasticaQuery->setQuery($elasticaQueryString);
要添加過濾
$elasticaFilterLocation = new \Elastica\Filter\Term();
//search 'location' = $region;
$elasticaFilterLocation->setTerm('location', $region);
$elasticaQuery->setFilter($elasticaFilterLocation);
$elasticaResultSet = $elasticaIndex->search($elasticaQuery);
$elasticaResults = $elasticaResultSet->getResults();
如果我註釋掉過濾器,我確實得到了預期的結果。我錯過了什麼?它是否與分析儀或映射有關?
你能提供更多的細節嗎?比如你改變了你的分析儀,你改變了什麼? – landland 2013-05-11 20:16:48
我用了2自定義分析儀1電子郵件,標記者:uax_url_email,另一個用於詞(如你的位置的情況下),分詞器:標準,通過試驗和錯誤做了一些東西,因爲沒有大量的文檔資料...如果告訴我你需要幫助 – CodeBird 2013-05-11 22:04:23
是的,請幫忙。我在這裏旋轉我的輪子無處可去。文檔非常稀少。我試圖使用tokenizer:標準的位置,並已重建我的索引,但它仍然返回空。 – landland 2013-05-12 16:21:43