本文整理汇总了PHP中Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength方法的具体用法?PHP Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength怎么用?PHP Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Search_Query_Wildcard
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: tearDown
public function tearDown()
{
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($this->_wildcardMinPrefix);
Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($this->_defaultPrefixLength);
}
示例6: 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);
}
示例7: 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")));
}
示例8: 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
*/
}
示例9: 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;
示例10: __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);
}
示例11: 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;
}
}
示例12: 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;
}
//.........这里部分代码省略.........
示例13: getskillsAction
public function getskillsAction()
{
$skills = $this->getRequest()->getParam('skills');
//$this->view->result=$post;
/**
* Open index
*/
$index = Search_MyLucene::open($this->_userindexPath);
//$term=new Zend_search_lucene_i
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
//$query = 'name:' . $post['name'];
$query = 'skills:' . $skills . '*';
$results = $index->find($query);
$matches = array();
foreach ($results as $values) {
$string = explode(' ', $values->skills);
foreach ($string as $str) {
if (stripos($str, $skills) === 0) {
array_push($matches, strtolower($str));
}
}
}
$matches = array_unique($matches);
$this->view->result = $matches;
}