我有使用elastica的php代码来执行产品搜索。当我选择产品类别为“off_furniture”和“home_furniture”时,elasticsearch 只返回类别为“home_category”的产品。
请给我一些启发。以下是我的代码:
$value = $_GET['prod'];
$filter_manufacturer = $_GET['man'];
$filter_price = $_GET['price'];
$cat = $_GET['cat'];
$queryString = new Elastica_Query_QueryString((string)$value);
$queryString->setDefaultOperator('OR')
->setFields(array('name'));
$category = explode("|", $cat);
$elasticaFilterBool = new Elastica_Filter_Bool();
$filter2 = new Elastica_Filter_Term();
$filter2->setTerm('prodcat', array('off_furniture','home_furniture'));
$elasticaFilterBool->addMust($filter2);
$query->setFilter($elasticaFilterBool);
// Create the search object and inject the client
$search = new Elastica_Search(new Elastica_Client());
// Configure and execute the search
$resultSet = $search->addIndex('products3')
->addType('product3')
->search($query);
foreach ($resultSet as $elasticaResult) {
$result = $elasticaResult->getData();
echo $result["name"]. "|";
echo $result["prodcat"]. "|";
echo $result["description"]. "|";
echo $result["price"]. "|";
echo $result["manufacturer"]. "|@";
}