本文整理汇总了PHP中Zend\Search\Lucene\Lucene::setDefaultSearchField方法的典型用法代码示例。如果您正苦于以下问题:PHP Lucene::setDefaultSearchField方法的具体用法?PHP Lucene::setDefaultSearchField怎么用?PHP Lucene::setDefaultSearchField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Search\Lucene\Lucene
的用法示例。
在下文中一共展示了Lucene::setDefaultSearchField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mapQuery
/**
* Transforms a generic Query object into an Elastic Search query DSL
*
* @param Query $query
*/
public function mapQuery(Query $query)
{
$arguments = array();
$map = new Boolean();
if ($query->hasQueryString()) {
Lucene::setDefaultSearchField($query->getQueryString()->getDefaultField());
QueryParser::setDefaultOperator($query->getQueryString()->getDefaultOperator() == Query::OPERATOR_AND ? QueryParser::B_AND : QueryParser::B_OR);
$keyword = $query->getQueryString()->getQuery();
if ("*" === $keyword) {
$subQuery = new Wildcard(new Term($keyword));
$subQuery->setMinPrefixLength(0);
} else {
$subQuery = QueryParser::parse($keyword);
}
$map->addSubquery($subQuery, true);
}
$arguments[] = $map;
foreach ($query->getSort() as $sort) {
$arguments[] = key($sort);
$arguments[] = SORT_REGULAR;
$arguments[] = current($sort) == 'asc' ? SORT_ASC : SORT_DESC;
}
return $arguments;
}
示例2: testDefaultSearchField
public function testDefaultSearchField()
{
$currentDefaultSearchField = Lucene\Lucene::getDefaultSearchField();
$this->assertEquals($currentDefaultSearchField, null);
Lucene\Lucene::setDefaultSearchField('anotherField');
$this->assertEquals(Lucene\Lucene::getDefaultSearchField(), 'anotherField');
Lucene\Lucene::setDefaultSearchField($currentDefaultSearchField);
}
示例3: testQueryHit
public function testQueryHit()
{
// Restore default search field if it wasn't done by previous test because of failure
Lucene\Lucene::setDefaultSearchField(null);
$index = Lucene\Lucene::open(dirname(__FILE__) . '/_index23Sample/_files');
$hits = $index->find('submitting AND wishlists');
$hit = $hits[0];
$this->assertTrue($hit instanceof Search\QueryHit);
$this->assertTrue($hit->getIndex() instanceof Lucene\IndexInterface);
$doc = $hit->getDocument();
$this->assertTrue($doc instanceof Document\Document);
$this->assertEquals($doc->path, 'IndexSource/contributing.html');
}