private function buildExpr(array $objectList) { $query = new Search_Query(); foreach ($objectList as $object) { $object = (array) $object; $query->addObject($object['object_type'], $object['object_id']); } return $query->getExpr(); }
function testMoreLikeThisThroughAbstraction() { $builder = new QueryBuilder(); $builder->setDocumentReader(function ($type, $object) { return array('object_type' => $type, 'object_id' => $object, 'contents' => 'hello world'); }); $q = new Search_Query(); $q->filterSimilar('wiki page', 'A'); $query = $builder->build($q->getExpr()); $this->assertEquals(array('bool' => array('must' => array(array('more_like_this' => array('fields' => array('contents'), 'like_text' => 'hello world', 'boost' => 1.0))), 'must_not' => array(array('bool' => array('must' => array(array("match" => array("object_type" => array("query" => "wiki page"))), array("match" => array("object_id" => array("query" => "A"))))))))), $query['query']); }