本文整理汇总了PHP中Zend_Search_Lucene_Search_Query_Wildcard类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_Query_Wildcard类的具体用法?PHP Zend_Search_Lucene_Search_Query_Wildcard怎么用?PHP Zend_Search_Lucene_Search_Query_Wildcard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Search_Lucene_Search_Query_Wildcard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMatchingConnections
function getMatchingConnections($criteria)
{
$index = $this->getIndex();
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
Zend_Search_Lucene::setResultSetLimit(25);
// TODO during dev
$results = $index->find($criteria);
$ret = array();
foreach ($results as $hit) {
$res = array();
$res['created'] = $hit->created;
try {
$res['title'] = $hit->title;
} catch (Zend_Search_Lucene_Exception $e) {
$res['title'] = '';
}
try {
$res['url'] = $hit->url;
} catch (Zend_Search_Lucene_Exception $e) {
$res['url'] = '';
}
try {
$res['keywords'] = $hit->keywords;
} catch (Zend_Search_Lucene_Exception $e) {
$res['keywords'] = '';
}
try {
$res['language'] = $hit->language;
} catch (Zend_Search_Lucene_Exception $e) {
$res['language'] = '';
}
try {
$res['geo_lat'] = $hit->geo_lat;
} catch (Zend_Search_Lucene_Exception $e) {
$res['geo_lat'] = '';
}
try {
$res['geo_lon'] = $hit->geo_lon;
} catch (Zend_Search_Lucene_Exception $e) {
$res['geo_lon'] = '';
}
try {
$res['geo_zoom'] = $hit->geo_zoom;
} catch (Zend_Search_Lucene_Exception $e) {
$res['geo_zoom'] = '';
}
$res['class'] = 'tablename';
$res['metadata'] = '';
if ($res['geo_lat'] && $res['geo_lon']) {
$res['class'] .= ' geolocated connection';
$res['metadata'] = " data-geo-lat=\"{$res['geo_lat']}\" data-geo-lon=\"{$res['geo_lon']}\"";
if (isset($res['geo_zoom'])) {
$res['metadata'] .= " data-geo-zoom=\"{$res['geo_zoom']}\"";
}
$res['metadata'] .= ' data-icon-name="tiki"';
}
$ret[] = $res;
}
return $ret;
}
示例2: luceneSearchAction
public function luceneSearchAction()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$path = PUBLIC_PATH . '/tmp/lucene';
$index = Zend_Search_Lucene::open($path);
// $term = new Zend_Search_Lucene_Index_Term('ritesh','title');
// $subquery1 = new Zend_Search_Lucene_Search_Query_Term($term);
//
// $from = new Zend_Search_Lucene_Index_Term('0', 'empcode');
// $to = new Zend_Search_Lucene_Index_Term('53', 'empcode');
// $subquery2 = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);
//
// $query = new Zend_Search_Lucene_Search_Query_Boolean();
// $query->addSubquery($subquery1, true );
// $query->addSubquery($subquery2, null );
// Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
// $hits = $index->find($query);
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
$hits = $index->find("empcode:[000 TO 200]");
foreach ($hits as $h) {
echo "Title:" . $h->title;
echo "-------EmpCode:" . $h->empcode;
echo "<br>";
}
}
示例3: find
/**
* @param $queryString
* @return array
*/
public function find($queryString)
{
$queryString = trim($queryString);
if (empty($queryString)) {
return ["queryString" => $queryString, "message" => "No String"];
} else {
$index = \Zend_Search_Lucene::open($this->indexfile);
$res = explode(' ', $queryString);
\Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
\Zend_Search_Lucene::setResultSetLimit(5);
$query = new \Zend_Search_Lucene_Search_Query_Boolean();
foreach ($res as $val) {
if (!empty($val)) {
$subquery = new \Zend_Search_Lucene_Search_Query_Boolean();
$searchkey1 = $val . "*";
$pattern = new \Zend_Search_Lucene_Index_Term($searchkey1, "name");
$userQuery = new \Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$patternUsername = new \Zend_Search_Lucene_Index_Term($searchkey1, "username");
$usernameQuery = new \Zend_Search_Lucene_Search_Query_Wildcard($patternUsername);
$subquery->addSubquery($userQuery, null);
$subquery->addSubquery($usernameQuery, null);
$query->addSubquery($subquery, true);
}
}
$hits = $index->find($query);
if (!empty($hits)) {
$results = [];
foreach ($hits as $hit) {
if ($hit->username != $_SESSION['user']->username) {
$results[] = $hit->username;
}
}
if (!empty($results)) {
/** @noinspection PhpUndefinedMethodInspection */
/** @var Users $users */
$users = $_SESSION['user']->getTable();
if (isset($_POST['friends'])) {
/** @noinspection PhpUndefinedMethodInspection */
$friends = $_SESSION['user']->getFriendList();
if (empty($friends)) {
return ["queryString" => $queryString, "users" => []];
} else {
$userresult = $users->getSet($results, 'u.username');
}
} else {
$userresult = $users->getSet($results, "u.username", ["u.userid", "u.username", "u.name"]);
}
return ["queryString" => $queryString, "users" => $userresult->toArray()];
}
}
}
return ["queryString" => $queryString];
}
示例4: prepareLuceneQuery
protected function prepareLuceneQuery($keyword)
{
$keyword = strtolower($keyword);
$query = new Zend_Search_Lucene_Search_Query_Boolean();
# multiterm query
$subquery1 = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach (explode(' ', $keyword) as $key) {
if (!trim($key)) {
continue;
}
$subquery1->addTerm(new Zend_Search_Lucene_Index_Term($key));
}
# wildcard query
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
$tokens = preg_split('/ /', $keyword, -1, PREG_SPLIT_NO_EMPTY);
$lastWord = trim(array_pop($tokens)) . "*";
$pattern = new Zend_Search_Lucene_Index_Term($lastWord);
$subquery2 = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$query->addSubquery($subquery1);
$query->addSubquery($subquery2);
return $query;
}
示例5: _highlightMatches
/**
* Query specific matches highlighting
*
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for highlighting)
*/
protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{
/** Skip fields detection. We don't need it, since we expect all fields presented in the HTML body and don't differentiate them */
/** Skip exact term matching recognition, keyword fields highlighting is not supported */
// -------------------------------------
// Recognize wildcard queries
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */
if (@preg_match('/\\pL/u', 'a') == 1) {
$word = iconv($this->_encoding, 'UTF-8', $this->_word);
$wildcardsPattern = '/[*?]/u';
$subPatternsEncoding = 'UTF-8';
} else {
$word = $this->_word;
$wildcardsPattern = '/[*?]/';
$subPatternsEncoding = $this->_encoding;
}
$subPatterns = preg_split($wildcardsPattern, $word, -1, PREG_SPLIT_OFFSET_CAPTURE);
if (count($subPatterns) > 1) {
// Wildcard query is recognized
$pattern = '';
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
foreach ($subPatterns as $id => $subPattern) {
// Append corresponding wildcard character to the pattern before each sub-pattern (except first)
if ($id != 0) {
$pattern .= $word[$subPattern[1] - 1];
}
// Check if each subputtern is a single word in terms of current analyzer
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPattern[0], $subPatternsEncoding);
if (count($tokens) > 1) {
// Do nothing (nothing is highlighted)
return;
}
foreach ($tokens as $token) {
$pattern .= $token->getTermText();
}
}
require_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Wildcard.php';
$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
$query->_highlightMatches($highlighter);
return;
}
// -------------------------------------
// Recognize one-term multi-term and "insignificant" queries
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding);
if (count($tokens) == 0) {
// Do nothing
return;
}
if (count($tokens) == 1) {
$highlighter->highlight($tokens[0]->getTermText());
return;
}
//It's not insignificant or one term query
$words = array();
foreach ($tokens as $token) {
$words[] = $token->getTermText();
}
$highlighter->highlight($words);
}
示例6: tearDown
public function tearDown()
{
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($this->_wildcardMinPrefix);
Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($this->_defaultPrefixLength);
}
示例7: testWildcardQuery
public function testWildcardQuery()
{
$index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_index23Sample/_files');
$wildcardMinPrefix = Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength();
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
$hits = $index->find('*cont*');
$this->assertEquals(count($hits), 9);
$expectedResultset = array(array(8, 0.328087, 'IndexSource/contributing.html'), array(2, 0.318592, 'IndexSource/contributing.patches.html'), array(7, 0.260137, 'IndexSource/contributing.bugs.html'), array(0, 0.203372, 'IndexSource/contributing.documentation.html'), array(1, 0.202366, 'IndexSource/contributing.wishlist.html'), array(4, 0.052931, 'IndexSource/copyright.html'), array(3, 0.01707, 'IndexSource/about-pear.html'), array(5, 0.01015, 'IndexSource/authors.html'), array(9, 0.003504, 'IndexSource/core.html'));
foreach ($hits as $resId => $hit) {
$this->assertEquals($hit->id, $expectedResultset[$resId][0]);
$this->assertTrue(abs($hit->score - $expectedResultset[$resId][1]) < 1.0E-6);
$this->assertEquals($hit->path, $expectedResultset[$resId][2]);
}
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($wildcardMinPrefix);
}
示例8: getQuery
/**
* Transform entry to a subquery
*
* @param string $encoding
* @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException
*/
public function getQuery($encoding)
{
if (strpos($this->_term, '?') !== false || strpos($this->_term, '*') !== false) {
if ($this->_fuzzyQuery) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is not supported for terms with wildcards.');
}
$pattern = '';
$subPatterns = explode('*', $this->_term);
$astericFirstPass = true;
foreach ($subPatterns as $subPattern) {
if (!$astericFirstPass) {
$pattern .= '*';
} else {
$astericFirstPass = false;
}
$subPatternsL2 = explode('?', $subPattern);
$qMarkFirstPass = true;
foreach ($subPatternsL2 as $subPatternL2) {
if (!$qMarkFirstPass) {
$pattern .= '?';
} else {
$qMarkFirstPass = false;
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPatternL2, $encoding);
if (count($tokens) > 1) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard search is supported only for non-multiple word terms');
}
foreach ($tokens as $token) {
$pattern .= $token->getTermText();
}
}
}
$term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
$query->setBoost($this->_boost);
return $query;
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_term, $encoding);
if (count($tokens) == 0) {
return new Zend_Search_Lucene_Search_Query_Insignificant();
}
if (count($tokens) == 1 && !$this->_fuzzyQuery) {
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->_boost);
return $query;
}
if (count($tokens) == 1 && $this->_fuzzyQuery) {
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_similarity);
$query->setBoost($this->_boost);
return $query;
}
if ($this->_fuzzyQuery) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is supported only for non-multiple word terms');
}
//It's not empty or one term query
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
/**
* @todo Process $token->getPositionIncrement() to support stemming, synonyms and other
* analizer design features
*/
foreach ($tokens as $token) {
$term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field);
$query->addTerm($term, true);
// all subterms are required
}
$query->setBoost($this->_boost);
return $query;
}
示例9: setDefaultAnalyzer
protected function setDefaultAnalyzer()
{
switch ($this->getFilteredOption("QUERY_ANALYSER")) {
case "utf8num_insensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
break;
case "utf8num_sensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num());
break;
case "utf8_insensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
break;
case "utf8_sensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
break;
case "textnum_insensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
break;
case "textnum_sensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_textNum());
break;
case "text_insensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive());
break;
case "text_sensitive":
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Text());
break;
default:
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
break;
}
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(intval($this->getFilteredOption("WILDCARD_LIMITATION")));
}
示例10: open_index
/**
*
* @throws nc_search_exception
*/
protected function open_index()
{
$path = $this->get_index_path();
try {
if ($this->index_exists($path)) {
$this->index = Zend_Search_Lucene::open($path);
} else {
$this->index = Zend_Search_Lucene::create($path);
}
} catch (Zend_Search_Lucene_Exception $e) {
throw new nc_search_exception("Cannot open Lucene index: {$e->getMessage()}");
}
$this->is_opened = true;
// apply settings to the index
Zend_Search_Lucene::setResultSetLimit($this->get_setting('ZendSearchLucene_ResultSetLimit'));
Zend_Search_Lucene::setTermsPerQueryLimit($this->get_setting('MaxTermsPerQuery'));
$settings = array('MaxBufferedDocs', 'MaxMergeDocs', 'MergeFactor');
foreach ($settings as $s) {
$setter = "set{$s}";
$this->index->{$setter}($this->get_setting("ZendSearchLucene_{$s}"));
}
// set analyzer
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new nc_search_provider_zend_analyzer());
// set fuzzy prefix length so fuzzy searches will match a wider array of possibilities
Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength(0);
// set wildcard prefix length so wildcards will match a wider array of possibilities
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
/**
* @todo set default search fields
*/
}
示例11: isset
{
static $instances;
isset($name) && isset($thing) and $instances[$name] =& $thing;
return $instances[$name];
}
ini_set("error_reporting", E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . "zend");
singleton("errors_fatal", false);
singleton("errors_format", "html");
singleton("errors_logged", false);
singleton("errors_thrown", false);
singleton("errors_haltdb", false);
// Set the charset for Zend Lucene search indexer http://framework.zend.com/manual/en/zend.search.lucene.charset.html
require_once "Zend" . DIRECTORY_SEPARATOR . "Search" . DIRECTORY_SEPARATOR . "Lucene.php";
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
// Undo magic quotes if it's enabled
if (get_magic_quotes_gpc()) {
function stripslashes_array($array)
{
return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
}
$_COOKIE = stripslashes_array($_COOKIE);
$_FILES = stripslashes_array($_FILES);
$_GET = stripslashes_array($_GET);
$_POST = stripslashes_array($_POST);
$_REQUEST = stripslashes_array($_REQUEST);
}
// Get the alloc directory
$f = trim(dirname(__FILE__));
substr($f, -1, 1) != DIRECTORY_SEPARATOR and $f .= DIRECTORY_SEPARATOR;
示例12: __construct
/**
* Constructor
*/
public function __construct()
{
$this->core = Zend_Registry::get('Core');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
}
示例13: wildcardFindTerms
/**
*
* @param string $queryStr
* @param \Zend_Search_Lucene_Interface $index
* @return Array $hits
*/
public static function wildcardFindTerms($queryStr, $index)
{
if ($index != NULL) {
$pattern = new \Zend_Search_Lucene_Index_Term($queryStr . '*');
$userQuery = new \Zend_Search_Lucene_Search_Query_Wildcard($pattern);
\Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(2);
$index->find($userQuery);
$terms = $userQuery->getQueryTerms();
return $terms;
}
}
示例14: _highlightMatches
protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{
if (@preg_match('/\\pL/u', 'a') == 1) {
$word = iconv($this->_encoding, 'UTF-8', $this->_word);
$wildcardsPattern = '/[*?]/u';
$subPatternsEncoding = 'UTF-8';
} else {
$word = $this->_word;
$wildcardsPattern = '/[*?]/';
$subPatternsEncoding = $this->_encoding;
}
$subPatterns = preg_split($wildcardsPattern, $word, -1, PREG_SPLIT_OFFSET_CAPTURE);
if (count($subPatterns) > 1) {
$pattern = '';
foreach ($subPatterns as $id => $subPattern) {
if ($id != 0) {
$pattern .= $word[$subPattern[1] - 1];
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPattern[0], $subPatternsEncoding);
if (count($tokens) > 1) {
return;
}
foreach ($tokens as $token) {
$pattern .= $token->getTermText();
}
}
$term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
$query->_highlightMatches($highlighter);
return;
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding);
if (count($tokens) == 0) {
return;
}
if (count($tokens) == 1) {
$highlighter->highlight($tokens[0]->getTermText());
return;
}
$words = array();
foreach ($tokens as $token) {
$words[] = $token->getTermText();
}
$highlighter->highlight($words);
}
示例15: searchPagesByQuery
/**
* Search all pages that match the query.
*
* <code>
* //$query = '(pi AND groupe AND partner*) OR pi-groupe';
* $query = " travers projet ference coin";
* $options = array(
* 'searchBool' => true,
* 'searchBoolType' => 'AND',
* 'searchByMotif' => true,
* 'setMinPrefixLength'=> 0,
* 'getResultSetLimit' => 0,
* 'searchFields' => array(
* 0=> array('sortField'=>'Contents', 'sortType'=> SORT_STRING, 'sortOrder' => SORT_ASC),
* 1=> array('sortField'=>'Key', 'sortType'=> SORT_NUMERIC, 'sortOrder' => SORT_DESC)
* ),
* );
* $result = $this->container->get('pi_app_admin.manager.search_lucene')->searchPagesByQuery($query, $options);
* </code>
*
* @link http://framework.zend.com/manual/fr/zend.search.lucene.searching.html
* @link http://framework.zend.com/manual/fr/learning.lucene.queries.html
* @link http://framework.zend.com/manual/1.12/fr/zend.search.lucene.query-api.html
* @param string $query The search query index file
* @param array $options Options of the search query of the index file
* @return array All Etags from pages that match the query.
* @access public
*
* @author Etienne de Longeaux <etienne_delongeaux@hotmail.com>
* @since 2012-06-11
*/
public function searchPagesByQuery($query = "Key:*", $options = null, $locale = '')
{
try {
if (isset($options) && is_array($options) && count($options) >= 1) {
$options_values = array_map(function ($key, $value) {
if (in_array($value, array("true"))) {
return 1;
} elseif (in_array($value, array("false"))) {
return 0;
} elseif (!is_array($value) && preg_match_all("/[0-9]+/", $value, $nbrs, PREG_SET_ORDER)) {
return intval($value);
} else {
return $value;
}
}, array_keys($options), array_values($options));
$options = array_combine(array_keys($options), $options_values);
}
if (empty($query)) {
return null;
} else {
$query = $this->container->get('sfynx.tool.string_manager')->minusculesSansAccents($query);
}
if (empty($locale)) {
$locale = $this->container->get('request')->getLocale();
}
$options_default = array('searchBool' => true, 'searchBoolType' => 'OR', 'searchByMotif' => true, 'setMinPrefixLength' => 0, 'getResultSetLimit' => 0, 'searchFields' => '*', 'searchMaxResultByWord' => 5);
if (is_array($options)) {
$options = array_merge($options_default, $options);
} else {
$options = $options_default;
}
if ($options['searchBool']) {
$q_string = $this->container->get('sfynx.tool.string_manager')->cleanWhitespace($query);
$q_array = explode(' ', $q_string);
if ($options['searchByMotif']) {
$q_array = array_map(function ($value) {
return $value . '*';
}, array_values($q_array));
}
switch ($options['searchBoolType']) {
case 'OR':
$new_query = implode(' OR ', $q_array);
break;
case 'AND':
$new_query = implode(' AND ', $q_array);
break;
default:
break;
}
} else {
$new_query = $query;
}
// Open the index.
self::open($this->_indexPath);
// Set minimum prefix length.
\Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($options['setMinPrefixLength']);
// Set result set limit.
\Zend_Search_Lucene::setResultSetLimit($options['getResultSetLimit']);
// Performs a query against the index.
if (is_array($options['searchFields']) && $query != "Key:*") {
$fields_vars = "\$hits = self::\$_index->find(\$new_query,";
$i = 0;
foreach ($options['searchFields'] as $key => $valuesField) {
$sortField = $valuesField["sortField"];
if (isset($valuesField["sortType"]) && !empty($valuesField["sortType"])) {
$sortType = $valuesField["sortType"];
} else {
$sortType = SORT_STRING;
}
//.........这里部分代码省略.........