希望你一切都好。
我是弹性搜索的新手,使用 ElasticSearchDSL 插件当然很棒,因为您有可以应用某些逻辑的条件,例如是否设置了某些内容、包含它等等。
我似乎碰到了一堵砖墙,因为我希望能够按相关性作为默认排序,但说提供按 date_closing、date_posted 等排序的选项(它是一个求职功能)。
除非我错过了 ONGR 网站上的一些术语,否则有人在 ElasticSearchDSL 之前遇到过这种情况吗?
我有以下当前代码(如果需要):
$termQueryForTitle = new ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery('title', $keyword);
$termQueryForDescription = new ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery('description', $keyword);
$termQueryForStatus = new ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery('status', 1);
$termQueryForDeleted = new ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery('is_deleted', 0);
$rangeQueryDateClosing = new ONGR\ElasticsearchDSL\Query\TermLevel\RangeQuery('date_closing', ['gte' => date('Y-m-d')]);
$termsQuerySector = new ONGR\ElasticsearchDSL\Query\TermLevel\TermsQuery('job_sector_id', [implode('\', \'', array_filter($sector_id))]);
$termsQuerySubject = new ONGR\ElasticsearchDSL\Query\TermLevel\TermsQuery('job_subject_id', [implode('\', \'', array_filter($subject_id))]);
$termsQueryArea = new ONGR\ElasticsearchDSL\Query\TermLevel\TermsQuery('area_id', [implode('\', \'', array_filter($area_id))]);
$termsQueryTown = new ONGR\ElasticsearchDSL\Query\TermLevel\TermsQuery('town_id', [implode('\', \'', array_filter($town_id))]);
$bool = new ONGR\ElasticsearchDSL\Query\Compound\BoolQuery();
//$bool->addParameter('minimum_should_match', 1);
//$bool->addParameter('boost', 1);
if($keyword != '')
{
$bool->add($termQueryForTitle, $bool::SHOULD);
$bool->add($termQueryForDescription, $bool::SHOULD);
}
if(count($sector_id) > 0)
{
$bool->add($termsQuerySector, $bool::MUST);
}
if(count($subject_id) > 0)
{
$bool->add($termsQuerySubject, $bool::MUST);
}
if(count($area_id) > 0)
{
$bool->add($termsQueryArea, $bool::MUST);
}
if(count($town_id) > 0)
{
$bool->add($termsQueryTown, $bool::MUST);
}
$bool->add($rangeQueryDateClosing, $bool::MUST);
$bool->add($termQueryForStatus, $bool::FILTER);
$bool->add($termQueryForDeleted, $bool::FILTER);
$DSL_search = new ONGR\ElasticsearchDSL\Search();
$DSL_search->addQuery($bool);
$query_params = $DSL_search->toArray();
$data = $this->__elastic->Search_document('jobs', $query_params, $limit, $offset);
//pprint_r($data);
TIA