下列四种搜索客户端实现中哪种写法更合理?

WBOY
Lepaskan: 2016-06-06 20:11:31
asal
932 orang telah melayarinya

<code>//方案一:

$mustFilter = Filter::getMustFilter();
$shouldFilter = Filter::getShouldFilter();
$notMustFilter = Filter::getNotMustFilter();

$queryFilter = Filter::getQueryFilter();

$mustFilter
    ->setTerm($termParmas)
    ->setTerms($termsParmas)
    ->setRange($rangeParams);


$queryParams = Filter::init($alias)
    ->addFilter($mustFilter)
    ->addFilter($shouldFilter)
    ->addFilter($notMustFilter)
    ->addFilter($queryFilter)
    ->setSort($sortParams)
    ->setLimit($from, $size)
    ->build();

$result = Searcher::search($queryParams);

//方案二:

Eql::getInstance()
    ->setMust()
        ->add('goog', 'eq', 1)
        ->add('a', '>', 2)
    ->setShould()
        ->add('goog', 'eq', 1)
        ->add('a', '>', 2)
    ->query('keyword');

//方案三:

Eql::query([
    ['a','eq', 1, 'must'],
    ['b','eq', 1, 'must'],
    ['c','eq', 1, 'should'],
    ['d','eq', 1, 'should'],
]);

//方案四:

$searcher = Searcher::getInstance();
$query = new Query();
$query->setMustCondition($mustCondition)
      ->setMustNotCondition($mustNotCondition)
      ->setSort($sortCondition)
      ->setPageSize(10)
      ->getPage(1);
$result = $searcher->search($query);</code>
Salin selepas log masuk
Salin selepas log masuk

回复内容:

<code>//方案一:

$mustFilter = Filter::getMustFilter();
$shouldFilter = Filter::getShouldFilter();
$notMustFilter = Filter::getNotMustFilter();

$queryFilter = Filter::getQueryFilter();

$mustFilter
    ->setTerm($termParmas)
    ->setTerms($termsParmas)
    ->setRange($rangeParams);


$queryParams = Filter::init($alias)
    ->addFilter($mustFilter)
    ->addFilter($shouldFilter)
    ->addFilter($notMustFilter)
    ->addFilter($queryFilter)
    ->setSort($sortParams)
    ->setLimit($from, $size)
    ->build();

$result = Searcher::search($queryParams);

//方案二:

Eql::getInstance()
    ->setMust()
        ->add('goog', 'eq', 1)
        ->add('a', '>', 2)
    ->setShould()
        ->add('goog', 'eq', 1)
        ->add('a', '>', 2)
    ->query('keyword');

//方案三:

Eql::query([
    ['a','eq', 1, 'must'],
    ['b','eq', 1, 'must'],
    ['c','eq', 1, 'should'],
    ['d','eq', 1, 'should'],
]);

//方案四:

$searcher = Searcher::getInstance();
$query = new Query();
$query->setMustCondition($mustCondition)
      ->setMustNotCondition($mustNotCondition)
      ->setSort($sortCondition)
      ->setPageSize(10)
      ->getPage(1);
$result = $searcher->search($query);</code>
Salin selepas log masuk
Salin selepas log masuk
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan