Merge pull request #126 from tractorcow/pulls/2.0/extra-fields

API Add VersionTitle and Archived fields to config
This commit is contained in:
Robbie Averill 2016-12-05 10:22:45 +13:00 committed by GitHub
commit 40d70a0b32
112 changed files with 3871 additions and 2991 deletions

View File

@ -12,16 +12,9 @@ php:
- 7.0 - 7.0
env: env:
- DB=MYSQL CORE_RELEASE=3.2 - DB=MYSQL CORE_RELEASE=3
matrix: matrix:
include:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.1
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3.2
allow_failures: allow_failures:
- php: 7.0 - php: 7.0

View File

@ -7,11 +7,11 @@
*/ */
if(!defined('DOCSVIEWER_PATH')) { if(!defined('DOCSVIEWER_PATH')) {
define('DOCSVIEWER_PATH', dirname(__FILE__)); define('DOCSVIEWER_PATH', dirname(__FILE__));
} }
if(!defined('DOCSVIEWER_DIR')) { if(!defined('DOCSVIEWER_DIR')) {
$dir = explode(DIRECTORY_SEPARATOR, DOCSVIEWER_PATH); $dir = explode(DIRECTORY_SEPARATOR, DOCSVIEWER_PATH);
define('DOCSVIEWER_DIR', array_pop($dir)); define('DOCSVIEWER_DIR', array_pop($dir));
} }

View File

@ -10,10 +10,10 @@
* array( * array(
* 'en/someniceurl/' => array( * 'en/someniceurl/' => array(
* 'filepath' => '/path/to/docs/en/SomeniceFile.md', * 'filepath' => '/path/to/docs/en/SomeniceFile.md',
* 'title' => 'Some nice URL', * 'title' => 'Some nice URL',
* 'summary' => 'Summary Text', * 'summary' => 'Summary Text',
* 'basename' => 'SomeniceFile.md', * 'basename' => 'SomeniceFile.md',
* 'type' => 'DocumentationPage' * 'type' => 'DocumentationPage'
* ) * )
* ) * )
* </code> * </code>
@ -21,10 +21,10 @@
* URL format is in the following structures: * URL format is in the following structures:
* *
* {lang}/{path} * {lang}/{path}
* {lang}/{module}/{path} * {lang}/{module}/{path}
* {lang}/{module}/{version}/{/path} * {lang}/{module}/{version}/{/path}
* *
* @package framework * @package framework
* @subpackage manifest * @subpackage manifest
*/ */
class DocumentationManifest class DocumentationManifest
@ -81,7 +81,7 @@ class DocumentationManifest
* or loaded from cache until needed. * or loaded from cache until needed.
* *
* @param bool $includeTests Include tests in the manifest. * @param bool $includeTests Include tests in the manifest.
* @param bool $forceRegen Force the manifest to be regenerated. * @param bool $forceRegen Force the manifest to be regenerated.
*/ */
public function __construct($forceRegen = false) public function __construct($forceRegen = false)
{ {
@ -89,10 +89,12 @@ class DocumentationManifest
$this->forceRegen = $forceRegen; $this->forceRegen = $forceRegen;
$this->registeredEntities = new ArrayList(); $this->registeredEntities = new ArrayList();
$this->cache = SS_Cache::factory('DocumentationManifest', 'Core', array( $this->cache = SS_Cache::factory(
'DocumentationManifest', 'Core', array(
'automatic_serialization' => true, 'automatic_serialization' => true,
'lifetime' => null 'lifetime' => null
)); )
);
$this->setupEntities(); $this->setupEntities();
} }
@ -138,6 +140,12 @@ class DocumentationManifest
$version = (isset($details['Version'])) ? $details['Version'] : ''; $version = (isset($details['Version'])) ? $details['Version'] : '';
$versionTitle = isset($details['VersionTitle'])
? $details['VersionTitle']
: $version;
$archived = !empty($details['Archived']);
$branch = (isset($details['Branch'])) ? $details['Branch'] : ''; $branch = (isset($details['Branch'])) ? $details['Branch'] : '';
$langs = scandir($path); $langs = scandir($path);
@ -147,6 +155,9 @@ class DocumentationManifest
foreach ($langs as $k => $lang) { foreach ($langs as $k => $lang) {
if (isset($possible[$lang])) { if (isset($possible[$lang])) {
/**
* @var DocumentationEntity $entity
*/
$entity = Injector::inst()->create( $entity = Injector::inst()->create(
'DocumentationEntity', $key 'DocumentationEntity', $key
); );
@ -155,7 +166,9 @@ class DocumentationManifest
$entity->setTitle($details['Title']); $entity->setTitle($details['Title']);
$entity->setLanguage($lang); $entity->setLanguage($lang);
$entity->setVersion($version); $entity->setVersion($version);
$entity->setVersionTitle($versionTitle);
$entity->setBranch($branch); $entity->setBranch($branch);
$entity->setIsArchived($archived);
if (isset($details['Stable'])) { if (isset($details['Stable'])) {
$entity->setIsStable($details['Stable']); $entity->setIsStable($details['Stable']);
@ -307,7 +320,7 @@ class DocumentationManifest
/** /**
* Get any redirect for the given url * Get any redirect for the given url
* *
* @param type $url * @param type $url
* @return string * @return string
*/ */
public function getRedirect($url) public function getRedirect($url)
@ -328,10 +341,12 @@ class DocumentationManifest
public function regenerate($cache = true) public function regenerate($cache = true)
{ {
$finder = new DocumentationManifestFileFinder(); $finder = new DocumentationManifestFileFinder();
$finder->setOptions(array( $finder->setOptions(
array(
'dir_callback' => array($this, 'handleFolder'), 'dir_callback' => array($this, 'handleFolder'),
'file_callback' => array($this, 'handleFile') 'file_callback' => array($this, 'handleFile')
)); )
);
$this->redirects = array(); $this->redirects = array();
foreach ($this->getEntities() as $entity) { foreach ($this->getEntities() as $entity) {
@ -355,21 +370,23 @@ class DocumentationManifest
$this->pages = array(); $this->pages = array();
foreach ($grouped as $entity) { foreach ($grouped as $entity) {
uasort($entity, function ($a, $b) { uasort(
// ensure parent directories are first $entity, function ($a, $b) {
$a['filepath'] = str_replace('index.md', '', $a['filepath']); // ensure parent directories are first
$b['filepath'] = str_replace('index.md', '', $b['filepath']); $a['filepath'] = str_replace('index.md', '', $a['filepath']);
$b['filepath'] = str_replace('index.md', '', $b['filepath']);
if (strpos($b['filepath'], $a['filepath']) === 0) { if (strpos($b['filepath'], $a['filepath']) === 0) {
return -1; return -1;
}
if ($a['filepath'] == $b['filepath']) {
return 0;
}
return ($a['filepath'] < $b['filepath']) ? -1 : 1;
} }
);
if ($a['filepath'] == $b['filepath']) {
return 0;
}
return ($a['filepath'] < $b['filepath']) ? -1 : 1;
});
$this->pages = array_merge($this->pages, $entity); $this->pages = array_merge($this->pages, $entity);
} }
@ -390,23 +407,25 @@ class DocumentationManifest
/** /**
* Remove the link_base from the start of a link * Remove the link_base from the start of a link
* *
* @param string $link * @param string $link
* @return string * @return string
*/ */
protected function stripLinkBase($link) protected function stripLinkBase($link)
{ {
return ltrim(str_replace( return ltrim(
Config::inst()->get('DocumentationViewer', 'link_base'), str_replace(
'', Config::inst()->get('DocumentationViewer', 'link_base'),
$link '',
), '/'); $link
), '/'
);
} }
/** /**
* *
* @param DocumentationPage $page * @param DocumentationPage $page
* @param string $basename * @param string $basename
* @param string $path * @param string $path
*/ */
protected function addPage($page, $basename, $path) protected function addPage($page, $basename, $path)
{ {
@ -465,7 +484,7 @@ class DocumentationManifest
* *
* @param string $basename * @param string $basename
* @param string $path * @param string $path
* @param int $depth * @param int $depth
*/ */
public function handleFile($basename, $path, $depth) public function handleFile($basename, $path, $depth)
{ {
@ -503,10 +522,14 @@ class DocumentationManifest
$parts = explode('/', trim($record->getRelativeLink(), '/')); $parts = explode('/', trim($record->getRelativeLink(), '/'));
// Add the base link. // Add the base link.
$output->push(new ArrayData(array( $output->push(
'Link' => $base->Link(), new ArrayData(
'Title' => $base->Title array(
))); 'Link' => $base->Link(),
'Title' => $base->Title
)
)
);
$progress = $base->Link(); $progress = $base->Link();
@ -514,10 +537,14 @@ class DocumentationManifest
if ($part) { if ($part) {
$progress = Controller::join_links($progress, $part, '/'); $progress = Controller::join_links($progress, $part, '/');
$output->push(new ArrayData(array( $output->push(
'Link' => $progress, new ArrayData(
'Title' => DocumentationHelper::clean_page_name($part) array(
))); 'Link' => $progress,
'Title' => DocumentationHelper::clean_page_name($part)
)
)
);
} }
} }
@ -542,20 +569,24 @@ class DocumentationManifest
foreach ($this->getPages() as $url => $page) { foreach ($this->getPages() as $url => $page) {
if ($grabNext && strpos($page['filepath'], $entityBase) !== false) { if ($grabNext && strpos($page['filepath'], $entityBase) !== false) {
return new ArrayData(array( return new ArrayData(
array(
'Link' => Controller::join_links(Config::inst()->get('DocumentationViewer', 'link_base'), $url), 'Link' => Controller::join_links(Config::inst()->get('DocumentationViewer', 'link_base'), $url),
'Title' => $page['title'] 'Title' => $page['title']
)); )
);
} }
if ($filepath == $page['filepath']) { if ($filepath == $page['filepath']) {
$grabNext = true; $grabNext = true;
} elseif (!$fallback && strpos($page['filepath'], $filepath) !== false) { } elseif (!$fallback && strpos($page['filepath'], $filepath) !== false) {
$fallback = new ArrayData(array( $fallback = new ArrayData(
array(
'Link' => Controller::join_links(Config::inst()->get('DocumentationViewer', 'link_base'), $url), 'Link' => Controller::join_links(Config::inst()->get('DocumentationViewer', 'link_base'), $url),
'Title' => $page['title'], 'Title' => $page['title'],
'Fallback' => true 'Fallback' => true
)); )
);
} }
} }
@ -584,10 +615,12 @@ class DocumentationManifest
foreach ($this->getPages() as $url => $page) { foreach ($this->getPages() as $url => $page) {
if ($filepath == $page['filepath']) { if ($filepath == $page['filepath']) {
if ($previousUrl) { if ($previousUrl) {
return new ArrayData(array( return new ArrayData(
array(
'Link' => Controller::join_links(Config::inst()->get('DocumentationViewer', 'link_base'), $previousUrl), 'Link' => Controller::join_links(Config::inst()->get('DocumentationViewer', 'link_base'), $previousUrl),
'Title' => $previousPage['title'] 'Title' => $previousPage['title']
)); )
);
} }
} }
@ -666,13 +699,17 @@ class DocumentationManifest
$children = $this->getChildrenFor($pagePath, $recordPath); $children = $this->getChildrenFor($pagePath, $recordPath);
} }
$output->push(new ArrayData(array( $output->push(
'Link' => Controller::join_links($base, $url, '/'), new ArrayData(
'Title' => $page['title'], array(
'LinkingMode' => $mode, 'Link' => Controller::join_links($base, $url, '/'),
'Summary' => $page['summary'], 'Title' => $page['title'],
'Children' => $children 'LinkingMode' => $mode,
))); 'Summary' => $page['summary'],
'Children' => $children
)
)
);
} }
} }
@ -720,8 +757,7 @@ class DocumentationManifest
} }
/** /**
* @param DocumentationEntity * @param DocumentationEntity $entity
*
* @return ArrayList * @return ArrayList
*/ */
public function getVersions($entity) public function getVersions($entity)
@ -732,17 +768,26 @@ class DocumentationManifest
$output = new ArrayList(); $output = new ArrayList();
/**
* @var DocumentationEntity $check
*/
foreach ($this->getEntities() as $check) { foreach ($this->getEntities() as $check) {
if ($check->getKey() == $entity->getKey()) { if ($check->getKey() == $entity->getKey()) {
if ($check->getLanguage() == $entity->getLanguage()) { if ($check->getLanguage() == $entity->getLanguage()) {
$same = ($check->getVersion() == $entity->getVersion()); $same = ($check->getVersion() == $entity->getVersion());
$output->push(new ArrayData(array( $output->push(
'Title' => $check->getVersion(), new ArrayData(
'Link' => $check->Link(), array(
'LinkingMode' => ($same) ? 'current' : 'link', 'Title' => $check->getVersionTitle(),
'IsStable' => $check->getIsStable() 'Version' => $check->getVersion(),
))); 'Archived' => $check->getIsArchived(),
'Link' => $check->Link(),
'LinkingMode' => ($same) ? 'current' : 'link',
'IsStable' => $check->getIsStable()
)
)
);
} }
} }
} }
@ -772,6 +817,7 @@ class DocumentationManifest
/** /**
* Gets whether there is a default entity or not * Gets whether there is a default entity or not
*
* @return boolean * @return boolean
*/ */
public function getHasDefaultEntity() public function getHasDefaultEntity()

View File

@ -30,11 +30,11 @@ class DocumentationParser
* Pathparts: folder/subfolder/page * Pathparts: folder/subfolder/page
* *
* @param DocumentationPage $page * @param DocumentationPage $page
* @param String $baselink Link relative to webroot, up until the "root" * @param string $baselink Link relative to webroot, up until the "root" of the module.
* of the module. Necessary to rewrite relative * Necessary to rewrite relative links of the module. Necessary
* links * to rewrite relative links
* *
* @return String * @return string
*/ */
public static function parse(DocumentationPage $page, $baselink = null) public static function parse(DocumentationPage $page, $baselink = null)
{ {
@ -238,16 +238,22 @@ class DocumentationParser
} }
// Rewrite URL (relative or absolute) // Rewrite URL (relative or absolute)
$baselink = DocumentationHelper::relativePath(DocumentationHelper::normalizePath( $baselink = DocumentationHelper::relativePath(
dirname($page->getPath()) DocumentationHelper::normalizePath(
)); dirname($page->getPath())
)
);
// if the image starts with a slash, it's absolute // if the image starts with a slash, it's absolute
if (substr($url, 0, 1) == '/') { if (substr($url, 0, 1) == '/') {
$relativeUrl = DocumentationHelper::normalizePath(str_replace(BASE_PATH, '', Controller::join_links( $relativeUrl = DocumentationHelper::normalizePath(
$page->getEntity()->getPath(), str_replace(
$url BASE_PATH, '', Controller::join_links(
))); $page->getEntity()->getPath(),
$url
)
)
);
} else { } else {
$relativeUrl = rtrim($baselink, '/') . '/' . ltrim($url, '/'); $relativeUrl = rtrim($baselink, '/') . '/' . ltrim($url, '/');
} }
@ -264,7 +270,7 @@ class DocumentationParser
); );
// Replace any double slashes (apart from protocol) // Replace any double slashes (apart from protocol)
// $absoluteUrl = preg_replace('/([^:])\/{2,}/', '$1/', $absoluteUrl); // $absoluteUrl = preg_replace('/([^:])\/{2,}/', '$1/', $absoluteUrl);
// Replace in original content // Replace in original content
$md = str_replace( $md = str_replace(
@ -299,8 +305,8 @@ class DocumentationParser
* The markdown parser gets confused by the extra pair of parentheses in links of the form [DataObject](api:DataObject::populateDefaults()) so * The markdown parser gets confused by the extra pair of parentheses in links of the form [DataObject](api:DataObject::populateDefaults()) so
* all links are re-written as html markup instead of markdown [Title](url). This also prevents other markdown parsing problems. * all links are re-written as html markup instead of markdown [Title](url). This also prevents other markdown parsing problems.
* *
* @param String $markdown * @param String $markdown
* @param DocumentationPage $doc_page * @param DocumentationPage $doc_page
* @return String * @return String
*/ */
public static function rewrite_api_links($markdown, $doc_page) public static function rewrite_api_links($markdown, $doc_page)
@ -324,19 +330,19 @@ class DocumentationParser
preg_match_all($regex, $markdown, $links); preg_match_all($regex, $markdown, $links);
if($links) { if($links) {
foreach($links[0] as $i => $match) { foreach($links[0] as $i => $match) {
if($type === 'no_title'){ if($type === 'no_title') {
$title = $links[1][$i]; $title = $links[1][$i];
$link = $links[1][$i]; $link = $links[1][$i];
// change backticked links to avoid being parsed in the same way as non-backticked links // change backticked links to avoid being parsed in the same way as non-backticked links
$markdown = str_replace('`'.$match.'`','XYZ'.$link.'XYZ',$markdown); $markdown = str_replace('`'.$match.'`', 'XYZ'.$link.'XYZ', $markdown);
} else { } else {
$title = $links[1][$i]; $title = $links[1][$i];
$link = $links[2][$i]; $link = $links[2][$i];
// change backticked links to avoid being parsed in the same way as non-backticked links // change backticked links to avoid being parsed in the same way as non-backticked links
$markdown = str_replace('`'.$match.'`','XX'.$title.'YY'.$link.'ZZ',$markdown); $markdown = str_replace('`'.$match.'`', 'XX'.$title.'YY'.$link.'ZZ', $markdown);
} }
$html = sprintf($html_format, $link, $version, $module, $title); $html = sprintf($html_format, $link, $version, $module, $title);
$markdown = str_replace($match,$html,$markdown); $markdown = str_replace($match, $html, $markdown);
} }
} }
} }
@ -346,7 +352,7 @@ class DocumentationParser
if($links) { if($links) {
foreach($links[0] as $i => $match) { foreach($links[0] as $i => $match) {
$link = $links[1][$i]; $link = $links[1][$i];
$markdown = str_replace($match,'`[api:'.$link.']`',$markdown); $markdown = str_replace($match, '`[api:'.$link.']`', $markdown);
} }
} }
@ -356,7 +362,7 @@ class DocumentationParser
foreach($links[0] as $i => $match) { foreach($links[0] as $i => $match) {
$title = $links[1][$i]; $title = $links[1][$i];
$link = $links[2][$i]; $link = $links[2][$i];
$markdown = str_replace($match,'`['.$title.'](api:'.$link.')`',$markdown); $markdown = str_replace($match, '`['.$title.'](api:'.$link.')`', $markdown);
} }
} }
@ -418,7 +424,7 @@ class DocumentationParser
/** /**
* Resolves all relative links within markdown. * Resolves all relative links within markdown.
* *
* @param String $md Markdown content * @param String $md Markdown content
* @param DocumentationPage $page * @param DocumentationPage $page
* *
* @return String Markdown * @return String Markdown
@ -524,11 +530,13 @@ class DocumentationParser
public static function retrieve_meta_data(DocumentationPage &$page) public static function retrieve_meta_data(DocumentationPage &$page)
{ {
if ($md = $page->getMarkdown()) { if ($md = $page->getMarkdown()) {
$matches = preg_match_all('/ $matches = preg_match_all(
'/
(?<key>[A-Za-z0-9_-]+): (?<key>[A-Za-z0-9_-]+):
\s* \s*
(?<value>.*) (?<value>.*)
/x', $md, $meta); /x', $md, $meta
);
if ($matches) { if ($matches) {
foreach ($meta['key'] as $index => $key) { foreach ($meta['key'] as $index => $key) {

View File

@ -21,7 +21,7 @@ class DocumentationPermalinks
* *
* <code> * <code>
* DocumentationPermalinks::add(array( * DocumentationPermalinks::add(array(
* 'debugging' => 'current/en/sapphire/topics/debugging' * 'debugging' => 'current/en/sapphire/topics/debugging'
* )); * ));
* </code> * </code>
* *

View File

@ -127,7 +127,7 @@ class DocumentationSearch
* Folder name for indexes (in the temp folder). * Folder name for indexes (in the temp folder).
* *
* @config * @config
* @var string * @var string
*/ */
private static $index_location; private static $index_location;
@ -240,7 +240,8 @@ class DocumentationSearch
$content = $hit->content; $content = $hit->content;
$obj = new ArrayData(array( $obj = new ArrayData(
array(
'Title' => DBField::create_field('Varchar', $doc->getFieldValue('Title')), 'Title' => DBField::create_field('Varchar', $doc->getFieldValue('Title')),
'BreadcrumbTitle' => DBField::create_field('HTMLText', $doc->getFieldValue('BreadcrumbTitle')), 'BreadcrumbTitle' => DBField::create_field('HTMLText', $doc->getFieldValue('BreadcrumbTitle')),
'Link' => DBField::create_field('Varchar', $doc->getFieldValue('Link')), 'Link' => DBField::create_field('Varchar', $doc->getFieldValue('Link')),
@ -251,7 +252,8 @@ class DocumentationSearch
'Score' => $hit->score, 'Score' => $hit->score,
'Number' => $k + 1, 'Number' => $k + 1,
'ID' => md5($doc->getFieldValue('Link')) 'ID' => md5($doc->getFieldValue('Link'))
)); )
);
$results->push($obj); $results->push($obj);
} }
@ -267,13 +269,15 @@ class DocumentationSearch
// Pagination links // Pagination links
if ($currentPage > 1) { if ($currentPage > 1) {
$data['PrevUrl'] = DBField::create_field('Text', $data['PrevUrl'] = DBField::create_field(
'Text',
$this->buildQueryUrl(array('start' => ($currentPage - 2) * $pageLength)) $this->buildQueryUrl(array('start' => ($currentPage - 2) * $pageLength))
); );
} }
if ($currentPage < $totalPages) { if ($currentPage < $totalPages) {
$data['NextUrl'] = DBField::create_field('Text', $data['NextUrl'] = DBField::create_field(
'Text',
$this->buildQueryUrl(array('start' => $currentPage * $pageLength)) $this->buildQueryUrl(array('start' => $currentPage * $pageLength))
); );
} }
@ -284,9 +288,11 @@ class DocumentationSearch
$obj = new DataObject(); $obj = new DataObject();
$obj->IsEllipsis = false; $obj->IsEllipsis = false;
$obj->PageNumber = $i; $obj->PageNumber = $i;
$obj->Link = $this->buildQueryUrl(array( $obj->Link = $this->buildQueryUrl(
array(
'start' => ($i - 1) * $pageLength 'start' => ($i - 1) * $pageLength
)); )
);
$obj->Current = false; $obj->Current = false;
if ($i == $currentPage) { if ($i == $currentPage) {

View File

@ -41,8 +41,10 @@ class DocumentationOpenSearchController extends Controller
return $this->customise( return $this->customise(
new ArrayData($data) new ArrayData($data)
)->renderWith(array( )->renderWith(
array(
'OpenSearchDescription' 'OpenSearchDescription'
)); )
);
} }
} }

View File

@ -105,14 +105,16 @@ class DocumentationViewer extends Controller implements PermissionProvider
Requirements::javascript('https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'); Requirements::javascript('https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js');
Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js'); Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js');
Requirements::combine_files('docs.css', array( Requirements::combine_files(
'docs.css', array(
DOCSVIEWER_DIR .'/css/normalize.css', DOCSVIEWER_DIR .'/css/normalize.css',
DOCSVIEWER_DIR .'/css/utilities.css', DOCSVIEWER_DIR .'/css/utilities.css',
DOCSVIEWER_DIR .'/css/typography.css', DOCSVIEWER_DIR .'/css/typography.css',
DOCSVIEWER_DIR .'/css/forms.css', DOCSVIEWER_DIR .'/css/forms.css',
DOCSVIEWER_DIR .'/css/layout.css', DOCSVIEWER_DIR .'/css/layout.css',
DOCSVIEWER_DIR .'/css/small.css' DOCSVIEWER_DIR .'/css/small.css'
)); )
);
} }
} }
@ -122,7 +124,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
* @return array * @return array
*/ */
public function providePermissions() { public function providePermissions()
{
return array( return array(
'CMS_VIEW_DEVDOCS' => array( 'CMS_VIEW_DEVDOCS' => array(
'name' => 'View Site Documentation', 'name' => 'View Site Documentation',
@ -270,10 +273,12 @@ class DocumentationViewer extends Controller implements PermissionProvider
$this->init(); $this->init();
$type = get_class($this->record); $type = get_class($this->record);
$body = $this->renderWith(array( $body = $this->renderWith(
array(
"DocumentationViewer_{$type}", "DocumentationViewer_{$type}",
"DocumentationViewer" "DocumentationViewer"
)); )
);
return new SS_HTTPResponse($body, 200); return new SS_HTTPResponse($body, 200);
} elseif ($redirect = $this->getManifest()->getRedirect($url)) { } elseif ($redirect = $this->getManifest()->getRedirect($url)) {
@ -281,10 +286,12 @@ class DocumentationViewer extends Controller implements PermissionProvider
$to = Controller::join_links(Director::baseURL(), $base, $redirect); $to = Controller::join_links(Director::baseURL(), $base, $redirect);
return $response->redirect($to, 301); return $response->redirect($to, 301);
} elseif (!$url || $url == $lang) { } elseif (!$url || $url == $lang) {
$body = $this->renderWith(array( $body = $this->renderWith(
array(
"DocumentationViewer_DocumentationFolder", "DocumentationViewer_DocumentationFolder",
"DocumentationViewer" "DocumentationViewer"
)); )
);
return new SS_HTTPResponse($body, 200); return new SS_HTTPResponse($body, 200);
} }
@ -294,7 +301,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
} }
/** /**
* @param int $status * @param int $status
* @param string $message * @param string $message
* *
* @return SS_HTTPResponse * @return SS_HTTPResponse
@ -304,9 +311,13 @@ class DocumentationViewer extends Controller implements PermissionProvider
$this->init(); $this->init();
$class = get_class($this); $class = get_class($this);
$body = $this->customise(new ArrayData(array( $body = $this->customise(
'Message' => $message new ArrayData(
)))->renderWith(array("{$class}_error", $class)); array(
'Message' => $message
)
)
)->renderWith(array("{$class}_error", $class));
return new SS_HTTPResponse($body, $status); return new SS_HTTPResponse($body, $status);
} }
@ -386,13 +397,17 @@ class DocumentationViewer extends Controller implements PermissionProvider
$link = $entity->Link(); $link = $entity->Link();
$output->push(new ArrayData(array( $output->push(
'Title' => $entity->getTitle(), new ArrayData(
'Link' => $link, array(
'LinkingMode' => $mode, 'Title' => $entity->getTitle(),
'DefaultEntity' => $entity->getIsDefaultEntity(), 'Link' => $link,
'Children' => $children 'LinkingMode' => $mode,
))); 'DefaultEntity' => $entity->getIsDefaultEntity(),
'Children' => $children
)
)
);
} }
return $output; return $output;
@ -449,9 +464,13 @@ class DocumentationViewer extends Controller implements PermissionProvider
} }
} }
return $this->customise(new ArrayData(array( return $this->customise(
'Children' => $children new ArrayData(
)))->renderWith('Includes/DocumentationPages'); array(
'Children' => $children
)
)
)->renderWith('Includes/DocumentationPages');
} }
/** /**
@ -565,11 +584,15 @@ class DocumentationViewer extends Controller implements PermissionProvider
$first = strtoupper(trim(substr($page['title'], 0, 1))); $first = strtoupper(trim(substr($page['title'], 0, 1)));
if ($first) { if ($first) {
$output->push(new ArrayData(array( $output->push(
'Link' => Controller::join_links($baseLink, $url), new ArrayData(
'Title' => $page['title'], array(
'FirstLetter' => $first 'Link' => Controller::join_links($baseLink, $url),
))); 'Title' => $page['title'],
'FirstLetter' => $first
)
)
);
} }
} }
@ -596,18 +619,18 @@ class DocumentationViewer extends Controller implements PermissionProvider
* to jump into editing the documentation. * to jump into editing the documentation.
* *
* Some variables are replaced: * Some variables are replaced:
* - %version% * - %version%
* - %entity% * - %entity%
* - %path% * - %path%
* - %lang% * - %lang%
* *
* For example to provide an edit link to the framework module in github: * For example to provide an edit link to the framework module in github:
* *
* <code> * <code>
* DocumentationViewer::set_edit_link( * DocumentationViewer::set_edit_link(
* 'framework', * 'framework',
* 'https://github.com/silverstripe/%entity%/edit/%version%/docs/%lang%/%path%', * 'https://github.com/silverstripe/%entity%/edit/%version%/docs/%lang%/%path%',
* $opts * $opts
* )); * ));
* </code> * </code>
* *
@ -635,8 +658,6 @@ class DocumentationViewer extends Controller implements PermissionProvider
if ($page) { if ($page) {
$entity = $page->getEntity(); $entity = $page->getEntity();
if ($entity && isset(self::$edit_links[strtolower($entity->title)])) { if ($entity && isset(self::$edit_links[strtolower($entity->title)])) {
// build the edit link, using the version defined // build the edit link, using the version defined
@ -648,7 +669,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
} }
if ($version == "trunk" && (isset($url['options']['rewritetrunktomaster']))) { if ($version == 'trunk' && (isset($url['options']['rewritetrunktomaster']))) {
if ($url['options']['rewritetrunktomaster']) { if ($url['options']['rewritetrunktomaster']) {
$version = "master"; $version = "master";
} }
@ -662,7 +683,6 @@ class DocumentationViewer extends Controller implements PermissionProvider
$version, $version,
ltrim($page->getRelativePath(), '/') ltrim($page->getRelativePath(), '/')
), ),
$url['url'] $url['url']
); );
} }
@ -677,13 +697,14 @@ class DocumentationViewer extends Controller implements PermissionProvider
* Returns the next page. Either retrieves the sibling of the current page * Returns the next page. Either retrieves the sibling of the current page
* or return the next sibling of the parent page. * or return the next sibling of the parent page.
* *
* @return DocumentationPage * @return DocumentationPage|null
*/ */
public function getNextPage() public function getNextPage()
{ {
return ($this->record) return ($this->record)
? $this->getManifest()->getNextPage( ? $this->getManifest()->getNextPage(
$this->record->getPath(), $this->getEntity()->getPath()) $this->record->getPath(), $this->getEntity()->getPath()
)
: null; : null;
} }
@ -691,18 +712,19 @@ class DocumentationViewer extends Controller implements PermissionProvider
* Returns the previous page. Either returns the previous sibling or the * Returns the previous page. Either returns the previous sibling or the
* parent of this page * parent of this page
* *
* @return DocumentationPage * @return DocumentationPage|null
*/ */
public function getPreviousPage() public function getPreviousPage()
{ {
return ($this->record) return ($this->record)
? $this->getManifest()->getPreviousPage( ? $this->getManifest()->getPreviousPage(
$this->record->getPath(), $this->getEntity()->getPath()) $this->record->getPath(), $this->getEntity()->getPath()
)
: null; : null;
} }
/** /**
* @return string * @return string|void
*/ */
public function getGoogleAnalyticsCode() public function getGoogleAnalyticsCode()
{ {
@ -721,6 +743,9 @@ class DocumentationViewer extends Controller implements PermissionProvider
return $this->config()->get('documentation_title'); return $this->config()->get('documentation_title');
} }
/**
* @return string
*/
public function getDocumentationBaseHref() public function getDocumentationBaseHref()
{ {
return Config::inst()->get('DocumentationViewer', 'link_base'); return Config::inst()->get('DocumentationViewer', 'link_base');
@ -728,8 +753,9 @@ class DocumentationViewer extends Controller implements PermissionProvider
/** /**
* Gets whether there is a default entity or not * Gets whether there is a default entity or not
*
* @return boolean * @return boolean
* @see DocumentationManifest::getHasDefaultEntity() * @see DocumentationManifest::getHasDefaultEntity()
*/ */
public function getHasDefaultEntity() public function getHasDefaultEntity()
{ {

View File

@ -10,7 +10,7 @@
* <code> * <code>
* StaticExporter: * StaticExporter:
* extensions: * extensions:
* - DocumentationStaticPublisherExtension * - DocumentationStaticPublisherExtension
* </code> * </code>
* *
* If you don't plan on using static publisher for anything else and you have * If you don't plan on using static publisher for anything else and you have

View File

@ -1,14 +1,15 @@
<?php <?php
/** /**
* Check to see if the currently accessed version is out of date or perhaps a * @package docsviewer
* future version rather than the stable edition.
*
* @return false|ArrayData
*/ */
class DocumentationViewerVersionWarning extends Extension class DocumentationViewerVersionWarning extends Extension
{ {
/**
* Check to see if the currently accessed version is out of date or perhaps a
* future version rather than the stable edition.
*
* @return false|ArrayData
*/
public function VersionWarning() public function VersionWarning()
{ {
$page = $this->owner->getPage(); $page = $this->owner->getPage();
@ -32,16 +33,24 @@ class DocumentationViewerVersionWarning extends Extension
$stable = $this->owner->getManifest()->getStableVersion($entity); $stable = $this->owner->getManifest()->getStableVersion($entity);
$compare = $entity->compare($stable); $compare = $entity->compare($stable);
if ($entity->getVersion() == "master" || $compare > 0) { if ($entity->getVersion() == 'master' || $compare > 0) {
return $this->owner->customise(new ArrayData(array( return $this->owner->customise(
'FutureRelease' => true, new ArrayData(
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion()) array(
))); 'FutureRelease' => true,
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion())
)
)
);
} else { } else {
return $this->owner->customise(new ArrayData(array( return $this->owner->customise(
'OutdatedRelease' => true, new ArrayData(
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion()) array(
))); 'OutdatedRelease' => true,
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion())
)
)
);
} }
return false; return false;

View File

@ -11,8 +11,7 @@
* entity can have a language attached to it. So for an instance with en, de and * entity can have a language attached to it. So for an instance with en, de and
* fr documentation you may have three {@link DocumentationEntities} registered. * fr documentation you may have three {@link DocumentationEntities} registered.
* *
* * @package docsviewer
* @package docsviewer
* @subpackage models * @subpackage models
*/ */
@ -35,6 +34,13 @@ class DocumentationEntity extends ViewableData
*/ */
protected $title; protected $title;
/**
* Label for this version
*
* @var string
*/
protected $versionTitle;
/** /**
* If the system is setup to only document one entity then you may only * If the system is setup to only document one entity then you may only
* want to show a single entity in the URL and the sidebar. Set this when * want to show a single entity in the URL and the sidebar. Set this when
@ -45,6 +51,13 @@ class DocumentationEntity extends ViewableData
*/ */
protected $defaultEntity; protected $defaultEntity;
/**
* Set if this version is archived
*
* @var bool
*/
protected $archived = false;
/** /**
* @var mixed * @var mixed
*/ */
@ -77,10 +90,11 @@ class DocumentationEntity extends ViewableData
protected $language; protected $language;
/** /**
* * @param string $key Key of module
*/ */
public function __construct($key) public function __construct($key)
{ {
parent::__construct();
$this->key = DocumentationHelper::clean_page_url($key); $this->key = DocumentationHelper::clean_page_url($key);
} }
@ -101,7 +115,7 @@ class DocumentationEntity extends ViewableData
/** /**
* @param string $title * @param string $title
* @return this * @return $this
*/ */
public function setTitle($title) public function setTitle($title)
{ {
@ -115,7 +129,7 @@ class DocumentationEntity extends ViewableData
* *
* Includes the version information * Includes the version information
* *
* @param boolean $short If true, will attempt to return a short version of the url * @param boolean $short If true, will attempt to return a short version of the url
* This might omit the version number if this is the default version. * This might omit the version number if this is the default version.
* @return string * @return string
*/ */
@ -172,12 +186,12 @@ class DocumentationEntity extends ViewableData
} }
/** /**
* @param boolean $bool * @param bool $bool
* @return $this
*/ */
public function setIsDefaultEntity($bool) public function setIsDefaultEntity($bool)
{ {
$this->defaultEntity = $bool; $this->defaultEntity = $bool;
return $this; return $this;
} }
@ -208,7 +222,7 @@ class DocumentationEntity extends ViewableData
/** /**
* @param string * @param string
* *
* @return this * @return $this
*/ */
public function setLanguage($language) public function setLanguage($language)
{ {
@ -219,6 +233,7 @@ class DocumentationEntity extends ViewableData
/** /**
* @param string * @param string
* @return $this
*/ */
public function setVersion($version) public function setVersion($version)
{ {
@ -235,8 +250,51 @@ class DocumentationEntity extends ViewableData
return $this->version; return $this->version;
} }
/**
* Get the version for this title
*
* @return string
*/
public function getVersionTitle()
{
return $this->versionTitle;
}
/**
* Sets the title for this version
*
* @param string $title
* @return $this
*/
public function setVersionTitle($title)
{
$this->versionTitle = $title;
return $this;
}
/**
* Set if this is archived
*
* @param bool $archived
* @return $this
*/
public function setIsArchived($archived)
{
$this->archived = $archived;
return $this;
}
/**
* @return bool
*/
public function getIsArchived()
{
return $this->archived;
}
/** /**
* @param string * @param string
* @return $this
*/ */
public function setBranch($branch) public function setBranch($branch)
{ {
@ -262,9 +320,8 @@ class DocumentationEntity extends ViewableData
} }
/** /**
* @param string $path * @param string $path
* * @return $this
* @return this
*/ */
public function setPath($path) public function setPath($path)
{ {
@ -274,7 +331,8 @@ class DocumentationEntity extends ViewableData
} }
/** /**
* @param boolean * @param bool
* @return $this
*/ */
public function setIsStable($stable) public function setIsStable($stable)
{ {
@ -291,19 +349,30 @@ class DocumentationEntity extends ViewableData
return $this->stable; return $this->stable;
} }
/** /**
* Returns an integer value based on if a given version is the latest * Returns an integer value based on if a given version is the latest
* version. Will return -1 for if the version is older, 0 if versions are * version. Will return -1 for if the version is older, 0 if versions are
* the same and 1 if the version is greater than. * the same and 1 if the version is greater than.
* *
* @param string $version * @param DocumentationEntity $other
* @return int * @return int
*/ */
public function compare(DocumentationEntity $other) public function compare(DocumentationEntity $other)
{ {
return version_compare($this->getVersion(), $other->getVersion()); $v1 = $this->getVersion();
$v2 = $other->getVersion();
// Normalise versions prior to comparison
$dots = substr_count($v1, '.') - substr_count($v2, '.');
while ($dots > 0) {
$dots--;
$v2 .= '.99999';
}
while ($dots < 0) {
$dots++;
$v1 .= '.99999';
}
return version_compare($v1, $v2);
} }
/** /**
@ -312,10 +381,10 @@ class DocumentationEntity extends ViewableData
public function toMap() public function toMap()
{ {
return array( return array(
'Key' => $this->key, 'Key' => $this->key,
'Path' => $this->getPath(), 'Path' => $this->getPath(),
'Version' => $this->getVersion(), 'Version' => $this->getVersion(),
'Branch' => $this->getBranch(), 'Branch' => $this->getBranch(),
'IsStable' => $this->getIsStable(), 'IsStable' => $this->getIsStable(),
'Language' => $this->getLanguage() 'Language' => $this->getLanguage()
); );

View File

@ -5,7 +5,7 @@
* *
* Maps to a folder on the file system. * Maps to a folder on the file system.
* *
* @package docsviewer * @package docsviewer
* @subpackage model * @subpackage model
*/ */
class DocumentationFolder extends DocumentationPage class DocumentationFolder extends DocumentationPage

View File

@ -7,7 +7,7 @@
* not always be the file name. If the file contains meta data with a nicer URL * not always be the file name. If the file contains meta data with a nicer URL
* sthen it will use that. * sthen it will use that.
* *
* @package docsviewer * @package docsviewer
* @subpackage model * @subpackage model
*/ */
class DocumentationPage extends ViewableData class DocumentationPage extends ViewableData
@ -38,8 +38,8 @@ class DocumentationPage extends ViewableData
/** /**
* @param DocumentationEntity $entity * @param DocumentationEntity $entity
* @param string $filename * @param string $filename
* @param string $path * @param string $path
*/ */
public function __construct(DocumentationEntity $entity, $filename, $path) public function __construct(DocumentationEntity $entity, $filename, $path)
{ {
@ -71,15 +71,21 @@ class DocumentationPage extends ViewableData
// add the module to the breadcrumb trail. // add the module to the breadcrumb trail.
$pathParts[] = $this->entity->getTitle(); $pathParts[] = $this->entity->getTitle();
$titleParts = array_map(array( $titleParts = array_map(
'DocumentationHelper', 'clean_page_name' array(
), $pathParts); 'DocumentationHelper',
'clean_page_name'
),
$pathParts
);
$titleParts = array_filter($titleParts, function ($val) { $titleParts = array_filter(
if ($val) { $titleParts, function ($val) {
return $val; if ($val) {
return $val;
}
} }
}); );
if ($this->getTitle()) { if ($this->getTitle()) {
array_unshift($titleParts, $this->getTitle()); array_unshift($titleParts, $this->getTitle());
@ -107,7 +113,7 @@ class DocumentationPage extends ViewableData
$page = DocumentationHelper::clean_page_name($this->filename); $page = DocumentationHelper::clean_page_name($this->filename);
if ($page == "Index") { if ($page == 'Index') {
return $this->getTitleFromFolder(); return $this->getTitleFromFolder();
} }
@ -146,7 +152,7 @@ class DocumentationPage extends ViewableData
* *
* @param boolean $removeMetaData * @param boolean $removeMetaData
* *
* @return string * @return string|false
*/ */
public function getMarkdown($removeMetaData = false) public function getMarkdown($removeMetaData = false)
{ {
@ -171,6 +177,9 @@ class DocumentationPage extends ViewableData
$this->$key = $value; $this->$key = $value;
} }
/**
* @return string
*/
public function getIntroduction() public function getIntroduction()
{ {
if (!$this->read) { if (!$this->read) {
@ -208,9 +217,15 @@ class DocumentationPage extends ViewableData
{ {
$path = $this->getRelativePath(); $path = $this->getRelativePath();
$url = explode('/', $path); $url = explode('/', $path);
$url = implode('/', array_map(function ($a) { $url = implode(
return DocumentationHelper::clean_page_url($a); '/',
}, $url)); array_map(
function ($a) {
return DocumentationHelper::clean_page_url($a);
},
$url
)
);
$url = trim($url, '/') . '/'; $url = trim($url, '/') . '/';
@ -240,16 +255,18 @@ class DocumentationPage extends ViewableData
* Returns the URL that will be required for the user to hit to view the * Returns the URL that will be required for the user to hit to view the
* given document base name. * given document base name.
* *
* @param boolean $short If true, will attempt to return a short version of the url * @param boolean $short If true, will attempt to return a short version of the url
* This might omit the version number if this is the default version. * This might omit the version number if this is the default version.
* @return string * @return string
*/ */
public function Link($short = false) public function Link($short = false)
{ {
return ltrim(Controller::join_links( return ltrim(
$this->entity->Link($short), Controller::join_links(
$this->getRelativeLink() $this->entity->Link($short),
), '/'); $this->getRelativeLink()
), '/'
);
} }
/** /**
@ -257,7 +274,7 @@ class DocumentationPage extends ViewableData
* block on request * block on request
* *
* @param DocumentationPage $md * @param DocumentationPage $md
* @param bool $remove * @param bool $remove
*/ */
public function populateMetaDataFromText(&$md, $removeMetaData = false) public function populateMetaDataFromText(&$md, $removeMetaData = false)
{ {
@ -297,6 +314,9 @@ class DocumentationPage extends ViewableData
return $this->entity->getVersion(); return $this->entity->getVersion();
} }
/**
* @return string
*/
public function __toString() public function __toString()
{ {
return sprintf(get_class($this) .': %s)', $this->getPath()); return sprintf(get_class($this) .': %s)', $this->getPath());

View File

@ -3,19 +3,22 @@
/** /**
* Check status of sources dirs * Check status of sources dirs
*/ */
class CheckDocsSourcesTask extends BuildTask { class CheckDocsSourcesTask extends BuildTask
{
protected $errors = 0; protected $errors = 0;
protected $description = "Check validity of all docs source files registered"; protected $description = "Check validity of all docs source files registered";
public function start() { public function start()
{
if(!Director::is_cli()) { if(!Director::is_cli()) {
echo "<ul>"; echo "<ul>";
} }
} }
public function end() { public function end()
{
if(Director::is_cli()) { if(Director::is_cli()) {
echo "\nTotal errors: {$this->errors}\n"; echo "\nTotal errors: {$this->errors}\n";
} else { } else {
@ -24,7 +27,8 @@ class CheckDocsSourcesTask extends BuildTask {
} }
} }
public function showError($error) { public function showError($error)
{
$this->errors++; $this->errors++;
if(Director::is_cli()) { if(Director::is_cli()) {
echo "\n$error"; echo "\n$error";
@ -36,7 +40,7 @@ class CheckDocsSourcesTask extends BuildTask {
/** /**
* Validate all source files * Validate all source files
* *
* @param SS_HTTPRequest $request * @param SS_HTTPRequest $request
* @throws Exception * @throws Exception
*/ */
public function run($request) public function run($request)

View File

@ -5,7 +5,7 @@
* *
* For the hourly cron rebuild use RebuildLuceneDocusIndex_Hourly * For the hourly cron rebuild use RebuildLuceneDocusIndex_Hourly
* *
* @package docsviewer * @package docsviewer
* @subpackage tasks * @subpackage tasks
*/ */
@ -23,7 +23,7 @@ class RebuildLuceneDocsIndex extends BuildTask
public function rebuildIndexes($quiet = false) public function rebuildIndexes($quiet = false)
{ {
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
ini_set("memory_limit", -1); ini_set("memory_limit", -1);
ini_set('max_execution_time', 0); ini_set('max_execution_time', 0);
@ -85,21 +85,29 @@ class RebuildLuceneDocsIndex extends BuildTask
$doc->addField($titleField = Zend_Search_Lucene_Field::Text('Title', $page->getTitle())); $doc->addField($titleField = Zend_Search_Lucene_Field::Text('Title', $page->getTitle()));
$doc->addField($breadcrumbField = Zend_Search_Lucene_Field::Text('BreadcrumbTitle', $page->getBreadcrumbTitle())); $doc->addField($breadcrumbField = Zend_Search_Lucene_Field::Text('BreadcrumbTitle', $page->getBreadcrumbTitle()));
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
'Version', $page->getEntity()->getVersion() Zend_Search_Lucene_Field::Keyword(
)); 'Version', $page->getEntity()->getVersion()
)
);
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
'Language', $page->getEntity()->getLanguage() Zend_Search_Lucene_Field::Keyword(
)); 'Language', $page->getEntity()->getLanguage()
)
);
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
'Entity', $page->getEntity() Zend_Search_Lucene_Field::Keyword(
)); 'Entity', $page->getEntity()
)
);
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
'Link', $page->Link() Zend_Search_Lucene_Field::Keyword(
)); 'Link', $page->Link()
)
);
// custom boosts // custom boosts
$titleField->boost = 3; $titleField->boost = 3;

View File

@ -1,38 +1,38 @@
fieldset { fieldset {
border: none; border: none;
margin: 0; margin: 0;
padding: 0 0 5px 0; padding: 0 0 5px 0;
} }
#DocumentationAdvancedSearchForm_AdvancedSearchForm_q { #DocumentationAdvancedSearchForm_AdvancedSearchForm_q {
width: 100%; width: 100%;
font-size: 15px; font-size: 15px;
padding: 10px 10px; padding: 10px 10px;
} }
#DocumentationAdvancedSearchForm_AdvancedSearchForm #q { #DocumentationAdvancedSearchForm_AdvancedSearchForm #q {
width: 55%; width: 55%;
padding-right: 2%; padding-right: 2%;
float: left; float: left;
} }
#DocumentationAdvancedSearchForm_AdvancedSearchForm #Entities { #DocumentationAdvancedSearchForm_AdvancedSearchForm #Entities {
width: 25%; width: 25%;
padding-right: 2%; padding-right: 2%;
float: left; float: left;
} }
#DocumentationAdvancedSearchForm_AdvancedSearchForm #Versions { #DocumentationAdvancedSearchForm_AdvancedSearchForm #Versions {
width: auto; width: auto;
float: left; float: left;
margin-top: 12px; margin-top: 12px;
} }
.optionset ul { .optionset ul {
margin: 0; margin: 0;
} }
.optionset li { .optionset li {
list-style: none; list-style: none;
float: left; float: left;
padding-right: 12px; padding-right: 12px;
} }

View File

@ -1,11 +1,11 @@
html { html {
background: #fff; background: #fff;
font: 15px/1.5 "proxima-nova", "Helvetica Neue", Helvetica, Arial, sans-serif; font: 15px/1.5 "proxima-nova", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #586667; color: #586667;
padding-bottom: 40px; padding-bottom: 40px;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
box-sizing: border-box; box-sizing: border-box;
overflow-y: scroll; overflow-y: scroll;
} }
*, *:before, *:after { *, *:before, *:after {
@ -14,406 +14,406 @@ html {
/*! container */ /*! container */
.wrapper { .wrapper {
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
padding-left: 15px; padding-left: 15px;
padding-right: 15px; padding-right: 15px;
} }
.introduction {} .introduction {}
.introduction h1 { .introduction h1 {
margin-bottom: 20px; margin-bottom: 20px;
} }
.introduction p { .introduction p {
font-size: 20px; font-size: 20px;
margin-bottom: 10px; margin-bottom: 10px;
max-width: 80%; max-width: 80%;
} }
.no-box { .no-box {
padding: 15px; padding: 15px;
} }
/*! main content column */ /*! main content column */
#content { #content {
float: right; float: right;
width: 72%; width: 72%;
} }
#content .box { #content .box {
padding: 30px 5px; padding: 30px 5px;
} }
/*! sidebar */ /*! sidebar */
#sidebar { #sidebar {
float: left; float: left;
padding-top:20px; padding-top:20px;
} }
#sidebar .nav, #sidebar .nav,
#sidebar .minor-nav { #sidebar .minor-nav {
margin: 0; margin: 0;
padding: 0; padding: 0;
list-style: none; list-style: none;
} }
#sidebar .nav { #sidebar .nav {
font-size: 16px; font-size: 16px;
} }
#sidebar .nav .top { #sidebar .nav .top {
width: 100%; width: 100%;
display: block; display: block;
line-height: 15px; line-height: 15px;
color: #808c8d; color: #808c8d;
padding: 15px 15px 14px; padding: 15px 15px 14px;
text-transform: uppercase; text-transform: uppercase;
} }
#sidebar .nav .current .top { #sidebar .nav .current .top {
color: #1389CE; color: #1389CE;
font-weight: 700; font-weight: 700;
} }
#sidebar .nav a { #sidebar .nav a {
display:block; display:block;
padding-top:7px; padding-top:7px;
padding-bottom:7px; padding-bottom:7px;
padding-right:12px; padding-right:12px;
} }
/* Sidebar hover states */ /* Sidebar hover states */
#sidebar .nav a:hover, #sidebar .nav a:hover,
#sidebar .nav a.top:hover, #sidebar .nav a.top:hover,
#sidebar .nav .section ul li .section:hover, #sidebar .nav .section ul li .section:hover,
#sidebar .nav a.current:hover, #sidebar .nav a.current:hover,
/* Sidebar focus states */ /* Sidebar focus states */
#sidebar .nav a:focus, #sidebar .nav a:focus,
#sidebar .nav a.top:focus, #sidebar .nav a.top:focus,
#sidebar .nav .section ul li .section:focus, #sidebar .nav .section ul li .section:focus,
#sidebar .nav a.current:focus { #sidebar .nav a.current:focus {
background-color: #1389ce; background-color: #1389ce;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
-webkit-transition: all 500ms ease; -webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease; -moz-transition: all 500ms ease;
transition: all 500ms ease; transition: all 500ms ease;
} }
#sidebar .nav .section .top { #sidebar .nav .section .top {
border: none; border: none;
color: #1389CE; color: #1389CE;
} }
#sidebar li { #sidebar li {
margin: 0; margin: 0;
list-style:none; list-style:none;
} }
#sidebar li a.current { #sidebar li a.current {
color:#fff; color:#fff;
} }
#sidebar .nav > li {} #sidebar .nav > li {}
#sidebar .nav .section ul, #sidebar .nav .section ul,
#sidebar .nav .current ul { #sidebar .nav .current ul {
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
margin: 0; margin: 0;
padding:0; padding:0;
} }
#sidebar .nav .section ul li a, #sidebar .nav .section ul li a,
#sidebar .nav .current ul li a { #sidebar .nav .current ul li a {
padding-left:30px; padding-left:30px;
} }
#sidebar .nav .section ul li a.section { #sidebar .nav .section ul li a.section {
color: #1389CE; color: #1389CE;
} }
#sidebar .nav .section ul li ul li a, #sidebar .nav .section ul li ul li a,
#sidebar .nav .current ul li ul li a { #sidebar .nav .current ul li ul li a {
padding-left:48px; padding-left:48px;
font-size:14px; font-size:14px;
} }
#sidebar .nav a.current { #sidebar .nav a.current {
color: #1389CE; color: #1389CE;
font-weight: 700; font-weight: 700;
} }
#sidebar .minor-nav a { #sidebar .minor-nav a {
color: #181C17; color: #181C17;
opacity: 0.4; opacity: 0.4;
filter: alpha(opacity=40); filter: alpha(opacity=40);
} }
#sidebar .search {} #sidebar .search {}
#sidebar .search fieldset { #sidebar .search fieldset {
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
padding: 15px 10px 14px; padding: 15px 10px 14px;
} }
#sidebar .search label, #sidebar .search label,
#sidebar .search .Actions { #sidebar .search .Actions {
display: none; display: none;
} }
#sidebar .search input { #sidebar .search input {
width: 100%; width: 100%;
outline: none; outline: none;
border-radius: 2px; border-radius: 2px;
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 9px; padding: 9px;
} }
#sidebar .search input:focus { #sidebar .search input:focus {
border-color: #1389ce; border-color: #1389ce;
} }
#layout { #layout {
padding-bottom: 20px; padding-bottom: 20px;
position:relative; position:relative;
} }
#masthead { #masthead {
padding: 50px 0; padding: 50px 0;
background:#f6f7f8; background:#f6f7f8;
position:relative; position:relative;
} }
#masthead.has_versions { #masthead.has_versions {
padding-bottom: 0; padding-bottom: 0;
} }
#masthead .wrapper { #masthead .wrapper {
overflow: hidden; overflow: hidden;
} }
.versions { .versions {
float: right; float: right;
} }
.versions p { .versions p {
margin: 0 0 5px; margin: 0 0 5px;
font-size: 12px; font-size: 12px;
} }
.versions ul { .versions ul {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.versions li { .versions li {
list-style: none; list-style: none;
display: block; display: block;
float: left; float: left;
margin: 0 0 0 5px; margin: 0 0 0 5px;
} }
.versions li a { .versions li a {
padding: 10px 15px; padding: 10px 15px;
display: block; display: block;
} }
.versions .current { .versions .current {
background: #fff; background: #fff;
} }
/*! language */ /*! language */
#language {} #language {}
#language label { #language label {
float: left; float: left;
width: 830px; width: 830px;
line-height: 19px; line-height: 19px;
text-align: right; text-align: right;
font-size: 11px; font-size: 11px;
color: #999; color: #999;
} }
#language select { #language select {
float: right; float: right;
width: 120px; width: 120px;
} }
#language input.action { #language input.action {
float: right; float: right;
margin-top: 4px; margin-top: 4px;
} }
/* Header */ /* Header */
#header { #header {
padding: 0 0 14px 0; padding: 0 0 14px 0;
overflow: hidden; overflow: hidden;
} }
#header h1 { #header h1 {
margin: 0; margin: 0;
line-height: 38px; line-height: 38px;
float: left; float: left;
} }
#header h1 a { #header h1 a {
text-decoration: none; text-decoration: none;
font-size: 22px; font-size: 22px;
color: #0973A6; color: #0973A6;
letter-spacing: -1px; letter-spacing: -1px;
} }
#header .logo { #header .logo {
background: #fff url(../../docsviewer/images/logo.jpg) no-repeat bottom left; background: #fff url(../../docsviewer/images/logo.jpg) no-repeat bottom left;
height: 36px; width: 140px; height: 36px; width: 140px;
display: inline-block; display: inline-block;
} }
/* Search Results */ /* Search Results */
#search-results {} #search-results {}
#search-results li { #search-results li {
list-style: none; list-style: none;
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
padding: 0 0 19px 0; padding: 0 0 19px 0;
margin: 0 0 20px 0; margin: 0 0 20px 0;
background: none; background: none;
} }
/* Comments */ /* Comments */
#comments { #comments {
clear: both; clear: both;
padding-top: 18px; padding-top: 18px;
} }
#comments .notice { #comments .notice {
font-size: 14px; font-size: 14px;
} }
/* Footer */ /* Footer */
#footer { #footer {
margin: 20px auto; margin: 20px auto;
padding: 0 30px; padding: 0 30px;
} }
#footer p { #footer p {
color: #798D85; color: #798D85;
} }
#footer p a { #footer p a {
color: #798D85; color: #798D85;
} }
/*! Pagination */ /*! Pagination */
#page-numbers span, #page-numbers span,
#page-numbers a { #page-numbers a {
padding: 3px 5px; padding: 3px 5px;
} }
#page-numbers span {} #page-numbers span {}
#page-numbers a:hover { #page-numbers a:hover {
color: #FFFFFF; color: #FFFFFF;
background-color: #005F99; background-color: #005F99;
} }
.pagination { .pagination {
margin: 27px 0; margin: 27px 0;
} }
.pagination li { .pagination li {
display: inline; display: inline;
background: none; background: none;
padding: 0 4px 0 0; padding: 0 4px 0 0;
} }
.pagination li strong, .pagination li a { .pagination li strong, .pagination li a {
padding: 1px 4px; padding: 1px 4px;
} }
.pagination li.active strong { .pagination li.active strong {
background-color: #c3dbd4; background-color: #c3dbd4;
} }
.pagination li a:hover { .pagination li a:hover {
background-color: #0973A6; background-color: #0973A6;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
} }
/* Table of contents */ /* Table of contents */
#table-of-contents { #table-of-contents {
margin: 0 0 10px 0; margin: 0 0 10px 0;
padding: 6px 6px 6px 10px; padding: 6px 6px 6px 10px;
background: #f6fbfe; background: #f6fbfe;
border: 1px solid #DDE8ED; border: 1px solid #DDE8ED;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
margin-bottom: 21px; margin-bottom: 21px;
} }
#table-of-contents h4 { #table-of-contents h4 {
font-size: 14px; font-size: 14px;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
#table-of-contents h4 span.updown { #table-of-contents h4 span.updown {
color: #a2c1d0; color: #a2c1d0;
margin-left: 6px; margin-left: 6px;
font-size: 10px; font-size: 10px;
} }
#table-of-contents h4:hover { #table-of-contents h4:hover {
opacity: 0.8; opacity: 0.8;
filter: alpha(opacity=80); filter: alpha(opacity=80);
} }
#table-of-contents ul { #table-of-contents ul {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
#table-of-contents li { #table-of-contents li {
line-height: 14px; line-height: 14px;
padding: 0; padding: 0;
list-style: none; list-style: none;
margin: 0; margin: 0;
line-height: 20px; line-height: 20px;
} }
#table-of-contents li.H2 { padding-left:20px; } #table-of-contents li.H2 { padding-left:20px; }
#table-of-contents li.H3 { padding-left:40px; } #table-of-contents li.H3 { padding-left:40px; }
#table-of-contents li.H4 { padding-left:60px; } #table-of-contents li.H4 { padding-left:60px; }
#table-of-contents li.H5 { padding-left:80px; } #table-of-contents li.H5 { padding-left:80px; }
#table-of-contents li.H6 { padding-left:100px; } #table-of-contents li.H6 { padding-left:100px; }
#table-of-contents li li { #table-of-contents li li {
padding-left: 20px; padding-left: 20px;
} }
#table-of-contents a, #table-of-contents a,
#table-of-contents a:visited { #table-of-contents a:visited {
color: #1389ce; color: #1389ce;
text-decoration: none; text-decoration: none;
} }
#table-of-contents a:hover, #table-of-contents a:hover,
#table-of-contents a:focus { #table-of-contents a:focus {
text-decoration: underline; text-decoration: underline;
color: #1389ce; color: #1389ce;
} }
/*! Messages */ /*! Messages */
/** /**
* Example: * Example:
* <div class="info"> * <div class="info">
* <h5>This is a info message</h5> * <h5>This is a info message</h5>
* <p>Body text</p> * <p>Body text</p>
* <a href="#" class="close" title="Close notification">close</a> * <a href="#" class="close" title="Close notification">close</a>
* </div> * </div>
*/ */
#content .warningBox h5, #content .warningBox h5,
@ -421,22 +421,22 @@ html {
#content .notice h5, #content .notice h5,
#content .warning h5, #content .warning h5,
#content .info h5 { #content .info h5 {
margin-bottom: 0px; margin-bottom: 0px;
} }
.hint a.close, .hint a.close,
.notice a.close, .notice a.close,
.warning a.close, .warning a.close,
.info a.close { .info a.close {
background:url(../../docsviewer/images/ico_close_off.png) no-repeat scroll left top transparent; background:url(../../docsviewer/images/ico_close_off.png) no-repeat scroll left top transparent;
display:block; display:block;
font-size:0; font-size:0;
height:11px; height:11px;
position:absolute; position:absolute;
right:3px; right:3px;
text-indent:-9999px; text-indent:-9999px;
top:3px; top:3px;
width:11px; width:11px;
} }
.hint, .hint,
@ -447,17 +447,17 @@ html {
.info, .info,
.pageSkip, .pageSkip,
.warningBox { .warningBox {
border-radius:4px; border-radius:4px;
padding: 10px 20px; padding: 10px 20px;
clear: both; clear: both;
position: relative; position: relative;
margin: 40px 0; margin: 40px 0;
} }
.typography .note h3, .typography .note h3,
.typography .hint h3 { .typography .hint h3 {
line-height: 27px; line-height: 27px;
} }
.hint p, .hint p,
.note p, .note p,
@ -466,357 +466,357 @@ html {
.warning p, .warning p,
.info p, .info p,
.warningBox p { .warningBox p {
margin-bottom: 0; margin-bottom: 0;
font-weight:400; font-weight:400;
} }
.pageSkip { .pageSkip {
background-color: #f9fafa; background-color: #f9fafa;
border: 1px solid #a5b5b0; border: 1px solid #a5b5b0;
text-align: center; text-align: center;
} }
.notice, .notice,
.note, .note,
.warningBox { .warningBox {
background: #FFFFAD; background: #FFFFAD;
} }
.warning, .warning,
.alert { .alert {
background: #FF8480; background: #FF8480;
color:#fff; color:#fff;
} }
.warning a, .warning a,
.alert a { .alert a {
color:#fff; color:#fff;
text-decoration:underline; text-decoration:underline;
} }
.warning code, .warning code,
.alert code { .alert code {
color:#666; color:#666;
} }
.hint { .hint {
background: #f4f4f4; background: #f4f4f4;
} }
.info { .info {
background: #CAF7FF; background: #CAF7FF;
} }
.warning p { .warning p {
margin-bottom: 0; margin-bottom: 0;
} }
.warningBoxTop { .warningBoxTop {
padding: 10px 10px 10px 70px; padding: 10px 10px 10px 70px;
background: url(../../docsviewer/images/warning.png) no-repeat 18px 14px; background: url(../../docsviewer/images/warning.png) no-repeat 18px 14px;
} }
.warningBoxTop h1 { .warningBoxTop h1 {
margin-bottom: 0; margin-bottom: 0;
} }
.warningBoxTop ul { .warningBoxTop ul {
margin: 9px 0 18px; margin: 9px 0 18px;
} }
.warningBoxTop li { .warningBoxTop li {
margin-bottom: 0; margin-bottom: 0;
} }
.warningBox { .warningBox {
margin-top: 0; margin-top: 0;
} }
.warningBoxBottom { .warningBoxBottom {
background-color: #0973A6; background-color: #0973A6;
padding: 12px 0 16px; padding: 12px 0 16px;
} }
.warningBoxBottom a { color: #fff; } .warningBoxBottom a { color: #fff; }
.warningBoxBottom a:hover { color: #f3fbfe; } .warningBoxBottom a:hover { color: #f3fbfe; }
.warningBoxBottom ul { margin: 0 0 0 40px; } .warningBoxBottom ul { margin: 0 0 0 40px; }
.warningBoxBottom li { background: none; margin-bottom: 0; } .warningBoxBottom li { background: none; margin-bottom: 0; }
.doc-breadcrumbs {} .doc-breadcrumbs {}
.doc-breadcrumbs p { .doc-breadcrumbs p {
margin: 0 0 5px 0; margin: 0 0 5px 0;
color: #999; color: #999;
font-size: 38px; font-size: 38px;
} }
.doc-breadcrumbs p a { .doc-breadcrumbs p a {
color: rgb(3, 91, 136); color: rgb(3, 91, 136);
text-decoration:none; text-decoration:none;
font-weight:200; font-weight:200;
} }
.doc-breadcrumbs p a.current { .doc-breadcrumbs p a.current {
color:#696868; color:#696868;
} }
.menu-open { .menu-open {
display:none; display:none;
} }
.well { .well {
min-height: 20px; min-height: 20px;
padding: 19px; padding: 19px;
margin-bottom: 40px; margin-bottom: 40px;
background-color: #f5f5f5; background-color: #f5f5f5;
border: 1px solid #e3e3e3; border: 1px solid #e3e3e3;
border-radius: 4px; border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0,0,0,.05); box-shadow: inset 0 1px 1px rgba(0,0,0,.05);
} }
.well h4 { .well h4 {
margin-top: 0; margin-top: 0;
} }
.result {} .result {}
.result h2 { .result h2 {
margin-bottom: 0; margin-bottom: 0;
} }
.documentation_children { .documentation_children {
overflow: hidden; overflow: hidden;
padding-bottom: 20px; padding-bottom: 20px;
} }
.documentation_children ul { .documentation_children ul {
margin: 0; margin: 0;
} }
.documentation_children h3 { .documentation_children h3 {
font-size: 18px; font-size: 18px;
border-top: 1px solid #ddd; border-top: 1px solid #ddd;
padding-top: 19px; padding-top: 19px;
margin-top: 0; margin-top: 0;
margin-bottom: 0 0 1px 0; margin-bottom: 0 0 1px 0;
} }
.documentation_children li { .documentation_children li {
float: left; float: left;
width: 33%; width: 33%;
margin: 0 0 40px; margin: 0 0 40px;
padding: 0 3% 0 0; padding: 0 3% 0 0;
list-style: none; list-style: none;
} }
.documentation_children li:nth-child(3n+1) { .documentation_children li:nth-child(3n+1) {
clear: both; clear: both;
} }
.documentation_children p { .documentation_children p {
font-size: 15px; font-size: 15px;
opacity: 0.9; opacity: 0.9;
filter: alpha(opacity=90); filter: alpha(opacity=90);
} }
.btn { .btn {
background: #eee; background: #eee;
padding: 10px; padding: 10px;
border-radius: 4px; border-radius: 4px;
font-weight: 400; font-weight: 400;
} }
.btn:hover { .btn:hover {
text-decoration:none; text-decoration:none;
background:#E7E6E6; background:#E7E6E6;
} }
.next-prev { .next-prev {
border-top: 1px solid #eee; border-top: 1px solid #eee;
margin-top: 20px; margin-top: 20px;
padding-top: 19px; padding-top: 19px;
} }
.next-prev a { .next-prev a {
color: #798D85; color: #798D85;
} }
.next-prev p { .next-prev p {
margin: 0; margin: 0;
} }
.next-prev .prev-link { .next-prev .prev-link {
float: left; float: left;
} }
.next-prev .next-link { .next-prev .next-link {
float: right; float: right;
} }
@media (max-width: 767px) { @media (max-width: 767px) {
a.breadcrumb, .introduction p { a.breadcrumb, .introduction p {
font-size:14px; font-size:14px;
} }
.documentation_children li { .documentation_children li {
float: none; float: none;
width: auto; width: auto;
} }
.next-prev .prev-link, .next-prev .prev-link,
.next-prev .next-link { .next-prev .next-link {
float:none; float:none;
margin:20px 0; margin:20px 0;
} }
} }
@media (min-width: 768px) { @media (min-width: 768px) {
.wrapper { .wrapper {
width: 750px; width: 750px;
} }
.documentation_children li { .documentation_children li {
width: 50%; width: 50%;
} }
} }
@media (min-width: 992px) { @media (min-width: 992px) {
.wrapper { .wrapper {
width: 970px; width: 970px;
} }
#sidebar { #sidebar {
width: 25%; width: 25%;
} }
/* Removes close button on desktop view */ /* Removes close button on desktop view */
#sidebar .menu-close { #sidebar .menu-close {
display: none; display: none;
} }
.documentation_children li { .documentation_children li {
width:33%; width:33%;
} }
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.wrapper { .wrapper {
width: 1170px; width: 1170px;
} }
} }
/* Sidebar mobile styles (default:hidden) */ /* Sidebar mobile styles (default:hidden) */
@media (max-width: 991px) { @media (max-width: 991px) {
#sidebar { #sidebar {
position: fixed; position: fixed;
background: transparent; background: transparent;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
opacity: 0; opacity: 0;
z-index: -1; /* [-1] Sidebar: hidden, [0] Page, [1] Sidebar: Show */ z-index: -1; /* [-1] Sidebar: hidden, [0] Page, [1] Sidebar: Show */
box-shadow: none; box-shadow: none;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
-webkit-transition: all 300ms ease; -webkit-transition: all 300ms ease;
-moz-transition: all 300ms ease; -moz-transition: all 300ms ease;
transition: all 300ms ease; transition: all 300ms ease;
-webkit-touch-callout: none; -webkit-touch-callout: none;
-webkit-user-select: none; -webkit-user-select: none;
-khtml-user-select: none; -khtml-user-select: none;
-moz-user-select: none; -moz-user-select: none;
-ms-user-select: none; -ms-user-select: none;
-moz-box-shadow: none!important; -moz-box-shadow: none!important;
-webkit-box-shadow: none!important; -webkit-box-shadow: none!important;
box-shadow: none!important; box-shadow: none!important;
} }
/* Opened sidebar styles */ /* Opened sidebar styles */
#sidebar.open { #sidebar.open {
z-index: 1; z-index: 1;
background: #fff; background: #fff;
opacity: 1; opacity: 1;
} }
/* Fade out sidebar state styles before class is removed */ /* Fade out sidebar state styles before class is removed */
#sidebar.hide { #sidebar.hide {
z-index: 1; z-index: 1;
background: transparent; background: transparent;
color: white; color: white;
} }
#content { #content {
float:none; float:none;
width:auto; width:auto;
} }
#masthead { #masthead {
padding:20px 0; padding:20px 0;
} }
.doc-breadcrumbs p { .doc-breadcrumbs p {
font-size:18px; font-size:18px;
} }
.introduction p { .introduction p {
font-size:14px; font-size:14px;
} }
/* Menu button styles */ /* Menu button styles */
.wrapper .menu-open { .wrapper .menu-open {
display: block; display: block;
position: relative; position: relative;
width: 70px; width: 70px;
height: 40px; height: 40px;
margin-left: auto; margin-left: auto;
margin-bottom: 20px; margin-bottom: 20px;
padding: 7px 10px; padding: 7px 10px;
font-weight: 700; font-weight: 700;
text-decoration: none; text-decoration: none;
text-transform: uppercase; text-transform: uppercase;
color: #1389ce; color: #1389ce;
background-color: transparent; background-color: transparent;
border: 2px solid #1389ce; border: 2px solid #1389ce;
border-radius: 5px; border-radius: 5px;
cursor: pointer; cursor: pointer;
-webkit-user-select: none; /* Chrome/Safari */ -webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */ -moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */ -ms-user-select: none; /* IE10+ */
} }
.wrapper .menu-open:hover { .wrapper .menu-open:hover {
background-color: #1389ce; background-color: #1389ce;
color: #fff; color: #fff;
transition: 300ms 0.1s ease; transition: 300ms 0.1s ease;
} }
/* Close button styles */ /* Close button styles */
.menu-close { .menu-close {
display: block; display: block;
position: relative; position: relative;
margin-left: auto; margin-left: auto;
margin-right: 10px; margin-right: 10px;
padding: 0px 12px; padding: 0px 12px;
font-size: 33px; font-size: 33px;
font-weight: 700; font-weight: 700;
line-height: 33px; line-height: 33px;
text-decoration: none; text-decoration: none;
color: #1389ce; color: #1389ce;
width: 40px; width: 40px;
height: 40px; height: 40px;
cursor: pointer; cursor: pointer;
-webkit-user-select: none; /* Chrome/Safari */ -webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */ -moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */ -ms-user-select: none; /* IE10+ */
} }
.menu-close:hover { .menu-close:hover {
text-decoration: none; text-decoration: none;
} }
} }
/* Hamburger positioning */ /* Hamburger positioning */
@media (max-width:992px) { @media (max-width:992px) {
#content { #content {
float: right; float: right;
width: 100%; width: 100%;
} }
} }
#content pre { #content pre {
@ -828,9 +828,9 @@ html {
} }
#content pre code { #content pre code {
color:#fff; color:#fff;
font-family: Menlo,Monaco,Consolas,"Courier New",monospace; font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
font-weight:bold; font-weight:bold;
} }
pre .nocode { pre .nocode {
@ -900,11 +900,11 @@ li.L1, li.L3, li.L5, li.L7, li.L9 {}
@media print { @media print {
#content pre.prettyprint { #content pre.prettyprint {
background-color: none; background-color: none;
display: block; display: block;
background-color: #333; background-color: #333;
border-radius:4px; border-radius:4px;
padding:13px 16px; padding:13px 16px;
margin-bottom:30px; margin-bottom:30px;
} }
pre .str,code .str { pre .str,code .str {

View File

@ -219,45 +219,45 @@
.syntaxhighlighter .line.highlighted .number .syntaxhighlighter .line.highlighted .number
{ {
background-color: #ddd !important; background-color: #ddd !important;
color: black !important; color: black !important;
} }
/* Highlighed line */ /* Highlighed line */
.syntaxhighlighter .line.highlighted.alt1 .content, .syntaxhighlighter .line.highlighted.alt1 .content,
.syntaxhighlighter .line.highlighted.alt2 .content .syntaxhighlighter .line.highlighted.alt2 .content
{ {
background-color: #ddd !important; background-color: #ddd !important;
} }
/* Gutter line numbers */ /* Gutter line numbers */
.syntaxhighlighter .line .number .syntaxhighlighter .line .number
{ {
color: #aaa !important; color: #aaa !important;
} }
/* Add border to the lines */ /* Add border to the lines */
.syntaxhighlighter .line .content .syntaxhighlighter .line .content
{ {
border-left: 2px solid #ccc !important; border-left: 2px solid #ccc !important;
color: #000 !important; color: #000 !important;
} }
.syntaxhighlighter.printing .line .content .syntaxhighlighter.printing .line .content
{ {
border: 0 !important; border: 0 !important;
} }
/* First line */ /* First line */
.syntaxhighlighter .line.alt1 .content .syntaxhighlighter .line.alt1 .content
{ {
background-color: #fafafa !important; background-color: #fafafa !important;
} }
/* Second line */ /* Second line */
.syntaxhighlighter .line.alt2 .content .syntaxhighlighter .line.alt2 .content
{ {
background-color: #fafafa !important; background-color: #fafafa !important;
} }
.syntaxhighlighter .line .content .block .syntaxhighlighter .line .content .block
@ -267,53 +267,53 @@
.syntaxhighlighter .ruler .syntaxhighlighter .ruler
{ {
color: silver !important; color: silver !important;
background-color: #F8F8F8 !important; background-color: #F8F8F8 !important;
border-left: 3px solid #6CE26C !important; border-left: 3px solid #6CE26C !important;
} }
.syntaxhighlighter.nogutter .ruler .syntaxhighlighter.nogutter .ruler
{ {
border: 0 !important; border: 0 !important;
} }
.syntaxhighlighter .toolbar .syntaxhighlighter .toolbar
{ {
background-color: #ddd !important; background-color: #ddd !important;
} }
.syntaxhighlighter .toolbar a .syntaxhighlighter .toolbar a
{ {
color: #a0a0a0 !important; color: #a0a0a0 !important;
} }
.syntaxhighlighter .toolbar a:hover .syntaxhighlighter .toolbar a:hover
{ {
color: red !important; color: red !important;
} }
.syntaxhighlighter .comments, .syntaxhighlighter .comments,
.syntaxhighlighter .comments a .syntaxhighlighter .comments a
{ {
color: #999988 !important; color: #999988 !important;
font-style: italic !important; font-style: italic !important;
line-height: 13px !important; line-height: 13px !important;
} }
.syntaxhighlighter .string, .syntaxhighlighter .string,
.syntaxhighlighter .string a .syntaxhighlighter .string a
{ {
color: #D81745 !important; color: #D81745 !important;
} }
.syntaxhighlighter .keyword .syntaxhighlighter .keyword
{ {
font-weight: bold !important; font-weight: bold !important;
} }
.syntaxhighlighter .preprocessor .syntaxhighlighter .preprocessor
{ {
color: gray !important; color: gray !important;
} }
.syntaxhighlighter .regex .syntaxhighlighter .regex
@ -338,46 +338,46 @@
.syntaxhighlighter .variable .syntaxhighlighter .variable
{ {
color: #177F80 !important; color: #177F80 !important;
} }
.syntaxhighlighter .value .syntaxhighlighter .value
{ {
color: red !important; color: red !important;
} }
.syntaxhighlighter .functions .syntaxhighlighter .functions
{ {
color: #990000 !important; color: #990000 !important;
font-weight:bold !important; font-weight:bold !important;
} }
.syntaxhighlighter .constants .syntaxhighlighter .constants
{ {
color: #177F80 !important; color: #177F80 !important;
} }
.syntaxhighlighter .script .syntaxhighlighter .script
{ {
background-color: yellow !important; background-color: yellow !important;
} }
.syntaxhighlighter .color1, .syntaxhighlighter .color1,
.syntaxhighlighter .color1 a .syntaxhighlighter .color1 a
{ {
color: #177F80 !important; color: #177F80 !important;
} }
.syntaxhighlighter .color2, .syntaxhighlighter .color2,
.syntaxhighlighter .color2 a .syntaxhighlighter .color2 a
{ {
color: #960B73 !important; color: #960B73 !important;
} }
.syntaxhighlighter .color3, .syntaxhighlighter .color3,
.syntaxhighlighter .color3 a .syntaxhighlighter .color3 a
{ {
color: red !important; color: red !important;
} }
/** end ugliness */ /** end ugliness */

View File

@ -1,36 +1,36 @@
@media screen and (max-width: 540px) { @media screen and (max-width: 540px) {
#content-column { #content-column {
width: 100%; width: 100%;
padding: 0; padding: 0;
} }
#container { #container {
padding: 15px; padding: 15px;
} }
#sidebar-column { #sidebar-column {
width: 100%; width: 100%;
} }
#sidebar-column .sidebar-box { #sidebar-column .sidebar-box {
padding: 10px; padding: 10px;
} }
#footer { #footer {
padding: 20px; padding: 20px;
} }
.pinned { position: absolute; left: 0; top: 0; background: #fff; width: 35%; overflow: hidden; overflow-x: scroll; border-right: 1px solid #ccc; border-left: 1px solid #ccc; } .pinned { position: absolute; left: 0; top: 0; background: #fff; width: 35%; overflow: hidden; overflow-x: scroll; border-right: 1px solid #ccc; border-left: 1px solid #ccc; }
.pinned table { border-right: none; border-left: none; width: 100%; } .pinned table { border-right: none; border-left: none; width: 100%; }
.pinned table th, .pinned table td { white-space: nowrap; } .pinned table th, .pinned table td { white-space: nowrap; }
.pinned td:last-child { border-bottom: 0; } .pinned td:last-child { border-bottom: 0; }
div.table-wrapper { position: relative; margin-bottom: 20px; overflow: hidden; border-right: 1px solid #ccc; } div.table-wrapper { position: relative; margin-bottom: 20px; overflow: hidden; border-right: 1px solid #ccc; }
div.table-wrapper div.scrollable table { margin-left: 35%; } div.table-wrapper div.scrollable table { margin-left: 35%; }
div.table-wrapper div.scrollable { overflow: scroll; overflow-y: hidden; } div.table-wrapper div.scrollable { overflow: scroll; overflow-y: hidden; }
table td, table th { position: relative; white-space: nowrap; overflow: hidden; } table td, table th { position: relative; white-space: nowrap; overflow: hidden; }
table th:first-child, table td:first-child, table td:first-child, .pinned table td { display: none; } table th:first-child, table td:first-child, table td:first-child, .pinned table td { display: none; }
.pinned table td:first-child, .pinned table td:first-child,
.pinned table th:first-child { display: block; } .pinned table th:first-child { display: block; }
} }

View File

@ -1,49 +1,49 @@
/*! text selection */ /*! text selection */
::-moz-selection { ::-moz-selection {
text-shadow:none; text-shadow:none;
color: #ffffff; color: #ffffff;
background: #1389CE; background: #1389CE;
} }
::selection { ::selection {
text-shadow: none; text-shadow: none;
color: #ffffff; color: #ffffff;
background: #1389CE; background: #1389CE;
} }
/*! links */ /*! links */
a { a {
color: #808c8d; color: #808c8d;
text-decoration: none; text-decoration: none;
} }
a:hover, a:hover,
a:focus { a:focus {
text-decoration: underline; text-decoration: underline;
} }
a[href$=".pdf"], a[href$=".pdf"],
a[href$=".PDF"], a[href$=".PDF"],
a.pdf { a.pdf {
padding: 2px; padding: 2px;
padding-left: 20px; padding-left: 20px;
background: url(../../docsviewer/images/icons/page_white_acrobat.png) no-repeat left center; background: url(../../docsviewer/images/icons/page_white_acrobat.png) no-repeat left center;
} }
a[href$=".doc"], a[href$=".doc"],
a[href$=".DOC"], a[href$=".DOC"],
a.doc { a.doc {
padding: 2px; padding: 2px;
padding-left: 20px; padding-left: 20px;
background: url(../../docsviewer/images/icons/page_word.png) no-repeat left center; background: url(../../docsviewer/images/icons/page_word.png) no-repeat left center;
} }
a[href$=".xls"], a[href$=".xls"],
a[href$=".XLS"], a[href$=".XLS"],
a.xls { a.xls {
padding: 2px; padding: 2px;
padding-left: 20px; padding-left: 20px;
background: url(../../docsviewer/images/icons/page_excel.png) no-repeat left center; background: url(../../docsviewer/images/icons/page_excel.png) no-repeat left center;
} }
a[href$=".gz"], a[href$=".gz"],
@ -53,136 +53,136 @@ a[href$=".GZIP"],
a[href$=".zip"], a[href$=".zip"],
a[href$=".ZIP"], a[href$=".ZIP"],
a.archive { a.archive {
padding: 2px; padding: 2px;
padding-left: 20px; padding-left: 20px;
background: url(../../docsviewer/images/icons/page_white_zip.png) no-repeat left center; background: url(../../docsviewer/images/icons/page_white_zip.png) no-repeat left center;
} }
a[href$=".exe"], a[href$=".exe"],
a[href$=".EXE"], a[href$=".EXE"],
a.application { a.application {
padding: 2px; padding: 2px;
padding-left: 20px; padding-left: 20px;
background: url(../../docsviewer/images/icons/application.png) no-repeat left center; background: url(../../docsviewer/images/icons/application.png) no-repeat left center;
} }
/*! pargraphs */ /*! pargraphs */
p { p {
font-size: 15px; font-size: 15px;
line-height: 1.5; line-height: 1.5;
margin: 0 0 25px; margin: 0 0 25px;
} }
.text-wrap { .text-wrap {
word-break: break-all; word-break: break-all;
} }
/*! lists */ /*! lists */
ul { ul {
margin: 10px 0 20px 20px; margin: 10px 0 20px 20px;
padding: 0; padding: 0;
} }
li, dd, li p { li, dd, li p {
font-size: 15px; font-size: 15px;
margin: 0 0 10px 0; margin: 0 0 10px 0;
line-height: 1.5; line-height: 1.5;
} }
li { li {
list-style-position: inside; list-style-position: inside;
} }
li ul, li ul,
li ol { li ol {
margin: 0 0 5px 20px; margin: 0 0 5px 20px;
} }
dl { dl {
margin: 7px 0 21px 0; margin: 7px 0 21px 0;
} }
dt { dt {
font-weight: bold; font-weight: bold;
} }
dd { dd {
margin: 5px 0 10px 20px; margin: 5px 0 10px 20px;
} }
.semantic { .semantic {
list-style: none; list-style: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
ul.third { ul.third {
overflow: hidden; overflow: hidden;
} }
ul.third li { ul.third li {
float: left; float: left;
width: 33.3%; width: 33.3%;
padding-right: 30px; padding-right: 30px;
padding-bottom: 20px; padding-bottom: 20px;
} }
ul.third li:nth-child(3n+1) { ul.third li:nth-child(3n+1) {
clear: both; clear: both;
} }
/*! headers */ /*! headers */
h1 { h1 {
font-size: 35px; font-size: 35px;
line-height: 40px; line-height: 40px;
margin-bottom: 10px; margin-bottom: 10px;
margin-top: 0; margin-top: 0;
letter-spacing: -1px; letter-spacing: -1px;
color:rgb(3, 91, 136); color:rgb(3, 91, 136);
} }
#table-of-contents + p { #table-of-contents + p {
font-size: 18px; font-size: 18px;
line-height: 20px; line-height: 20px;
} }
h1 + p { h1 + p {
margin-top: 30px; margin-top: 30px;
} }
h2 { h2 {
font-size: 28px; font-size: 28px;
line-height: 30px; line-height: 30px;
margin: 40px 0 20px; margin: 40px 0 20px;
border-top: 1px solid #eee; border-top: 1px solid #eee;
padding-top: 29px; padding-top: 29px;
letter-spacing: -1px; letter-spacing: -1px;
color: rgb(3, 91, 136); color: rgb(3, 91, 136);
} }
h3 { h3 {
font-size: 20px; font-size: 20px;
line-height: 20px; line-height: 20px;
margin: 30px 0 10px; margin: 30px 0 10px;
color: #181c1d; color: #181c1d;
} }
h4 { h4 {
font-size: 16px; font-size: 16px;
margin-bottom: 14px; margin-bottom: 14px;
line-height: 21px; line-height: 21px;
} }
h5 { h5 {
font-size: 14px; font-size: 14px;
line-height: 14px; line-height: 14px;
margin-bottom: 7px; margin-bottom: 7px;
} }
h6 { h6 {
font-size: 12px; font-size: 12px;
line-height: 15px; line-height: 15px;
margin-bottom: 10px; margin-bottom: 10px;
} }
h1 .heading-anchor-link, h1 .heading-anchor-link,
@ -191,167 +191,167 @@ h3 .heading-anchor-link,
h4 .heading-anchor-link, h4 .heading-anchor-link,
h5 .heading-anchor-link, h5 .heading-anchor-link,
h6 .heading-anchor-link { h6 .heading-anchor-link {
display: none; display: none;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
} }
h1.hover .heading-anchor-link, h1.hover .heading-anchor-link,
h2.hover .heading-anchor-link, h2.hover .heading-anchor-link,
h3.hover .heading-anchor-link, h3.hover .heading-anchor-link,
h4.hover .heading-anchor-link, h4.hover .heading-anchor-link,
h5.hover .heading-anchor-link, h5.hover .heading-anchor-link,
h6.hover .heading-anchor-link, h6.hover .heading-anchor-link,
.heading-anchor-link:hover { .heading-anchor-link:hover {
display: inline; display: inline;
color: #aaa; color: #aaa;
} }
/*! images */ /*! images */
img { img {
max-width: 100%; max-width: 100%;
border: 1px solid #ccc; border: 1px solid #ccc;
padding: 6px; padding: 6px;
margin: 10px 0; margin: 10px 0;
border-radius: 3px; border-radius: 3px;
} }
/*! code */ /*! code */
pre { pre {
margin: 20px 0 30px; margin: 20px 0 30px;
font: 13px/20px Monaco, 'Bitstream Vera Sans Mono', 'Courier New', monospace; font: 13px/20px Monaco, 'Bitstream Vera Sans Mono', 'Courier New', monospace;
background-color: #f6f7f8; background-color: #f6f7f8;
border: 1px solid #e9eaed; border: 1px solid #e9eaed;
padding: 14px; padding: 14px;
border-radius: 3px; border-radius: 3px;
overflow-x: scroll; overflow-x: scroll;
color: #4E5661; color: #4E5661;
} }
pre code { pre code {
background: none; background: none;
font-weight: normal; font-weight: normal;
padding: 0; padding: 0;
} }
code { code {
font: 13px/15px Monaco, 'Bitstream Vera Sans Mono', Courier, monospace; font: 13px/15px Monaco, 'Bitstream Vera Sans Mono', Courier, monospace;
background: #ecf0f1; background: #ecf0f1;
padding: 2px; padding: 2px;
} }
code a { code a {
color: #4E5661; color: #4E5661;
} }
/*! quotes */ /*! quotes */
blockquote { blockquote {
margin: 28px 0; margin: 28px 0;
padding: 14px 14px 0 38px; padding: 14px 14px 0 38px;
background: #f8f9fa url(../../docsviewer/images/quote.gif) no-repeat 9px 18px; background: #f8f9fa url(../../docsviewer/images/quote.gif) no-repeat 9px 18px;
overflow: hidden; overflow: hidden;
} }
blockquote h1, blockquote h1,
blockquote h2, blockquote h2,
blockquote h3, blockquote h3,
blockquote h4, blockquote h4,
blockquote h5, blockquote h5,
blockquote h6 { blockquote h6 {
font-style: italic; font-style: italic;
color: #627871; color: #627871;
} }
blockquote h4 { blockquote h4 {
font-size: 18px; font-size: 18px;
} }
blockquote p { blockquote p {
font-style: italic; font-style: italic;
font-size: 14px; font-size: 14px;
color: #667D76; color: #667D76;
} }
/*! tables */ /*! tables */
table { table {
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
background-color: #fafafa; background-color: #fafafa;
margin-bottom: 28px; margin-bottom: 28px;
border: 1px solid #c3cdca; border: 1px solid #c3cdca;
} }
table tr:nth-child(even) { table tr:nth-child(even) {
background: #eef4f6; background: #eef4f6;
} }
table caption { table caption {
text-align: left; text-align: left;
font-weight: bold; font-weight: bold;
font-size: 18px; font-size: 18px;
line-height: 21px; line-height: 21px;
} }
table thead { table thead {
background: #fafafa; background: #fafafa;
} }
table thead th { table thead th {
padding: 7px 10px 6px; padding: 7px 10px 6px;
font-size: 15px; font-size: 15px;
text-align: left; text-align: left;
border-right: 1px solid #c3cdca; border-right: 1px solid #c3cdca;
} }
table tbody tr { table tbody tr {
border-top: 1px solid #c3cdca; border-top: 1px solid #c3cdca;
} }
table td { table td {
font-size: 15px; font-size: 15px;
line-height: 21px; line-height: 21px;
padding: 7px; padding: 7px;
border-right: 1px solid #c3cdca; border-right: 1px solid #c3cdca;
} }
/*! Edit Link */ /*! Edit Link */
#edit-link { #edit-link {
margin: 30px 0; margin: 30px 0;
} }
#edit-link p { #edit-link p {
margin: 0; margin: 0;
overflow: hidden; overflow: hidden;
} }
#edit-link a { #edit-link a {
display: block; display: block;
background: #fafafa; background: #fafafa;
background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#fafafa), color-stop(100%,#e6e6e6)); background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#fafafa), color-stop(100%,#e6e6e6));
background: -webkit-linear-gradient(top, #fafafa 1%,#e6e6e6 100%); background: -webkit-linear-gradient(top, #fafafa 1%,#e6e6e6 100%);
background: -webkit-linear-gradient(top, #fafafa 1%, #e6e6e6 100%); background: -webkit-linear-gradient(top, #fafafa 1%, #e6e6e6 100%);
background: linear-gradient(to bottom, #fafafa 1%,#e6e6e6 100%); background: linear-gradient(to bottom, #fafafa 1%,#e6e6e6 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fafafa', endColorstr='#e6e6e6',GradientType=0 ); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fafafa', endColorstr='#e6e6e6',GradientType=0 );
border: 1px solid #d4d4d4; border: 1px solid #d4d4d4;
border-bottom-color: #bcbcbc; border-bottom-color: #bcbcbc;
text-shadow: 0 1px 0 #fff; text-shadow: 0 1px 0 #fff;
color: #333; color: #333;
font-weight: bold; font-weight: bold;
margin-bottom: 5px; margin-bottom: 5px;
text-decoration: none; text-decoration: none;
padding: 5px 10px; padding: 5px 10px;
border-radius: 3px; border-radius: 3px;
float: left; float: left;
} }
#edit-link a:hover, #edit-link a:hover,
#edit-link a:focus { #edit-link a:focus {
color: #fff; color: #fff;
text-shadow: 0 -1px 1px #3072B3; text-shadow: 0 -1px 1px #3072B3;
border-color: #518CC6; border-color: #518CC6;
background: #599BDC; background: #599BDC;
background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#3072B3), color-stop(100%,#3072B3)); background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#3072B3), color-stop(100%,#3072B3));
background: -webkit-linear-gradient(top, #599BDC 1%,#3072B3 100%); background: -webkit-linear-gradient(top, #599BDC 1%,#3072B3 100%);
background: -webkit-linear-gradient(top, #599BDC 1%, #3072B3 100%); background: -webkit-linear-gradient(top, #599BDC 1%, #3072B3 100%);
background: linear-gradient(to bottom, #599BDC 1%,#3072B3 100%); background: linear-gradient(to bottom, #599BDC 1%,#3072B3 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#599BDC', endColorstr='#3072B3',GradientType=0 ); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#599BDC', endColorstr='#3072B3',GradientType=0 );
} }

View File

@ -1,24 +1,24 @@
.clear { .clear {
clear: both; clear: both;
display: block; display: block;
overflow: hidden; overflow: hidden;
visibility: hidden; visibility: hidden;
width: 0; width: 0;
height: 0; height: 0;
} }
.clearfix:after { .clearfix:after {
clear: both; clear: both;
content:' '; content:' ';
display: block; display: block;
font-size: 0; font-size: 0;
line-height: 0; line-height: 0;
visibility: hidden; visibility: hidden;
width: 0; width: 0;
height: 0 height: 0
} }
* html .clearfix, * html .clearfix,
*:first-child+html .clearfix{ *:first-child+html .clearfix{
zoom: 1; zoom: 1;
} }

View File

@ -1,192 +1,233 @@
;(function($) { ;(function($) {
$(document).ready(function() { $(document).ready(
function() {
// Open sidebar on mobile // Open sidebar on mobile
$('.menu-open').click(function(){ $('.menu-open').click(
$('#sidebar').removeClass('hide').addClass('open'); function(){
return false; $('#sidebar').removeClass('hide').addClass('open');
}); return false;
// Close sidebar on mobile }
$('.menu-close').click(function(){ );
$('#sidebar').removeClass('open').addClass('hide'); // Close sidebar on mobile
$('.menu-close').click(
function(){
$('#sidebar').removeClass('open').addClass('hide');
setTimeout(function() { setTimeout(
$('#sidebar').removeClass('hide'); function() {
}, 500); $('#sidebar').removeClass('hide');
return false; }, 500
}); );
// Close sidebar by hitting of ESC return false;
$(document).keyup(function(e) { }
if (e.keyCode == 27) { );
$('#sidebar').removeClass('open'); // Close sidebar by hitting of ESC
} $(document).keyup(
}); function(e) {
if (e.keyCode == 27) {
$('#sidebar').removeClass('open');
}
}
);
var switched = false; var switched = false;
var updateTables = function() { var updateTables = function() {
if (($(window).width() < 540) && !switched ){ if (($(window).width() < 540) && !switched ) {
switched = true; switched = true;
$("table").each(function(i, element) { $("table").each(
splitTable($(element)); function(i, element) {
}); splitTable($(element));
}
);
return true; return true;
} }
else if (switched && ($(window).width() > 540)) { else if (switched && ($(window).width() > 540)) {
switched = false; switched = false;
$("table").each(function(i, element) { $("table").each(
unsplitTable($(element)); function(i, element) {
}); unsplitTable($(element));
} }
}; );
}
};
$(window).load(updateTables); $(window).load(updateTables);
$(window).on("redraw",function() { $(window).on(
switched = false; "redraw",function() {
updateTables(); switched = false;
}); // An event to listen for updateTables();
}
); // An event to listen for
$(window).on("resize", updateTables); $(window).on("resize", updateTables);
function splitTable(original) { function splitTable(original) {
original.wrap("<div class='table-wrapper' />"); original.wrap("<div class='table-wrapper' />");
var copy = original.clone(); var copy = original.clone();
copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none"); copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none");
copy.removeClass("responsive"); copy.removeClass("responsive");
original.closest(".table-wrapper").append(copy); original.closest(".table-wrapper").append(copy);
copy.wrap("<div class='pinned' />"); copy.wrap("<div class='pinned' />");
original.wrap("<div class='scrollable' />"); original.wrap("<div class='scrollable' />");
setCellHeights(original, copy); setCellHeights(original, copy);
} }
function unsplitTable(original) { function unsplitTable(original) {
original.closest(".table-wrapper").find(".pinned").remove(); original.closest(".table-wrapper").find(".pinned").remove();
original.unwrap(); original.unwrap();
original.unwrap(); original.unwrap();
} }
function setCellHeights(original, copy) { function setCellHeights(original, copy) {
var tr = original.find('tr'), var tr = original.find('tr'),
tr_copy = copy.find('tr'), tr_copy = copy.find('tr'),
heights = []; heights = [];
tr.each(function (index) { tr.each(
var self = $(this), function (index) {
tx = self.find('th, td'); var self = $(this),
tx = self.find('th, td');
tx.each(function () { tx.each(
var height = $(this).outerHeight(true); function () {
heights[index] = heights[index] || 0; var height = $(this).outerHeight(true);
heights[index] = heights[index] || 0;
if (height > heights[index]) heights[index] = height; if (height > heights[index]) { heights[index] = height;
}); }
}); }
);
}
);
tr_copy.each(function (index) { tr_copy.each(
$(this).height(heights[index]); function (index) {
}); $(this).height(heights[index]);
} }
);
}
/** ----------------------------------------------- /**
* TABLE OF CONTENTS * -----------------------------------------------
* * TABLE OF CONTENTS
* Transform a #table-of-contents div to a nested list *
*/ * Transform a #table-of-contents div to a nested list
if($("#table-contents-holder").length > 0) { */
var toc = '<div id="table-of-contents" class="open">' + if($("#table-contents-holder").length > 0) {
'<h4>Table of contents<span class="updown">&#9660;</span></h4><ul style="display: none;">'; var toc = '<div id="table-of-contents" class="open">' +
'<h4>Table of contents<span class="updown">&#9660;</span></h4><ul style="display: none;">';
// Remove existing anchor redirection in the url // Remove existing anchor redirection in the url
var pageURL = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, ''); var pageURL = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, '');
var itemCount = 0; var itemCount = 0;
$('#content h1[id], #content h2[id], #content h3[id], #content h4[id]').each(function(i) { $('#content h1[id], #content h2[id], #content h3[id], #content h4[id]').each(
var current = $(this); function(i) {
var tagName = current.prop("tagName"); var current = $(this);
if(typeof tagName == "String") tagName = tagName.toLowerCase(); var tagName = current.prop("tagName");
itemCount++; if(typeof tagName == "String") { tagName = tagName.toLowerCase();
toc += '<li class="' + tagName + '"><a id="link' + i + '" href="'+ pageURL +'#' + $(this).attr('id') + '" title="' + current.html() + '">' + current.html() + '</a></li>'; }
}); itemCount++;
toc += '<li class="' + tagName + '"><a id="link' + i + '" href="'+ pageURL +'#' + $(this).attr('id') + '" title="' + current.html() + '">' + current.html() + '</a></li>';
}
);
// if no items in the table of contents, don't show anything // if no items in the table of contents, don't show anything
if(itemCount == 0) return false; if(itemCount == 0) { return false;
}
toc += '</ul></div>'; toc += '</ul></div>';
$('#table-contents-holder').prepend(toc); $('#table-contents-holder').prepend(toc);
// Toggle the TOC // Toggle the TOC
$('#table-of-contents').attr('href', 'javascript:void()').toggle( $('#table-of-contents').attr('href', 'javascript:void()').toggle(
function() { function() {
$("#table-of-contents ul").animate({'height':'show'}, 200, function(){$('#table-of-contents h4 span').html('&#9650;');}) $("#table-of-contents ul").animate({'height':'show'}, 200, function(){$('#table-of-contents h4 span').html('&#9650;');})
}, },
function() { function() {
$("#table-of-contents ul").animate({'height':'hide'}, 200, function(){$('#table-of-contents h4 span').html('&#9660;');}) $("#table-of-contents ul").animate({'height':'hide'}, 200, function(){$('#table-of-contents h4 span').html('&#9660;');})
} }
); );
// Make sure clicking a link won't toggle the TOC // Make sure clicking a link won't toggle the TOC
$("#table-of-contents li a").click(function (e) { e.stopPropagation(); }); $("#table-of-contents li a").click(function (e) { e.stopPropagation(); });
} }
/** --------------------------------------------- /**
* HEADING ANCHOR LINKS * ---------------------------------------------
* * HEADING ANCHOR LINKS
* Automatically adds anchor links to headings that have IDs *
*/ * Automatically adds anchor links to headings that have IDs
var url = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, ''); */
var url = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, '');
$("#content h1[id], #content h2[id], #content h3[id], #content h4[id], #content h5[id], #content h6[id]").each(function() { $("#content h1[id], #content h2[id], #content h3[id], #content h4[id], #content h5[id], #content h6[id]").each(
var link = '<a class="heading-anchor-link" title="Link to this section" href="'+ url + '#' + $(this).attr('id') + '">&para;</a>'; function() {
$(this).append(' ' + link); var link = '<a class="heading-anchor-link" title="Link to this section" href="'+ url + '#' + $(this).attr('id') + '">&para;</a>';
}); $(this).append(' ' + link);
}
);
$("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]").mouseenter(function() { $("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]").mouseenter(
$(this).addClass('hover'); function() {
}); $(this).addClass('hover');
}
);
$("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]").mouseleave(function() { $("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]").mouseleave(
$(this).removeClass('hover'); function() {
}); $(this).removeClass('hover');
}
);
/** --------------------------------------------- /**
* LANGAUGE SELECTER * ---------------------------------------------
* * LANGAUGE SELECTER
* Hide the change button and do it onclick *
*/ * Hide the change button and do it onclick
$("#Form_LanguageForm .Actions").hide(); */
$("#Form_LanguageForm .Actions").hide();
$("#Form_LanguageForm select").change(function() { $("#Form_LanguageForm select").change(
$("#Form_LanguageForm").submit(); function() {
}); $("#Form_LanguageForm").submit();
}
);
/** --------------------------------------------- /**
* SYNTAX HIGHLIGHTER * ---------------------------------------------
* * SYNTAX HIGHLIGHTER
* As the Markdown parser now uses the GFM structure (```yml) this does *
* not work with SyntaxHighlighter. The below translates the GFM output * As the Markdown parser now uses the GFM structure (```yml) this does
* to one SyntaxHighter can use * not work with SyntaxHighlighter. The below translates the GFM output
*/ * to one SyntaxHighter can use
$("pre").each(function(i, elem) { */
var code = $(elem).find('code[class^=language]'); $("pre").each(
function(i, elem) {
var code = $(elem).find('code[class^=language]');
if(code.length > 0) { if(code.length > 0) {
var brush = code.attr('class').replace('language-', ''); var brush = code.attr('class').replace('language-', '');
$(elem).attr('class', 'prettyprint lang-' + brush); $(elem).attr('class', 'prettyprint lang-' + brush);
// $(elem).html(code.html()); // $(elem).html(code.html());
} }
}); }
);
}); }
);
})(jQuery); })(jQuery);

View File

@ -0,0 +1,33 @@
<?php
class DocumentationEntityTest extends SapphireTest
{
public function dataCompare()
{
return array(
array('3', '3.0', 1),
array('3.1', '3.1', 0),
array('3.0', '3', -1),
array('4', '3', 1),
array('3', '4', -1),
array('3.4.1', '4', -1)
);
}
/**
* @dataProvider dataCompare
* @param string $left
* @param string $right
* @param int $result
*/
public function testCompare($left, $right, $result)
{
$leftVersion = new DocumentationEntity('Framework');
$leftVersion->setVersion($left);
$rightVersion = new DocumentationEntity('Framework');
$rightVersion->setVersion($right);
$this->assertEquals($result, $leftVersion->compare($rightVersion));
}
}

View File

@ -8,68 +8,105 @@ class DocumentationHelperTests extends SapphireTest
{ {
public function testCleanName() public function testCleanName()
{ {
$this->assertEquals("File path", DocumentationHelper::clean_page_name( $this->assertEquals(
'00_file-path.md' 'File path',
)); DocumentationHelper::clean_page_name(
'00_file-path.md'
)
);
} }
public function testCleanUrl() public function testCleanUrl()
{ {
$this->assertEquals("some_path", DocumentationHelper::clean_page_url( $this->assertEquals(
'Some Path' 'some_path',
)); DocumentationHelper::clean_page_url(
'Some Path'
)
);
$this->assertEquals("somefilepath", DocumentationHelper::clean_page_url( $this->assertEquals(
'00_SomeFilePath.md' 'somefilepath',
)); DocumentationHelper::clean_page_url(
'00_SomeFilePath.md'
)
);
} }
public function testTrimSortNumber() public function testTrimSortNumber()
{ {
$this->assertEquals('file', DocumentationHelper::trim_sort_number( $this->assertEquals(
'0_file' 'file',
)); DocumentationHelper::trim_sort_number(
'0_file'
)
);
$this->assertEquals('2.1', DocumentationHelper::trim_sort_number( $this->assertEquals(
'2.1' '2.1',
)); DocumentationHelper::trim_sort_number(
'2.1'
)
);
$this->assertEquals('dev/tasks/2.1', DocumentationHelper::trim_sort_number( $this->assertEquals(
'dev/tasks/2.1' 'dev/tasks/2.1',
)); DocumentationHelper::trim_sort_number(
'dev/tasks/2.1'
)
);
} }
public function testTrimExtension() public function testTrimExtension()
{ {
$this->assertEquals('file', DocumentationHelper::trim_extension_off( $this->assertEquals(
'file.md' 'file',
)); DocumentationHelper::trim_extension_off(
'file.md'
)
);
$this->assertEquals('dev/path/file', DocumentationHelper::trim_extension_off( $this->assertEquals(
'dev/path/file.md' 'dev/path/file',
)); DocumentationHelper::trim_extension_off(
'dev/path/file.md'
)
);
} }
public function testGetExtension() public function testGetExtension()
{ {
$this->assertEquals('md', DocumentationHelper::get_extension( $this->assertEquals(
'file.md' 'md',
)); DocumentationHelper::get_extension(
'file.md'
)
);
$this->assertEquals('md', DocumentationHelper::get_extension( $this->assertEquals(
'dev/tasks/file.md' 'md',
)); DocumentationHelper::get_extension(
'dev/tasks/file.md'
)
);
$this->assertEquals('txt', DocumentationHelper::get_extension( $this->assertEquals(
'dev/tasks/file.txt' 'txt',
)); DocumentationHelper::get_extension(
'dev/tasks/file.txt'
)
);
$this->assertNull(DocumentationHelper::get_extension( $this->assertNull(
'doc_test/2.3' DocumentationHelper::get_extension(
)); 'doc_test/2.3'
)
);
$this->assertNull(DocumentationHelper::get_extension( $this->assertNull(
'dev/docs/en/doc_test/2.3/subfolder' DocumentationHelper::get_extension(
)); 'dev/docs/en/doc_test/2.3/subfolder'
)
);
} }
} }

View File

@ -107,51 +107,69 @@ class DocumentationManifestTests extends SapphireTest
{ {
// get next page at the end of one subfolder goes back up to the top // get next page at the end of one subfolder goes back up to the top
// most directory // most directory
$this->assertStringEndsWith('2.3/test/', $this->manifest->getNextPage( $this->assertStringEndsWith(
DOCSVIEWER_PATH . '/tests/docs/en/subfolder/subsubfolder/subsubpage.md', '2.3/test/',
DOCSVIEWER_PATH . '/tests/docs/en/' $this->manifest->getNextPage(
)->Link); DOCSVIEWER_PATH . '/tests/docs/en/subfolder/subsubfolder/subsubpage.md',
DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link
);
// after sorting, 2 is shown. // after sorting, 2 is shown.
$this->assertContains('/intermediate/', $this->manifest->getNextPage( $this->assertContains(
DOCSVIEWER_PATH . '/tests/docs/en/sort/01-basic.md', '/intermediate/',
DOCSVIEWER_PATH . '/tests/docs/en/' $this->manifest->getNextPage(
)->Link); DOCSVIEWER_PATH . '/tests/docs/en/sort/01-basic.md',
DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link
);
// next gets the following URL // next gets the following URL
$this->assertContains('/test/', $this->manifest->getNextPage( $this->assertContains(
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/index.md', '/test/',
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/' $this->manifest->getNextPage(
)->Link); DOCSVIEWER_PATH . '/tests/docs-v2.4/en/index.md',
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/'
)->Link
);
// last folder in a entity does not leak // last folder in a entity does not leak
$this->assertNull($this->manifest->getNextPage( $this->assertNull(
DOCSVIEWER_PATH . '/tests/docs/en/test.md', $this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/test.md',
)); DOCSVIEWER_PATH . '/tests/docs/en/'
)
);
} }
public function testGetPreviousPage() public function testGetPreviousPage()
{ {
// goes right into subfolders // goes right into subfolders
$this->assertContains('subfolder/subsubfolder/subsubpage', $this->manifest->getPreviousPage( $this->assertContains(
DOCSVIEWER_PATH . '/tests/docs/en/test.md', 'subfolder/subsubfolder/subsubpage',
DOCSVIEWER_PATH . '/tests/docs/en/' $this->manifest->getPreviousPage(
)->Link); DOCSVIEWER_PATH . '/tests/docs/en/test.md',
DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link
);
// does not leak between entities // does not leak between entities
$this->assertNull($this->manifest->getPreviousPage( $this->assertNull(
DOCSVIEWER_PATH . '/tests/docs/en/index.md', $this->manifest->getPreviousPage(
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/index.md',
)); DOCSVIEWER_PATH . '/tests/docs/en/'
)
);
// does not leak between entities // does not leak between entities
$this->assertNull($this->manifest->getPreviousPage( $this->assertNull(
DOCSVIEWER_PATH . ' /tests/docs/en/index.md', $this->manifest->getPreviousPage(
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . ' /tests/docs/en/index.md',
)); DOCSVIEWER_PATH . '/tests/docs/en/'
)
);
} }
public function testGetPage() public function testGetPage()
@ -170,9 +188,11 @@ class DocumentationManifestTests extends SapphireTest
array('Title' => 'Test', 'LinkingMode' => 'link') array('Title' => 'Test', 'LinkingMode' => 'link')
); );
$this->assertDOSContains($expected, $this->manifest->getChildrenFor( $this->assertDOSContains(
DOCSVIEWER_PATH . "/tests/docs/en/" $expected, $this->manifest->getChildrenFor(
)); DOCSVIEWER_PATH . '/tests/docs/en/'
)
);
$expected = array( $expected = array(
array('Title' => 'ChangeLog', 'LinkingMode' => 'current'), array('Title' => 'ChangeLog', 'LinkingMode' => 'current'),
@ -180,10 +200,13 @@ class DocumentationManifestTests extends SapphireTest
array('Title' => 'Empty') array('Title' => 'Empty')
); );
$this->assertDOSContains($expected, $this->manifest->getChildrenFor( $this->assertDOSContains(
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/', $expected,
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/ChangeLog.md' $this->manifest->getChildrenFor(
)); DOCSVIEWER_PATH . '/tests/docs-v3.0/en/',
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/ChangeLog.md'
)
);
} }
public function testGetAllVersions() public function testGetAllVersions()

View File

@ -43,7 +43,8 @@ class DocumentationPageTest extends SapphireTest
); );
// single layer // single layer
$this->assertEquals('dev/docs/en/doctest/2.4/test/', $page->Link(), $this->assertEquals(
'dev/docs/en/doctest/2.4/test/', $page->Link(),
'The page link should have no extension and have a language' 'The page link should have no extension and have a language'
); );

View File

@ -212,7 +212,7 @@ HTML;
$this->subPage $this->subPage
); );
# @todo this should redirect to /subpage/ // @todo this should redirect to /subpage/
$this->assertContains( $this->assertContains(
'[link: relative](dev/docs/en/documentationparsertest/2.4/subfolder/subpage.md/)', '[link: relative](dev/docs/en/documentationparsertest/2.4/subfolder/subpage.md/)',
$result $result
@ -223,7 +223,7 @@ HTML;
$result $result
); );
# @todo this should redirect to / // @todo this should redirect to /
$this->assertContains( $this->assertContains(
'[link: absolute index with name](dev/docs/en/documentationparsertest/2.4/index/)', '[link: absolute index with name](dev/docs/en/documentationparsertest/2.4/index/)',
$result $result
@ -304,9 +304,11 @@ HTML;
); );
$this->assertContains( $this->assertContains(
sprintf('[parent image link](%s)', Controller::join_links( sprintf(
Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/_images/image.png' '[parent image link](%s)', Controller::join_links(
)), Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/_images/image.png'
)
),
$result $result
); );
@ -341,17 +343,17 @@ HTML;
array('`[Title](api:DataObject)`','`[Title](api:DataObject)`'), array('`[Title](api:DataObject)`','`[Title](api:DataObject)`'),
array('`[Title](api:DataObject::$defaults)`','`[Title](api:DataObject::$defaults)`'), array('`[Title](api:DataObject::$defaults)`','`[Title](api:DataObject::$defaults)`'),
array('`[Title](api:DataObject::populateDefaults())`','`[Title](api:DataObject::populateDefaults())`'), array('`[Title](api:DataObject::populateDefaults())`','`[Title](api:DataObject::populateDefaults())`'),
array('[api:DataObject]', sprintf($html_format,'DataObject','DataObject')), array('[api:DataObject]', sprintf($html_format, 'DataObject', 'DataObject')),
array('[api:DataObject::$defaults]',sprintf($html_format,'DataObject::$defaults','DataObject::$defaults')), array('[api:DataObject::$defaults]',sprintf($html_format, 'DataObject::$defaults', 'DataObject::$defaults')),
array('[api:DataObject::populateDefaults()]',sprintf($html_format,'DataObject::populateDefaults()','DataObject::populateDefaults()')), array('[api:DataObject::populateDefaults()]',sprintf($html_format, 'DataObject::populateDefaults()', 'DataObject::populateDefaults()')),
array('[Title](api:DataObject)',sprintf($html_format,'DataObject','Title')), array('[Title](api:DataObject)',sprintf($html_format, 'DataObject', 'Title')),
array('[Title](api:DataObject::$defaults)',sprintf($html_format,'DataObject::$defaults','Title')), array('[Title](api:DataObject::$defaults)',sprintf($html_format, 'DataObject::$defaults', 'Title')),
array('[Title](api:DataObject::populateDefaults())',sprintf($html_format,'DataObject::populateDefaults()','Title')) array('[Title](api:DataObject::populateDefaults())',sprintf($html_format, 'DataObject::populateDefaults()', 'Title'))
); );
foreach($test_cases as $test_case) { foreach($test_cases as $test_case) {
$expected_html = $test_case[1]; $expected_html = $test_case[1];
$this->assertContains($expected_html,$parsed_page); $this->assertContains($expected_html, $parsed_page);
} }
} }

View File

@ -9,30 +9,35 @@ class DocumentationPermalinksTest extends FunctionalTest
public function testSavingAndAccessingMapping() public function testSavingAndAccessingMapping()
{ {
// basic test // basic test
DocumentationPermalinks::add(array( DocumentationPermalinks::add(
array(
'foo' => 'en/framework/subfolder/foo', 'foo' => 'en/framework/subfolder/foo',
'bar' => 'en/cms/bar' 'bar' => 'en/cms/bar'
)); )
);
$this->assertEquals('en/framework/subfolder/foo', $this->assertEquals(
'en/framework/subfolder/foo',
DocumentationPermalinks::map('foo') DocumentationPermalinks::map('foo')
); );
$this->assertEquals('en/cms/bar', $this->assertEquals(
'en/cms/bar',
DocumentationPermalinks::map('bar') DocumentationPermalinks::map('bar')
); );
} }
/** /**
* Tests to make sure short codes get translated to full paths. * Tests to make sure short codes get translated to full paths.
*
*/ */
public function testRedirectingMapping() public function testRedirectingMapping()
{ {
DocumentationPermalinks::add(array( DocumentationPermalinks::add(
array(
'foo' => 'en/framework/subfolder/foo', 'foo' => 'en/framework/subfolder/foo',
'bar' => 'en/cms/bar' 'bar' => 'en/cms/bar'
)); )
);
$this->autoFollowRedirection = false; $this->autoFollowRedirection = false;

View File

@ -47,12 +47,12 @@ class DocumentationSearchTest extends FunctionalTest
{ {
$c = new DocumentationOpenSearchController(); $c = new DocumentationOpenSearchController();
$response = $c->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst()); $response = $c->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
// $this->assertEquals(404, $response->getStatusCode()); // $this->assertEquals(404, $response->getStatusCode());
Config::inst()->update('DocumentationSearch', 'enabled', false); Config::inst()->update('DocumentationSearch', 'enabled', false);
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'description/'), DataModel::inst()); $response = $c->handleRequest(new SS_HTTPRequest('GET', 'description/'), DataModel::inst());
// $this->assertEquals(404, $response->getStatusCode()); // $this->assertEquals(404, $response->getStatusCode());
// test we get a response to the description. The meta data test will // test we get a response to the description. The meta data test will
// check that the individual fields are valid but we should check urls // check that the individual fields are valid but we should check urls
@ -61,9 +61,9 @@ class DocumentationSearchTest extends FunctionalTest
Config::inst()->update('DocumentationSearch', 'enabled', true); Config::inst()->update('DocumentationSearch', 'enabled', true);
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'description'), DataModel::inst()); $response = $c->handleRequest(new SS_HTTPRequest('GET', 'description'), DataModel::inst());
// $this->assertEquals(200, $response->getStatusCode()); // $this->assertEquals(200, $response->getStatusCode());
$desc = new SimpleXMLElement($response->getBody()); $desc = new SimpleXMLElement($response->getBody());
// $this->assertEquals(2, count($desc->Url)); // $this->assertEquals(2, count($desc->Url));
} }
} }

View File

@ -4,7 +4,7 @@
* Some of these tests are simply checking that pages load. They should not assume * Some of these tests are simply checking that pages load. They should not assume
* somethings working. * somethings working.
* *
* @package docsviewer * @package docsviewer
* @subpackage tests * @subpackage tests
*/ */

View File

@ -68,21 +68,21 @@ class DocumentationViewerVersionWarningTest extends SapphireTest
// the current version is set to 2.4, no notice should be shown on that page // the current version is set to 2.4, no notice should be shown on that page
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/'), DataModel::inst()); $response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/'), DataModel::inst());
// $this->assertFalse($v->VersionWarning()); // $this->assertFalse($v->VersionWarning());
// 2.3 is an older release, hitting that should return us an outdated flag // 2.3 is an older release, hitting that should return us an outdated flag
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/2.3/'), DataModel::inst()); $response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/2.3/'), DataModel::inst());
$warn = $v->VersionWarning(); $warn = $v->VersionWarning();
// $this->assertTrue($warn->OutdatedRelease); // $this->assertTrue($warn->OutdatedRelease);
// $this->assertNull($warn->FutureRelease); // $this->assertNull($warn->FutureRelease);
// 3.0 is a future release // 3.0 is a future release
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/3.0/'), DataModel::inst()); $response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/testdocs/3.0/'), DataModel::inst());
$warn = $v->VersionWarning(); $warn = $v->VersionWarning();
// $this->assertNull($warn->OutdatedRelease); // $this->assertNull($warn->OutdatedRelease);
// $this->assertTrue($warn->FutureRelease); // $this->assertTrue($warn->FutureRelease);
} }
} }

View File

@ -12,11 +12,11 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search * @package Zend_Search
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
@ -33,5 +33,7 @@ require_once 'Zend/Exception.php';
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Exception extends Zend_Exception class Zend_Search_Exception extends Zend_Exception
{} {
}

View File

@ -12,77 +12,121 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Lucene.php 21640 2010-03-24 18:28:32Z alexander $ * @version $Id: Lucene.php 21640 2010-03-24 18:28:32Z alexander $
*/ */
/** User land classes and interfaces turned on by Zend/Search/Lucene.php file inclusion. */ /**
/** @todo Section should be removed with ZF 2.0 release as obsolete */ * User land classes and interfaces turned on by Zend/Search/Lucene.php file inclusion.
*/
/**
* @todo Section should be removed with ZF 2.0 release as obsolete
*/
/** Zend_Search_Lucene_Document_Html */ /**
* Zend_Search_Lucene_Document_Html
*/
require_once 'Zend/Search/Lucene/Document/Html.php'; require_once 'Zend/Search/Lucene/Document/Html.php';
/** Zend_Search_Lucene_Document_Docx */ /**
* Zend_Search_Lucene_Document_Docx
*/
require_once 'Zend/Search/Lucene/Document/Docx.php'; require_once 'Zend/Search/Lucene/Document/Docx.php';
/** Zend_Search_Lucene_Document_Pptx */ /**
* Zend_Search_Lucene_Document_Pptx
*/
require_once 'Zend/Search/Lucene/Document/Pptx.php'; require_once 'Zend/Search/Lucene/Document/Pptx.php';
/** Zend_Search_Lucene_Document_Xlsx */ /**
* Zend_Search_Lucene_Document_Xlsx
*/
require_once 'Zend/Search/Lucene/Document/Xlsx.php'; require_once 'Zend/Search/Lucene/Document/Xlsx.php';
/** Zend_Search_Lucene_Search_QueryParser */ /**
* Zend_Search_Lucene_Search_QueryParser
*/
require_once 'Zend/Search/Lucene/Search/QueryParser.php'; require_once 'Zend/Search/Lucene/Search/QueryParser.php';
/** Zend_Search_Lucene_Search_QueryHit */ /**
* Zend_Search_Lucene_Search_QueryHit
*/
require_once 'Zend/Search/Lucene/Search/QueryHit.php'; require_once 'Zend/Search/Lucene/Search/QueryHit.php';
/** Zend_Search_Lucene_Analysis_Analyzer */ /**
* Zend_Search_Lucene_Analysis_Analyzer
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
/** Zend_Search_Lucene_Search_Query_Term */ /**
* Zend_Search_Lucene_Search_Query_Term
*/
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; require_once 'Zend/Search/Lucene/Search/Query/Term.php';
/** Zend_Search_Lucene_Search_Query_Phrase */ /**
* Zend_Search_Lucene_Search_Query_Phrase
*/
require_once 'Zend/Search/Lucene/Search/Query/Phrase.php'; require_once 'Zend/Search/Lucene/Search/Query/Phrase.php';
/** Zend_Search_Lucene_Search_Query_MultiTerm */ /**
* Zend_Search_Lucene_Search_Query_MultiTerm
*/
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
/** Zend_Search_Lucene_Search_Query_Wildcard */ /**
* Zend_Search_Lucene_Search_Query_Wildcard
*/
require_once 'Zend/Search/Lucene/Search/Query/Wildcard.php'; require_once 'Zend/Search/Lucene/Search/Query/Wildcard.php';
/** Zend_Search_Lucene_Search_Query_Range */ /**
* Zend_Search_Lucene_Search_Query_Range
*/
require_once 'Zend/Search/Lucene/Search/Query/Range.php'; require_once 'Zend/Search/Lucene/Search/Query/Range.php';
/** Zend_Search_Lucene_Search_Query_Fuzzy */ /**
* Zend_Search_Lucene_Search_Query_Fuzzy
*/
require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php'; require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php';
/** Zend_Search_Lucene_Search_Query_Boolean */ /**
* Zend_Search_Lucene_Search_Query_Boolean
*/
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; require_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
/** Zend_Search_Lucene_Search_Query_Empty */ /**
* Zend_Search_Lucene_Search_Query_Empty
*/
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; require_once 'Zend/Search/Lucene/Search/Query/Empty.php';
/** Zend_Search_Lucene_Search_Query_Insignificant */ /**
* Zend_Search_Lucene_Search_Query_Insignificant
*/
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
/** Internally used classes */ /**
* Internally used classes
*/
/** Zend_Search_Lucene_Interface */ /**
* Zend_Search_Lucene_Interface
*/
require_once 'Zend/Search/Lucene/Interface.php'; require_once 'Zend/Search/Lucene/Interface.php';
/** Zend_Search_Lucene_Index_SegmentInfo */ /**
* Zend_Search_Lucene_Index_SegmentInfo
*/
require_once 'Zend/Search/Lucene/Index/SegmentInfo.php'; require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
/** Zend_Search_Lucene_LockManager */ /**
* Zend_Search_Lucene_LockManager
*/
require_once 'Zend/Search/Lucene/LockManager.php'; require_once 'Zend/Search/Lucene/LockManager.php';
@ -200,13 +244,15 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Create index * Create index
* *
* @param mixed $directory * @param mixed $directory
* @return Zend_Search_Lucene_Interface * @return Zend_Search_Lucene_Interface
*/ */
public static function create($directory) public static function create($directory)
{ {
/** Zend_Search_Lucene_Proxy */ /**
require_once 'Zend/Search/Lucene/Proxy.php'; * Zend_Search_Lucene_Proxy
*/
include_once 'Zend/Search/Lucene/Proxy.php';
return new Zend_Search_Lucene_Proxy(new Zend_Search_Lucene($directory, true)); return new Zend_Search_Lucene_Proxy(new Zend_Search_Lucene($directory, true));
} }
@ -214,21 +260,27 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Open index * Open index
* *
* @param mixed $directory * @param mixed $directory
* @return Zend_Search_Lucene_Interface * @return Zend_Search_Lucene_Interface
*/ */
public static function open($directory) public static function open($directory)
{ {
/** Zend_Search_Lucene_Proxy */ /**
require_once 'Zend/Search/Lucene/Proxy.php'; * Zend_Search_Lucene_Proxy
*/
include_once 'Zend/Search/Lucene/Proxy.php';
return new Zend_Search_Lucene_Proxy(new Zend_Search_Lucene($directory, false)); return new Zend_Search_Lucene_Proxy(new Zend_Search_Lucene($directory, false));
} }
/** Generation retrieving counter */ /**
* Generation retrieving counter
*/
const GENERATION_RETRIEVE_COUNT = 10; const GENERATION_RETRIEVE_COUNT = 10;
/** Pause between generation retrieving attempts in milliseconds */ /**
* Pause between generation retrieving attempts in milliseconds
*/
const GENERATION_RETRIEVE_PAUSE = 50; const GENERATION_RETRIEVE_PAUSE = 50;
/** /**
@ -238,7 +290,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* 0 means pre-2.1 index format * 0 means pre-2.1 index format
* -1 means there are no segments files. * -1 means there are no segments files.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @return integer * @return integer
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -255,7 +307,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* without performance problems * without performance problems
*/ */
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
try { try {
for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) { for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) {
// Try to get generation file // Try to get generation file
@ -319,7 +371,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Get segments file name * Get segments file name
* *
* @param integer $generation * @param integer $generation
* @return string * @return string
*/ */
public static function getSegmentFileName($generation) public static function getSegmentFileName($generation)
@ -345,15 +397,16 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* Set index format version. * Set index format version.
* Index is converted to this format at the nearest upfdate time * Index is converted to this format at the nearest upfdate time
* *
* @param int $formatVersion * @param int $formatVersion
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function setFormatVersion($formatVersion) public function setFormatVersion($formatVersion)
{ {
if ($formatVersion != self::FORMAT_PRE_2_1 && if ($formatVersion != self::FORMAT_PRE_2_1
$formatVersion != self::FORMAT_2_1 && && $formatVersion != self::FORMAT_2_1
$formatVersion != self::FORMAT_2_3) { && $formatVersion != self::FORMAT_2_3
require_once 'Zend/Search/Lucene/Exception.php'; ) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unsupported index format'); throw new Zend_Search_Lucene_Exception('Unsupported index format');
} }
@ -372,7 +425,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$format = $segmentsFile->readInt(); $format = $segmentsFile->readInt();
if ($format != (int)0xFFFFFFFF) { if ($format != (int)0xFFFFFFFF) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wrong segments file format'); throw new Zend_Search_Lucene_Exception('Wrong segments file format');
} }
@ -393,9 +446,11 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$this->_docCount += $segSize; $this->_docCount += $segSize;
$this->_segmentInfos[$segName] = $this->_segmentInfos[$segName] =
new Zend_Search_Lucene_Index_SegmentInfo($this->_directory, new Zend_Search_Lucene_Index_SegmentInfo(
$segName, $this->_directory,
$segSize); $segName,
$segSize
);
} }
// Use 2.1 as a target version. Index will be reorganized at update time. // Use 2.1 as a target version. Index will be reorganized at update time.
@ -418,7 +473,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
} else if ($format == (int)0xFFFFFFFD) { } else if ($format == (int)0xFFFFFFFD) {
$this->_formatVersion = self::FORMAT_2_1; $this->_formatVersion = self::FORMAT_2_1;
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unsupported segments file format'); throw new Zend_Search_Lucene_Exception('Unsupported segments file format');
} }
@ -466,7 +521,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$normGens[] = $segmentsFile->readLong(); $normGens[] = $segmentsFile->readLong();
} }
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Separate norm files are not supported. Optimize index to use it with Zend_Search_Lucene.'); throw new Zend_Search_Lucene_Exception('Separate norm files are not supported. Optimize index to use it with Zend_Search_Lucene.');
} }
@ -486,13 +541,15 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$this->_docCount += $segSize; $this->_docCount += $segSize;
$this->_segmentInfos[$segName] = $this->_segmentInfos[$segName] =
new Zend_Search_Lucene_Index_SegmentInfo($this->_directory, new Zend_Search_Lucene_Index_SegmentInfo(
$segName, $this->_directory,
$segSize, $segName,
$delGen, $segSize,
$docStoreOptions, $delGen,
$hasSingleNormFile, $docStoreOptions,
$isCompound); $hasSingleNormFile,
$isCompound
);
} }
} }
@ -502,18 +559,18 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* IndexReader constructor needs Directory as a parameter. It should be * IndexReader constructor needs Directory as a parameter. It should be
* a string with a path to the index folder or a Directory object. * a string with a path to the index folder or a Directory object.
* *
* @param Zend_Search_Lucene_Storage_Directory_Filesystem|string $directory * @param Zend_Search_Lucene_Storage_Directory_Filesystem|string $directory
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct($directory = null, $create = false) public function __construct($directory = null, $create = false)
{ {
if ($directory === null) { if ($directory === null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Exception('No index directory specified'); throw new Zend_Search_Exception('No index directory specified');
} }
if (is_string($directory)) { if (is_string($directory)) {
require_once 'Zend/Search/Lucene/Storage/Directory/Filesystem.php'; include_once 'Zend/Search/Lucene/Storage/Directory/Filesystem.php';
$this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory); $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
$this->_closeDirOnExit = true; $this->_closeDirOnExit = true;
} else { } else {
@ -529,7 +586,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$this->_generation = self::getActualGeneration($this->_directory); $this->_generation = self::getActualGeneration($this->_directory);
if ($create) { if ($create) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
try { try {
Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory); Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
} catch (Zend_Search_Lucene_Exception $e) { } catch (Zend_Search_Lucene_Exception $e) {
@ -555,14 +612,14 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$this->_generation++; $this->_generation++;
} }
require_once 'Zend/Search/Lucene/Index/Writer.php'; include_once 'Zend/Search/Lucene/Index/Writer.php';
Zend_Search_Lucene_Index_Writer::createIndex($this->_directory, $this->_generation, $nameCounter); Zend_Search_Lucene_Index_Writer::createIndex($this->_directory, $this->_generation, $nameCounter);
Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory); Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
} }
if ($this->_generation == -1) { if ($this->_generation == -1) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Index doesn\'t exists in the specified directory.'); throw new Zend_Search_Lucene_Exception('Index doesn\'t exists in the specified directory.');
} else if ($this->_generation == 0) { } else if ($this->_generation == 0) {
$this->_readPre21SegmentsFile(); $this->_readPre21SegmentsFile();
@ -639,10 +696,12 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
private function _getIndexWriter() private function _getIndexWriter()
{ {
if ($this->_writer === null) { if ($this->_writer === null) {
require_once 'Zend/Search/Lucene/Index/Writer.php'; include_once 'Zend/Search/Lucene/Index/Writer.php';
$this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, $this->_writer = new Zend_Search_Lucene_Index_Writer(
$this->_segmentInfos, $this->_directory,
$this->_formatVersion); $this->_segmentInfos,
$this->_formatVersion
);
} }
return $this->_writer; return $this->_writer;
@ -701,14 +760,14 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Checks, that document is deleted * Checks, that document is deleted
* *
* @param integer $id * @param integer $id
* @return boolean * @return boolean
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/ */
public function isDeleted($id) public function isDeleted($id)
{ {
if ($id >= $this->_docCount) { if ($id >= $this->_docCount) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
} }
@ -911,20 +970,20 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* of Zend_Search_Lucene_Search_QueryHit objects. * of Zend_Search_Lucene_Search_QueryHit objects.
* Input is a string or Zend_Search_Lucene_Search_Query. * Input is a string or Zend_Search_Lucene_Search_Query.
* *
* @param Zend_Search_Lucene_Search_QueryParser|string $query * @param Zend_Search_Lucene_Search_QueryParser|string $query
* @return array Zend_Search_Lucene_Search_QueryHit * @return array Zend_Search_Lucene_Search_QueryHit
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function find($query) public function find($query)
{ {
if (is_string($query)) { if (is_string($query)) {
require_once 'Zend/Search/Lucene/Search/QueryParser.php'; include_once 'Zend/Search/Lucene/Search/QueryParser.php';
$query = Zend_Search_Lucene_Search_QueryParser::parse($query); $query = Zend_Search_Lucene_Search_QueryParser::parse($query);
} }
if (!$query instanceof Zend_Search_Lucene_Search_Query) { if (!$query instanceof Zend_Search_Lucene_Search_Query) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object'); throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object');
} }
@ -940,12 +999,14 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$topScore = 0; $topScore = 0;
/** Zend_Search_Lucene_Search_QueryHit */ /**
require_once 'Zend/Search/Lucene/Search/QueryHit.php'; * Zend_Search_Lucene_Search_QueryHit
*/
include_once 'Zend/Search/Lucene/Search/QueryHit.php';
foreach ($query->matchedDocs() as $id => $num) { foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this); $docScore = $query->score($id, $this);
if( $docScore != 0 ) { if($docScore != 0 ) {
$hit = new Zend_Search_Lucene_Search_QueryHit($this); $hit = new Zend_Search_Lucene_Search_QueryHit($this);
$hit->id = $id; $hit->id = $id;
$hit->score = $docScore; $hit->score = $docScore;
@ -977,9 +1038,11 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
if (func_num_args() == 1) { if (func_num_args() == 1) {
// sort by scores // sort by scores
array_multisort($scores, SORT_DESC, SORT_NUMERIC, array_multisort(
$ids, SORT_ASC, SORT_NUMERIC, $scores, SORT_DESC, SORT_NUMERIC,
$hits); $ids, SORT_ASC, SORT_NUMERIC,
$hits
);
} else { } else {
// sort by given field names // sort by given field names
@ -996,7 +1059,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$sortFieldValues = array(); $sortFieldValues = array();
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
for ($count = 1; $count < count($argList); $count++) { for ($count = 1; $count < count($argList); $count++) {
$fieldName = $argList[$count]; $fieldName = $argList[$count];
@ -1075,7 +1138,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Returns a list of all unique field names that exist in this index. * Returns a list of all unique field names that exist in this index.
* *
* @param boolean $indexed * @param boolean $indexed
* @return array * @return array
*/ */
public function getFieldNames($indexed = false) public function getFieldNames($indexed = false)
@ -1092,7 +1155,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* Returns a Zend_Search_Lucene_Document object for the document * Returns a Zend_Search_Lucene_Document object for the document
* number $id in this index. * number $id in this index.
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @return Zend_Search_Lucene_Document * @return Zend_Search_Lucene_Document
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/ */
@ -1104,7 +1167,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
} }
if ($id >= $this->_docCount) { if ($id >= $this->_docCount) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
} }
@ -1133,20 +1196,24 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$fieldInfo = $segmentInfo->getField($fieldNum); $fieldInfo = $segmentInfo->getField($fieldNum);
if (!($bits & 2)) { // Text data if (!($bits & 2)) { // Text data
$field = new Zend_Search_Lucene_Field($fieldInfo->name, $field = new Zend_Search_Lucene_Field(
$fdtFile->readString(), $fieldInfo->name,
'UTF-8', $fdtFile->readString(),
true, 'UTF-8',
$fieldInfo->isIndexed, true,
$bits & 1 ); $fieldInfo->isIndexed,
$bits & 1
);
} else { // Binary data } else { // Binary data
$field = new Zend_Search_Lucene_Field($fieldInfo->name, $field = new Zend_Search_Lucene_Field(
$fdtFile->readBinary(), $fieldInfo->name,
'', $fdtFile->readBinary(),
true, '',
$fieldInfo->isIndexed, true,
$bits & 1, $fieldInfo->isIndexed,
true ); $bits & 1,
true
);
} }
$doc->addField($field); $doc->addField($field);
@ -1161,7 +1228,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* *
* Is used for query optimization. * Is used for query optimization.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return boolean * @return boolean
*/ */
public function hasTerm(Zend_Search_Lucene_Index_Term $term) public function hasTerm(Zend_Search_Lucene_Index_Term $term)
@ -1178,8 +1245,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Returns IDs of all documents containing term. * Returns IDs of all documents containing term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
*/ */
public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -1212,8 +1279,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* It performs the same operation as termDocs, but return result as * It performs the same operation as termDocs, but return result as
* Zend_Search_Lucene_Index_DocsFilter object * Zend_Search_Lucene_Index_DocsFilter object
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return Zend_Search_Lucene_Index_DocsFilter * @return Zend_Search_Lucene_Index_DocsFilter
*/ */
public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -1245,8 +1312,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* Returns an array of all term freqs. * Returns an array of all term freqs.
* Result array structure: array(docId => freq, ...) * Result array structure: array(docId => freq, ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return integer * @return integer
*/ */
public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -1266,8 +1333,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* Returns an array of all term positions in the documents. * Returns an array of all term positions in the documents.
* Result array structure: array(docId => array(pos1, pos2, ...), ...) * Result array structure: array(docId => array(pos1, pos2, ...), ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
*/ */
public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -1287,7 +1354,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Returns the number of documents in this index containing the $term. * Returns the number of documents in this index containing the $term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return integer * @return integer
*/ */
public function docFreq(Zend_Search_Lucene_Index_Term $term) public function docFreq(Zend_Search_Lucene_Index_Term $term)
@ -1311,8 +1378,10 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/ */
public function getSimilarity() public function getSimilarity()
{ {
/** Zend_Search_Lucene_Search_Similarity */ /**
require_once 'Zend/Search/Lucene/Search/Similarity.php'; * Zend_Search_Lucene_Search_Similarity
*/
include_once 'Zend/Search/Lucene/Search/Similarity.php';
return Zend_Search_Lucene_Search_Similarity::getDefault(); return Zend_Search_Lucene_Search_Similarity::getDefault();
} }
@ -1321,8 +1390,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/** /**
* Returns a normalization factor for "field, document" pair. * Returns a normalization factor for "field, document" pair.
* *
* @param integer $id * @param integer $id
* @param string $fieldName * @param string $fieldName
* @return float * @return float
*/ */
public function norm($id, $fieldName) public function norm($id, $fieldName)
@ -1368,7 +1437,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* Deletes a document from the index. * Deletes a document from the index.
* $id is an internal document id * $id is an internal document id
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function delete($id) public function delete($id)
@ -1379,7 +1448,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
} }
if ($id >= $this->_docCount) { if ($id >= $this->_docCount) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
} }
@ -1466,8 +1535,10 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
{ {
$result = array(); $result = array();
/** Zend_Search_Lucene_Index_TermsPriorityQueue */ /**
require_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php'; * Zend_Search_Lucene_Index_TermsPriorityQueue
*/
include_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php';
$segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue(); $segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
@ -1481,9 +1552,9 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
} }
while (($segmentInfo = $segmentInfoQueue->pop()) !== null) { while (($segmentInfo = $segmentInfoQueue->pop()) !== null) {
if ($segmentInfoQueue->top() === null || if ($segmentInfoQueue->top() === null
$segmentInfoQueue->top()->currentTerm()->key() != || $segmentInfoQueue->top()->currentTerm()->key() != $segmentInfo->currentTerm()->key()
$segmentInfo->currentTerm()->key()) { ) {
// We got new term // We got new term
$result[] = $segmentInfo->currentTerm(); $result[] = $segmentInfo->currentTerm();
} }
@ -1511,8 +1582,10 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
public function resetTermsStream() public function resetTermsStream()
{ {
if ($this->_termsStream === null) { if ($this->_termsStream === null) {
/** Zend_Search_Lucene_TermStreamsPriorityQueue */ /**
require_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php'; * Zend_Search_Lucene_TermStreamsPriorityQueue
*/
include_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php';
$this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_segmentInfos); $this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_segmentInfos);
} else { } else {
@ -1573,5 +1646,6 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* @todo Implementation * @todo Implementation
*/ */
public function undeleteAll() public function undeleteAll()
{} {
}
} }

View File

@ -21,32 +21,52 @@
*/ */
/** User land classes and interfaces turned on by Zend/Search/Analyzer.php file inclusion. */ /**
/** @todo Section should be removed with ZF 2.0 release as obsolete */ * User land classes and interfaces turned on by Zend/Search/Analyzer.php file inclusion.
*/
/**
* @todo Section should be removed with ZF 2.0 release as obsolete
*/
if (!defined('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED')) { if (!defined('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED')) {
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8 */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8/CaseInsensitive.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8/CaseInsensitive.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num/CaseInsensitive.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num/CaseInsensitive.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Text */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Text
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php';
/** Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php';
} }
@ -96,7 +116,7 @@ abstract class Zend_Search_Lucene_Analysis_Analyzer
* *
* Tokens are returned in UTF-8 (internal Zend_Search_Lucene encoding) * Tokens are returned in UTF-8 (internal Zend_Search_Lucene encoding)
* *
* @param string $data * @param string $data
* @return array * @return array
*/ */
public function tokenize($data, $encoding = '') public function tokenize($data, $encoding = '')
@ -162,8 +182,10 @@ abstract class Zend_Search_Lucene_Analysis_Analyzer
*/ */
public static function getDefault() public static function getDefault()
{ {
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php'; * Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php';
if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Analysis_Analyzer) { if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Analysis_Analyzer) {
self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive(); self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive();

View File

@ -21,18 +21,28 @@
*/ */
/** Define constant used to provide correct file processing order */ /**
/** @todo Section should be removed with ZF 2.0 release as obsolete */ * Define constant used to provide correct file processing order
*/
/**
* @todo Section should be removed with ZF 2.0 release as obsolete
*/
define('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED', true); define('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED', true);
/** Zend_Search_Lucene_Analysis_Analyzer */ /**
* Zend_Search_Lucene_Analysis_Analyzer
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
/** Zend_Search_Lucene_Analysis_Token */ /**
* Zend_Search_Lucene_Analysis_Token
*/
require_once 'Zend/Search/Lucene/Analysis/Token.php'; require_once 'Zend/Search/Lucene/Analysis/Token.php';
/** Zend_Search_Lucene_Analysis_TokenFilter */ /**
* Zend_Search_Lucene_Analysis_TokenFilter
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
@ -72,7 +82,7 @@ abstract class Zend_Search_Lucene_Analysis_Analyzer_Common extends Zend_Search_L
/** /**
* Apply filters to the token. Can return null when the token was removed. * Apply filters to the token. Can return null when the token was removed.
* *
* @param Zend_Search_Lucene_Analysis_Token $token * @param Zend_Search_Lucene_Analysis_Token $token
* @return Zend_Search_Lucene_Analysis_Token * @return Zend_Search_Lucene_Analysis_Token
*/ */
public function normalize(Zend_Search_Lucene_Analysis_Token $token) public function normalize(Zend_Search_Lucene_Analysis_Token $token)

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';

View File

@ -21,10 +21,14 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Text */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common_Text
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php';
/** Zend_Search_Lucene_Analysis_TokenFilter_LowerCase */ /**
* Zend_Search_Lucene_Analysis_TokenFilter_LowerCase
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php';

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';

View File

@ -21,10 +21,14 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php';
/** Zend_Search_Lucene_Analysis_TokenFilter_LowerCase */ /**
* Zend_Search_Lucene_Analysis_TokenFilter_LowerCase
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php';

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
@ -58,7 +60,7 @@ class Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8 extends Zend_Search_Lucen
{ {
if (@preg_match('/\pL/u', 'a') != 1) { if (@preg_match('/\pL/u', 'a') != 1) {
// PCRE unicode support is turned off // PCRE unicode support is turned off
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Utf8 analyzer needs PCRE unicode support to be enabled.'); throw new Zend_Search_Lucene_Exception('Utf8 analyzer needs PCRE unicode support to be enabled.');
} }
} }
@ -72,8 +74,9 @@ class Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8 extends Zend_Search_Lucen
$this->_bytePosition = 0; $this->_bytePosition = 0;
// convert input into UTF-8 // convert input into UTF-8
if (strcasecmp($this->_encoding, 'utf8' ) != 0 && if (strcasecmp($this->_encoding, 'utf8') != 0
strcasecmp($this->_encoding, 'utf-8') != 0 ) { && strcasecmp($this->_encoding, 'utf-8') != 0
) {
$this->_input = iconv($this->_encoding, 'UTF-8', $this->_input); $this->_input = iconv($this->_encoding, 'UTF-8', $this->_input);
$this->_encoding = 'UTF-8'; $this->_encoding = 'UTF-8';
} }
@ -107,10 +110,14 @@ class Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8 extends Zend_Search_Lucen
// character position of the matched word in the input stream // character position of the matched word in the input stream
$startPos = $this->_position + $startPos = $this->_position +
iconv_strlen(substr($this->_input, iconv_strlen(
$this->_bytePosition, substr(
$binStartPos - $this->_bytePosition), $this->_input,
'UTF-8'); $this->_bytePosition,
$binStartPos - $this->_bytePosition
),
'UTF-8'
);
// character postion of the end of matched word in the input stream // character postion of the end of matched word in the input stream
$endPos = $startPos + iconv_strlen($matchedWord, 'UTF-8'); $endPos = $startPos + iconv_strlen($matchedWord, 'UTF-8');

View File

@ -21,10 +21,14 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8 */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php';
/** Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8 */ /**
* Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCaseUtf8.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCaseUtf8.php';

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
@ -58,7 +60,7 @@ class Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num extends Zend_Search_Lu
{ {
if (@preg_match('/\pL/u', 'a') != 1) { if (@preg_match('/\pL/u', 'a') != 1) {
// PCRE unicode support is turned off // PCRE unicode support is turned off
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Utf8Num analyzer needs PCRE unicode support to be enabled.'); throw new Zend_Search_Lucene_Exception('Utf8Num analyzer needs PCRE unicode support to be enabled.');
} }
} }
@ -72,8 +74,9 @@ class Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num extends Zend_Search_Lu
$this->_bytePosition = 0; $this->_bytePosition = 0;
// convert input into UTF-8 // convert input into UTF-8
if (strcasecmp($this->_encoding, 'utf8' ) != 0 && if (strcasecmp($this->_encoding, 'utf8') != 0
strcasecmp($this->_encoding, 'utf-8') != 0 ) { && strcasecmp($this->_encoding, 'utf-8') != 0
) {
$this->_input = iconv($this->_encoding, 'UTF-8', $this->_input); $this->_input = iconv($this->_encoding, 'UTF-8', $this->_input);
$this->_encoding = 'UTF-8'; $this->_encoding = 'UTF-8';
} }
@ -107,10 +110,14 @@ class Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num extends Zend_Search_Lu
// character position of the matched word in the input stream // character position of the matched word in the input stream
$startPos = $this->_position + $startPos = $this->_position +
iconv_strlen(substr($this->_input, iconv_strlen(
$this->_bytePosition, substr(
$binStartPos - $this->_bytePosition), $this->_input,
'UTF-8'); $this->_bytePosition,
$binStartPos - $this->_bytePosition
),
'UTF-8'
);
// character postion of the end of matched word in the input stream // character postion of the end of matched word in the input stream
$endPos = $startPos + iconv_strlen($matchedWord, 'UTF-8'); $endPos = $startPos + iconv_strlen($matchedWord, 'UTF-8');

View File

@ -21,10 +21,14 @@
*/ */
/** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num */ /**
* Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php';
/** Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8 */ /**
* Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCaseUtf8.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCaseUtf8.php';

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_Token */ /**
* Zend_Search_Lucene_Analysis_Token
*/
require_once 'Zend/Search/Lucene/Analysis/Token.php'; require_once 'Zend/Search/Lucene/Analysis/Token.php';
@ -39,7 +41,7 @@ abstract class Zend_Search_Lucene_Analysis_TokenFilter
/** /**
* Normalize Token or remove it (if null is returned) * Normalize Token or remove it (if null is returned)
* *
* @param Zend_Search_Lucene_Analysis_Token $srcToken * @param Zend_Search_Lucene_Analysis_Token $srcToken
* @return Zend_Search_Lucene_Analysis_Token * @return Zend_Search_Lucene_Analysis_Token
*/ */
abstract public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken); abstract public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken);

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_TokenFilter */ /**
* Zend_Search_Lucene_Analysis_TokenFilter
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
@ -40,15 +42,16 @@ class Zend_Search_Lucene_Analysis_TokenFilter_LowerCase extends Zend_Search_Luce
/** /**
* Normalize Token or remove it (if null is returned) * Normalize Token or remove it (if null is returned)
* *
* @param Zend_Search_Lucene_Analysis_Token $srcToken * @param Zend_Search_Lucene_Analysis_Token $srcToken
* @return Zend_Search_Lucene_Analysis_Token * @return Zend_Search_Lucene_Analysis_Token
*/ */
public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken) public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken)
{ {
$newToken = new Zend_Search_Lucene_Analysis_Token( $newToken = new Zend_Search_Lucene_Analysis_Token(
strtolower( $srcToken->getTermText() ), strtolower($srcToken->getTermText()),
$srcToken->getStartOffset(), $srcToken->getStartOffset(),
$srcToken->getEndOffset()); $srcToken->getEndOffset()
);
$newToken->setPositionIncrement($srcToken->getPositionIncrement()); $newToken->setPositionIncrement($srcToken->getPositionIncrement());

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_TokenFilter */ /**
* Zend_Search_Lucene_Analysis_TokenFilter
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
@ -44,7 +46,7 @@ class Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8 extends Zend_Search_
{ {
if (!function_exists('mb_strtolower')) { if (!function_exists('mb_strtolower')) {
// mbstring extension is disabled // mbstring extension is disabled
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Utf8 compatible lower case filter needs mbstring extension to be enabled.'); throw new Zend_Search_Lucene_Exception('Utf8 compatible lower case filter needs mbstring extension to be enabled.');
} }
} }
@ -52,15 +54,16 @@ class Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8 extends Zend_Search_
/** /**
* Normalize Token or remove it (if null is returned) * Normalize Token or remove it (if null is returned)
* *
* @param Zend_Search_Lucene_Analysis_Token $srcToken * @param Zend_Search_Lucene_Analysis_Token $srcToken
* @return Zend_Search_Lucene_Analysis_Token * @return Zend_Search_Lucene_Analysis_Token
*/ */
public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken) public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken)
{ {
$newToken = new Zend_Search_Lucene_Analysis_Token( $newToken = new Zend_Search_Lucene_Analysis_Token(
mb_strtolower($srcToken->getTermText(), 'UTF-8'), mb_strtolower($srcToken->getTermText(), 'UTF-8'),
$srcToken->getStartOffset(), $srcToken->getStartOffset(),
$srcToken->getEndOffset()); $srcToken->getEndOffset()
);
$newToken->setPositionIncrement($srcToken->getPositionIncrement()); $newToken->setPositionIncrement($srcToken->getPositionIncrement());

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Analysis_TokenFilter */ /**
* Zend_Search_Lucene_Analysis_TokenFilter
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
@ -39,6 +41,7 @@ class Zend_Search_Lucene_Analysis_TokenFilter_ShortWords extends Zend_Search_Luc
{ {
/** /**
* Minimum allowed term length * Minimum allowed term length
*
* @var integer * @var integer
*/ */
private $length; private $length;
@ -46,19 +49,21 @@ class Zend_Search_Lucene_Analysis_TokenFilter_ShortWords extends Zend_Search_Luc
/** /**
* Constructs new instance of this filter. * Constructs new instance of this filter.
* *
* @param integer $short minimum allowed length of term which passes this filter (default 2) * @param integer $short minimum allowed length of term which passes this filter (default 2)
*/ */
public function __construct($length = 2) { public function __construct($length = 2)
{
$this->length = $length; $this->length = $length;
} }
/** /**
* Normalize Token or remove it (if null is returned) * Normalize Token or remove it (if null is returned)
* *
* @param Zend_Search_Lucene_Analysis_Token $srcToken * @param Zend_Search_Lucene_Analysis_Token $srcToken
* @return Zend_Search_Lucene_Analysis_Token * @return Zend_Search_Lucene_Analysis_Token
*/ */
public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken) { public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken)
{
if (strlen($srcToken->getTermText()) < $this->length) { if (strlen($srcToken->getTermText()) < $this->length) {
return null; return null;
} else { } else {

View File

@ -20,7 +20,9 @@
* @version $Id: StopWords.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: StopWords.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Analysis_TokenFilter */ /**
* Zend_Search_Lucene_Analysis_TokenFilter
*/
require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php'; require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
/** /**
@ -40,6 +42,7 @@ class Zend_Search_Lucene_Analysis_TokenFilter_StopWords extends Zend_Search_Luce
{ {
/** /**
* Stop Words * Stop Words
*
* @var array * @var array
*/ */
private $_stopSet; private $_stopSet;
@ -49,17 +52,19 @@ class Zend_Search_Lucene_Analysis_TokenFilter_StopWords extends Zend_Search_Luce
* *
* @param array $stopwords array (set) of words that will be filtered out * @param array $stopwords array (set) of words that will be filtered out
*/ */
public function __construct($stopwords = array()) { public function __construct($stopwords = array())
{
$this->_stopSet = array_flip($stopwords); $this->_stopSet = array_flip($stopwords);
} }
/** /**
* Normalize Token or remove it (if null is returned) * Normalize Token or remove it (if null is returned)
* *
* @param Zend_Search_Lucene_Analysis_Token $srcToken * @param Zend_Search_Lucene_Analysis_Token $srcToken
* @return Zend_Search_Lucene_Analysis_Token * @return Zend_Search_Lucene_Analysis_Token
*/ */
public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken) { public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken)
{
if (array_key_exists($srcToken->getTermText(), $this->_stopSet)) { if (array_key_exists($srcToken->getTermText(), $this->_stopSet)) {
return null; return null;
} else { } else {
@ -73,27 +78,28 @@ class Zend_Search_Lucene_Analysis_TokenFilter_StopWords extends Zend_Search_Luce
* *
* You can call this method one or more times. New stopwords are always added to current set. * You can call this method one or more times. New stopwords are always added to current set.
* *
* @param string $filepath full path for text file with stopwords * @param string $filepath full path for text file with stopwords
* @throws Zend_Search_Exception When the file doesn`t exists or is not readable. * @throws Zend_Search_Exception When the file doesn`t exists or is not readable.
*/ */
public function loadFromFile($filepath = null) { public function loadFromFile($filepath = null)
{
if (! $filepath || ! file_exists($filepath)) { if (! $filepath || ! file_exists($filepath)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('You have to provide valid file path'); throw new Zend_Search_Lucene_Exception('You have to provide valid file path');
} }
$fd = fopen($filepath, "r"); $fd = fopen($filepath, "r");
if (! $fd) { if (! $fd) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Cannot open file ' . $filepath); throw new Zend_Search_Lucene_Exception('Cannot open file ' . $filepath);
} }
while (!feof ($fd)) { while (!feof($fd)) {
$buffer = trim(fgets($fd)); $buffer = trim(fgets($fd));
if (strlen($buffer) > 0 && $buffer[0] != '#') { if (strlen($buffer) > 0 && $buffer[0] != '#') {
$this->_stopSet[$buffer] = 1; $this->_stopSet[$buffer] = 1;
} }
} }
if (!fclose($fd)) { if (!fclose($fd)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Cannot close file ' . $filepath); throw new Zend_Search_Lucene_Exception('Cannot close file ' . $filepath);
} }
} }

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Field */ /**
* Zend_Search_Lucene_Field
*/
require_once 'Zend/Search/Lucene/Field.php'; require_once 'Zend/Search/Lucene/Field.php';
@ -69,7 +71,7 @@ class Zend_Search_Lucene_Document
/** /**
* Add a field object to this document. * Add a field object to this document.
* *
* @param Zend_Search_Lucene_Field $field * @param Zend_Search_Lucene_Field $field
* @return Zend_Search_Lucene_Document * @return Zend_Search_Lucene_Document
*/ */
public function addField(Zend_Search_Lucene_Field $field) public function addField(Zend_Search_Lucene_Field $field)
@ -94,13 +96,13 @@ class Zend_Search_Lucene_Document
/** /**
* Returns Zend_Search_Lucene_Field object for a named field in this document. * Returns Zend_Search_Lucene_Field object for a named field in this document.
* *
* @param string $fieldName * @param string $fieldName
* @return Zend_Search_Lucene_Field * @return Zend_Search_Lucene_Field
*/ */
public function getField($fieldName) public function getField($fieldName)
{ {
if (!array_key_exists($fieldName, $this->_fields)) { if (!array_key_exists($fieldName, $this->_fields)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document."); throw new Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document.");
} }
return $this->_fields[$fieldName]; return $this->_fields[$fieldName];
@ -110,7 +112,7 @@ class Zend_Search_Lucene_Document
/** /**
* Returns the string value of a named field in this document. * Returns the string value of a named field in this document.
* *
* @see __get() * @see __get()
* @return string * @return string
*/ */
public function getFieldValue($fieldName) public function getFieldValue($fieldName)
@ -121,7 +123,7 @@ class Zend_Search_Lucene_Document
/** /**
* Returns the string value of a named field in UTF-8 encoding. * Returns the string value of a named field in UTF-8 encoding.
* *
* @see __get() * @see __get()
* @return string * @return string
*/ */
public function getFieldUtf8Value($fieldName) public function getFieldUtf8Value($fieldName)

View File

@ -20,7 +20,9 @@
* @version $Id: Docx.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Docx.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Document_OpenXml */ /**
* Zend_Search_Lucene_Document_OpenXml
*/
require_once 'Zend/Search/Lucene/Document/OpenXml.php'; require_once 'Zend/Search/Lucene/Document/OpenXml.php';
/** /**
@ -32,7 +34,8 @@ require_once 'Zend/Search/Lucene/Document/OpenXml.php';
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenXml { class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenXml
{
/** /**
* Xml Schema - WordprocessingML * Xml Schema - WordprocessingML
* *
@ -43,13 +46,14 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Object constructor * Object constructor
* *
* @param string $fileName * @param string $fileName
* @param boolean $storeContent * @param boolean $storeContent
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
private function __construct($fileName, $storeContent) { private function __construct($fileName, $storeContent)
{
if (!class_exists('ZipArchive', false)) { if (!class_exists('ZipArchive', false)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('MS Office documents processing functionality requires Zip extension to be loaded'); throw new Zend_Search_Lucene_Exception('MS Office documents processing functionality requires Zip extension to be loaded');
} }
@ -64,18 +68,22 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
// Read relations and search for officeDocument // Read relations and search for officeDocument
$relationsXml = $package->getFromName('_rels/.rels'); $relationsXml = $package->getFromName('_rels/.rels');
if ($relationsXml === false) { if ($relationsXml === false) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .docx file.'); throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .docx file.');
} }
$relations = simplexml_load_string($relationsXml); $relations = simplexml_load_string($relationsXml);
foreach($relations->Relationship as $rel) { foreach($relations->Relationship as $rel) {
if ($rel ["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { if ($rel ["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
// Found office document! Read in contents... // Found office document! Read in contents...
$contents = simplexml_load_string($package->getFromName( $contents = simplexml_load_string(
$this->absoluteZipPath(dirname($rel['Target']) $package->getFromName(
. '/' $this->absoluteZipPath(
. basename($rel['Target'])) dirname($rel['Target'])
)); . '/'
. basename($rel['Target'])
)
)
);
$contents->registerXPathNamespace('w', Zend_Search_Lucene_Document_Docx::SCHEMA_WORDPROCESSINGML); $contents->registerXPathNamespace('w', Zend_Search_Lucene_Document_Docx::SCHEMA_WORDPROCESSINGML);
$paragraphs = $contents->xpath('//w:body/w:p'); $paragraphs = $contents->xpath('//w:body/w:p');
@ -89,12 +97,12 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
} }
foreach ($runs as $run) { foreach ($runs as $run) {
if ($run->getName() == 'br') { if ($run->getName() == 'br') {
// Break element // Break element
$documentBody[] = ' '; $documentBody[] = ' ';
} else { } else {
$documentBody[] = (string)$run; $documentBody[] = (string)$run;
} }
} }
// Add space after each paragraph. So they are not bound together. // Add space after each paragraph. So they are not bound together.
@ -135,14 +143,15 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Load Docx document from a file * Load Docx document from a file
* *
* @param string $fileName * @param string $fileName
* @param boolean $storeContent * @param boolean $storeContent
* @return Zend_Search_Lucene_Document_Docx * @return Zend_Search_Lucene_Document_Docx
* @throws Zend_Search_Lucene_Document_Exception * @throws Zend_Search_Lucene_Document_Exception
*/ */
public static function loadDocxFile($fileName, $storeContent = false) { public static function loadDocxFile($fileName, $storeContent = false)
{
if (!is_readable($fileName)) { if (!is_readable($fileName)) {
require_once 'Zend/Search/Lucene/Document/Exception.php'; include_once 'Zend/Search/Lucene/Document/Exception.php';
throw new Zend_Search_Lucene_Document_Exception('Provided file \'' . $fileName . '\' is not readable.'); throw new Zend_Search_Lucene_Document_Exception('Provided file \'' . $fileName . '\' is not readable.');
} }

View File

@ -12,11 +12,11 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
@ -33,5 +33,7 @@ require_once 'Zend/Search/Lucene/Exception.php';
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_Document_Exception extends Zend_Search_Lucene_Exception class Zend_Search_Lucene_Document_Exception extends Zend_Search_Lucene_Exception
{} {
}

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Document */ /**
* Zend_Search_Lucene_Document
*/
require_once 'Zend/Search/Lucene/Document.php'; require_once 'Zend/Search/Lucene/Document.php';
@ -68,7 +70,6 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
private static $_excludeNoFollowLinks = false; private static $_excludeNoFollowLinks = false;
/** /**
*
* List of inline tags * List of inline tags
* *
* @var array * @var array
@ -81,10 +82,10 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Object constructor * Object constructor
* *
* @param string $data HTML string (may be HTML fragment, ) * @param string $data HTML string (may be HTML fragment, )
* @param boolean $isFile * @param boolean $isFile
* @param boolean $storeContent * @param boolean $storeContent
* @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag. * @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag.
*/ */
private function __construct($data, $isFile, $storeContent, $defaultEncoding = '') private function __construct($data, $isFile, $storeContent, $defaultEncoding = '')
{ {
@ -101,15 +102,19 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
if ($this->_doc->encoding === null) { if ($this->_doc->encoding === null) {
// Document encoding is not recognized // Document encoding is not recognized
/** @todo improve HTML vs HTML fragment recognition */ /**
* @todo improve HTML vs HTML fragment recognition
*/
if (preg_match('/<html>/i', $htmlData, $matches, PREG_OFFSET_CAPTURE)) { if (preg_match('/<html>/i', $htmlData, $matches, PREG_OFFSET_CAPTURE)) {
// It's an HTML document // It's an HTML document
// Add additional HEAD section and recognize document // Add additional HEAD section and recognize document
$htmlTagOffset = $matches[0][1] + strlen($matches[0][0]); $htmlTagOffset = $matches[0][1] + strlen($matches[0][0]);
@$this->_doc->loadHTML(iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, 0, $htmlTagOffset)) @$this->_doc->loadHTML(
iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, 0, $htmlTagOffset))
. '<head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head>' . '<head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head>'
. iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, $htmlTagOffset))); . iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, $htmlTagOffset))
);
// Remove additional HEAD section // Remove additional HEAD section
$xpath = new DOMXPath($this->_doc); $xpath = new DOMXPath($this->_doc);
@ -117,13 +122,16 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
$head->parentNode->removeChild($head); $head->parentNode->removeChild($head);
} else { } else {
// It's an HTML fragment // It's an HTML fragment
@$this->_doc->loadHTML('<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>' @$this->_doc->loadHTML(
'<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>'
. iconv($defaultEncoding, 'UTF-8//IGNORE', $htmlData) . iconv($defaultEncoding, 'UTF-8//IGNORE', $htmlData)
. '</body></html>'); . '</body></html>'
);
} }
} }
/** @todo Add correction of wrong HTML encoding recognition processing /**
* @todo Add correction of wrong HTML encoding recognition processing
* The case is: * The case is:
* Content-type HTTP-EQUIV meta tag is presented, but ISO-8859-5 encoding is actually used, * Content-type HTTP-EQUIV meta tag is presented, but ISO-8859-5 encoding is actually used,
* even $this->_doc->encoding demonstrates another recognized encoding * even $this->_doc->encoding demonstrates another recognized encoding
@ -141,9 +149,13 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
$metaNodes = $xpath->query('/html/head/meta[@name]'); $metaNodes = $xpath->query('/html/head/meta[@name]');
foreach ($metaNodes as $metaNode) { foreach ($metaNodes as $metaNode) {
$this->addField(Zend_Search_Lucene_Field::Text($metaNode->getAttribute('name'), $this->addField(
$metaNode->getAttribute('content'), Zend_Search_Lucene_Field::Text(
'UTF-8')); $metaNode->getAttribute('name'),
$metaNode->getAttribute('content'),
'UTF-8'
)
);
} }
$docBody = ''; $docBody = '';
@ -160,17 +172,17 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
$linkNodes = $this->_doc->getElementsByTagName('a'); $linkNodes = $this->_doc->getElementsByTagName('a');
foreach ($linkNodes as $linkNode) { foreach ($linkNodes as $linkNode) {
if (($href = $linkNode->getAttribute('href')) != '' && if (($href = $linkNode->getAttribute('href')) != ''
(!self::$_excludeNoFollowLinks || strtolower($linkNode->getAttribute('rel')) != 'nofollow' ) && (!self::$_excludeNoFollowLinks || strtolower($linkNode->getAttribute('rel')) != 'nofollow' )
) { ) {
$this->_links[] = $href; $this->_links[] = $href;
} }
} }
$linkNodes = $this->_doc->getElementsByTagName('area'); $linkNodes = $this->_doc->getElementsByTagName('area');
foreach ($linkNodes as $linkNode) { foreach ($linkNodes as $linkNode) {
if (($href = $linkNode->getAttribute('href')) != '' && if (($href = $linkNode->getAttribute('href')) != ''
(!self::$_excludeNoFollowLinks || strtolower($linkNode->getAttribute('rel')) != 'nofollow' ) && (!self::$_excludeNoFollowLinks || strtolower($linkNode->getAttribute('rel')) != 'nofollow' )
) { ) {
$this->_links[] = $href; $this->_links[] = $href;
} }
} }
@ -211,7 +223,7 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
* We should exclude scripts, which may be not included into comment tags, CDATA sections, * We should exclude scripts, which may be not included into comment tags, CDATA sections,
* *
* @param DOMNode $node * @param DOMNode $node
* @param string &$text * @param string &$text
*/ */
private function _retrieveNodeText(DOMNode $node, &$text) private function _retrieveNodeText(DOMNode $node, &$text)
{ {
@ -250,9 +262,9 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Load HTML document from a string * Load HTML document from a string
* *
* @param string $data * @param string $data
* @param boolean $storeContent * @param boolean $storeContent
* @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag. * @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag.
* @return Zend_Search_Lucene_Document_Html * @return Zend_Search_Lucene_Document_Html
*/ */
public static function loadHTML($data, $storeContent = false, $defaultEncoding = '') public static function loadHTML($data, $storeContent = false, $defaultEncoding = '')
@ -263,9 +275,9 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Load HTML document from a file * Load HTML document from a file
* *
* @param string $file * @param string $file
* @param boolean $storeContent * @param boolean $storeContent
* @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag. * @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag.
* @return Zend_Search_Lucene_Document_Html * @return Zend_Search_Lucene_Document_Html
*/ */
public static function loadHTMLFile($file, $storeContent = false, $defaultEncoding = '') public static function loadHTMLFile($file, $storeContent = false, $defaultEncoding = '')
@ -277,16 +289,18 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Highlight text in text node * Highlight text in text node
* *
* @param DOMText $node * @param DOMText $node
* @param array $wordsToHighlight * @param array $wordsToHighlight
* @param callback $callback Callback method, used to transform (highlighting) text. * @param callback $callback Callback method, used to transform (highlighting) text.
* @param array $params Array of additionall callback parameters (first non-optional parameter is a text to transform) * @param array $params Array of additionall callback parameters (first non-optional parameter is a text to transform)
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
protected function _highlightTextNode(DOMText $node, $wordsToHighlight, $callback, $params) protected function _highlightTextNode(DOMText $node, $wordsToHighlight, $callback, $params)
{ {
/** Zend_Search_Lucene_Analysis_Analyzer */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; * Zend_Search_Lucene_Analysis_Analyzer
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault(); $analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
$analyzer->setInput($node->nodeValue, 'UTF-8'); $analyzer->setInput($node->nodeValue, 'UTF-8');
@ -321,11 +335,13 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
// into valid XHTML (It's automatically done by loadHTML() method) // into valid XHTML (It's automatically done by loadHTML() method)
$highlightedWordNodeSetDomDocument = new DOMDocument('1.0', 'UTF-8'); $highlightedWordNodeSetDomDocument = new DOMDocument('1.0', 'UTF-8');
$success = @$highlightedWordNodeSetDomDocument-> $success = @$highlightedWordNodeSetDomDocument->
loadHTML('<html><head><meta http-equiv="Content-type" content="text/html; charset=UTF-8"/></head><body>' loadHTML(
'<html><head><meta http-equiv="Content-type" content="text/html; charset=UTF-8"/></head><body>'
. $highlightedWordNodeSetHtml . $highlightedWordNodeSetHtml
. '</body></html>'); . '</body></html>'
);
if (!$success) { if (!$success) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception("Error occured while loading highlighted text fragment: '$highlightedWordNodeSetHtml'."); throw new Zend_Search_Lucene_Exception("Error occured while loading highlighted text fragment: '$highlightedWordNodeSetHtml'.");
} }
$highlightedWordNodeSetXpath = new DOMXPath($highlightedWordNodeSetDomDocument); $highlightedWordNodeSetXpath = new DOMXPath($highlightedWordNodeSetDomDocument);
@ -333,8 +349,10 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
for ($count = 0; $count < $highlightedWordNodeSet->length; $count++) { for ($count = 0; $count < $highlightedWordNodeSet->length; $count++) {
$nodeToImport = $highlightedWordNodeSet->item($count); $nodeToImport = $highlightedWordNodeSet->item($count);
$node->parentNode->insertBefore($this->_doc->importNode($nodeToImport, true /* deep copy */), $node->parentNode->insertBefore(
$matchedWordNode); $this->_doc->importNode($nodeToImport, true /* deep copy */),
$matchedWordNode
);
} }
$node->parentNode->removeChild($matchedWordNode); $node->parentNode->removeChild($matchedWordNode);
@ -345,10 +363,10 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* highlight words in content of the specified node * highlight words in content of the specified node
* *
* @param DOMNode $contextNode * @param DOMNode $contextNode
* @param array $wordsToHighlight * @param array $wordsToHighlight
* @param callback $callback Callback method, used to transform (highlighting) text. * @param callback $callback Callback method, used to transform (highlighting) text.
* @param array $params Array of additionall callback parameters (first non-optional parameter is a text to transform) * @param array $params Array of additionall callback parameters (first non-optional parameter is a text to transform)
*/ */
protected function _highlightNodeRecursive(DOMNode $contextNode, $wordsToHighlight, $callback, $params) protected function _highlightNodeRecursive(DOMNode $contextNode, $wordsToHighlight, $callback, $params)
{ {
@ -378,8 +396,8 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Standard callback method used to highlight words. * Standard callback method used to highlight words.
* *
* @param string $stringToHighlight * @param string $stringToHighlight
* @return string * @return string
* @internal * @internal
*/ */
public function applyColour($stringToHighlight, $colour) public function applyColour($stringToHighlight, $colour)
@ -390,8 +408,8 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Highlight text with specified color * Highlight text with specified color
* *
* @param string|array $words * @param string|array $words
* @param string $colour * @param string $colour
* @return string * @return string
*/ */
public function highlight($words, $colour = '#66ffff') public function highlight($words, $colour = '#66ffff')
@ -404,17 +422,19 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
/** /**
* Highlight text using specified View helper or callback function. * Highlight text using specified View helper or callback function.
* *
* @param string|array $words Words to highlight. Words could be organized using the array or string. * @param string|array $words Words to highlight. Words could be organized using the array or string.
* @param callback $callback Callback method, used to transform (highlighting) text. * @param callback $callback Callback method, used to transform (highlighting) text.
* @param array $params Array of additionall callback parameters passed through into it * @param array $params Array of additionall callback parameters passed through into it (first non-optional parameter is an HTML fragment for highlighting) (first non-optional parameter is an HTML fragment for highlighting)
* (first non-optional parameter is an HTML fragment for highlighting) * (first non-optional parameter is an HTML fragment for highlighting)
* @return string * @return string
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function highlightExtended($words, $callback, $params = array()) public function highlightExtended($words, $callback, $params = array())
{ {
/** Zend_Search_Lucene_Analysis_Analyzer */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; * Zend_Search_Lucene_Analysis_Analyzer
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
if (!is_array($words)) { if (!is_array($words)) {
$words = array($words); $words = array($words);
@ -437,7 +457,7 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
} }
if (!is_callable($callback)) { if (!is_callable($callback)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('$viewHelper parameter mast be a View Helper name, View Helper object or callback.'); throw new Zend_Search_Lucene_Exception('$viewHelper parameter mast be a View Helper name, View Helper object or callback.');
} }

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Document */ /**
* Zend_Search_Lucene_Document
*/
require_once 'Zend/Search/Lucene/Document.php'; require_once 'Zend/Search/Lucene/Document.php';
@ -74,7 +76,7 @@ abstract class Zend_Search_Lucene_Document_OpenXml extends Zend_Search_Lucene_Do
/** /**
* Extract metadata from document * Extract metadata from document
* *
* @param ZipArchive $package ZipArchive OpenXML package * @param ZipArchive $package ZipArchive OpenXML package
* @return array Key-value pairs containing document meta data * @return array Key-value pairs containing document meta data
*/ */
protected function extractMetaData(ZipArchive $package) protected function extractMetaData(ZipArchive $package)
@ -109,15 +111,17 @@ abstract class Zend_Search_Lucene_Document_OpenXml extends Zend_Search_Lucene_Do
/** /**
* Determine absolute zip path * Determine absolute zip path
* *
* @param string $path * @param string $path
* @return string * @return string
*/ */
protected function absoluteZipPath($path) { protected function absoluteZipPath($path)
{
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen'); $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array(); $absolutes = array();
foreach ($parts as $part) { foreach ($parts as $part) {
if ('.' == $part) continue; if ('.' == $part) { continue;
}
if ('..' == $part) { if ('..' == $part) {
array_pop($absolutes); array_pop($absolutes);
} else { } else {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Document_OpenXml */ /**
* Zend_Search_Lucene_Document_OpenXml
*/
require_once 'Zend/Search/Lucene/Document/OpenXml.php'; require_once 'Zend/Search/Lucene/Document/OpenXml.php';
/** /**
@ -66,14 +68,14 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Object constructor * Object constructor
* *
* @param string $fileName * @param string $fileName
* @param boolean $storeContent * @param boolean $storeContent
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
private function __construct($fileName, $storeContent) private function __construct($fileName, $storeContent)
{ {
if (!class_exists('ZipArchive', false)) { if (!class_exists('ZipArchive', false)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('MS Office documents processing functionality requires Zip extension to be loaded'); throw new Zend_Search_Lucene_Exception('MS Office documents processing functionality requires Zip extension to be loaded');
} }
@ -90,28 +92,28 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
// Read relations and search for officeDocument // Read relations and search for officeDocument
$relationsXml = $package->getFromName('_rels/.rels'); $relationsXml = $package->getFromName('_rels/.rels');
if ($relationsXml === false) { if ($relationsXml === false) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .pptx file.'); throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .pptx file.');
} }
$relations = simplexml_load_string($relationsXml); $relations = simplexml_load_string($relationsXml);
foreach ($relations->Relationship as $rel) { foreach ($relations->Relationship as $rel) {
if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
// Found office document! Search for slides... // Found office document! Search for slides...
$slideRelations = simplexml_load_string($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/_rels/" . basename($rel["Target"]) . ".rels")) ); $slideRelations = simplexml_load_string($package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/_rels/" . basename($rel["Target"]) . ".rels")));
foreach ($slideRelations->Relationship as $slideRel) { foreach ($slideRelations->Relationship as $slideRel) {
if ($slideRel["Type"] == Zend_Search_Lucene_Document_Pptx::SCHEMA_SLIDERELATION) { if ($slideRel["Type"] == Zend_Search_Lucene_Document_Pptx::SCHEMA_SLIDERELATION) {
// Found slide! // Found slide!
$slides[ str_replace( 'rId', '', (string)$slideRel["Id"] ) ] = simplexml_load_string( $slides[ str_replace('rId', '', (string)$slideRel["Id"]) ] = simplexml_load_string(
$package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($slideRel["Target"]) . "/" . basename($slideRel["Target"])) ) $package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($slideRel["Target"]) . "/" . basename($slideRel["Target"])))
); );
// Search for slide notes // Search for slide notes
$slideNotesRelations = simplexml_load_string($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($slideRel["Target"]) . "/_rels/" . basename($slideRel["Target"]) . ".rels")) ); $slideNotesRelations = simplexml_load_string($package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($slideRel["Target"]) . "/_rels/" . basename($slideRel["Target"]) . ".rels")));
foreach ($slideNotesRelations->Relationship as $slideNoteRel) { foreach ($slideNotesRelations->Relationship as $slideNoteRel) {
if ($slideNoteRel["Type"] == Zend_Search_Lucene_Document_Pptx::SCHEMA_SLIDENOTESRELATION) { if ($slideNoteRel["Type"] == Zend_Search_Lucene_Document_Pptx::SCHEMA_SLIDENOTESRELATION) {
// Found slide notes! // Found slide notes!
$slideNotes[ str_replace( 'rId', '', (string)$slideRel["Id"] ) ] = simplexml_load_string( $slideNotes[ str_replace('rId', '', (string)$slideRel["Id"]) ] = simplexml_load_string(
$package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($slideRel["Target"]) . "/" . dirname($slideNoteRel["Target"]) . "/" . basename($slideNoteRel["Target"])) ) $package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($slideRel["Target"]) . "/" . dirname($slideNoteRel["Target"]) . "/" . basename($slideNoteRel["Target"])))
); );
break; break;
@ -180,8 +182,7 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
} }
// Store title (if not present in meta data) // Store title (if not present in meta data)
if (!isset($coreProperties['title'])) if (!isset($coreProperties['title'])) {
{
$this->addField(Zend_Search_Lucene_Field::Text('title', $fileName, 'UTF-8')); $this->addField(Zend_Search_Lucene_Field::Text('title', $fileName, 'UTF-8'));
} }
} }
@ -189,8 +190,8 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Load Pptx document from a file * Load Pptx document from a file
* *
* @param string $fileName * @param string $fileName
* @param boolean $storeContent * @param boolean $storeContent
* @return Zend_Search_Lucene_Document_Pptx * @return Zend_Search_Lucene_Document_Pptx
*/ */
public static function loadPptxFile($fileName, $storeContent = false) public static function loadPptxFile($fileName, $storeContent = false)

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Document_OpenXml */ /**
* Zend_Search_Lucene_Document_OpenXml
*/
require_once 'Zend/Search/Lucene/Document/OpenXml.php'; require_once 'Zend/Search/Lucene/Document/OpenXml.php';
/** /**
@ -73,14 +75,14 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Object constructor * Object constructor
* *
* @param string $fileName * @param string $fileName
* @param boolean $storeContent * @param boolean $storeContent
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
private function __construct($fileName, $storeContent) private function __construct($fileName, $storeContent)
{ {
if (!class_exists('ZipArchive', false)) { if (!class_exists('ZipArchive', false)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('MS Office documents processing functionality requires Zip extension to be loaded'); throw new Zend_Search_Lucene_Exception('MS Office documents processing functionality requires Zip extension to be loaded');
} }
@ -97,20 +99,20 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
// Read relations and search for officeDocument // Read relations and search for officeDocument
$relationsXml = $package->getFromName('_rels/.rels'); $relationsXml = $package->getFromName('_rels/.rels');
if ($relationsXml === false) { if ($relationsXml === false) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .xlsx file.'); throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .xlsx file.');
} }
$relations = simplexml_load_string($relationsXml); $relations = simplexml_load_string($relationsXml);
foreach ($relations->Relationship as $rel) { foreach ($relations->Relationship as $rel) {
if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
// Found office document! Read relations for workbook... // Found office document! Read relations for workbook...
$workbookRelations = simplexml_load_string($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/_rels/" . basename($rel["Target"]) . ".rels")) ); $workbookRelations = simplexml_load_string($package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/_rels/" . basename($rel["Target"]) . ".rels")));
$workbookRelations->registerXPathNamespace("rel", Zend_Search_Lucene_Document_OpenXml::SCHEMA_RELATIONSHIP); $workbookRelations->registerXPathNamespace("rel", Zend_Search_Lucene_Document_OpenXml::SCHEMA_RELATIONSHIP);
// Read shared strings // Read shared strings
$sharedStringsPath = $workbookRelations->xpath("rel:Relationship[@Type='" . Zend_Search_Lucene_Document_Xlsx::SCHEMA_SHAREDSTRINGS . "']"); $sharedStringsPath = $workbookRelations->xpath("rel:Relationship[@Type='" . Zend_Search_Lucene_Document_Xlsx::SCHEMA_SHAREDSTRINGS . "']");
$sharedStringsPath = (string)$sharedStringsPath[0]['Target']; $sharedStringsPath = (string)$sharedStringsPath[0]['Target'];
$xmlStrings = simplexml_load_string($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . $sharedStringsPath)) ); $xmlStrings = simplexml_load_string($package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/" . $sharedStringsPath)));
if (isset($xmlStrings) && isset($xmlStrings->si)) { if (isset($xmlStrings) && isset($xmlStrings->si)) {
foreach ($xmlStrings->si as $val) { foreach ($xmlStrings->si as $val) {
if (isset($val->t)) { if (isset($val->t)) {
@ -124,8 +126,8 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
// Loop relations for workbook and extract worksheets... // Loop relations for workbook and extract worksheets...
foreach ($workbookRelations->Relationship as $workbookRelation) { foreach ($workbookRelations->Relationship as $workbookRelation) {
if ($workbookRelation["Type"] == Zend_Search_Lucene_Document_Xlsx::SCHEMA_WORKSHEETRELATION) { if ($workbookRelation["Type"] == Zend_Search_Lucene_Document_Xlsx::SCHEMA_WORKSHEETRELATION) {
$worksheets[ str_replace( 'rId', '', (string)$workbookRelation["Id"]) ] = simplexml_load_string( $worksheets[ str_replace('rId', '', (string)$workbookRelation["Id"]) ] = simplexml_load_string(
$package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($workbookRelation["Target"]) . "/" . basename($workbookRelation["Target"])) ) $package->getFromName($this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($workbookRelation["Target"]) . "/" . basename($workbookRelation["Target"])))
); );
} }
} }
@ -144,55 +146,56 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
// Determine data type // Determine data type
$dataType = (string)$c["t"]; $dataType = (string)$c["t"];
switch ($dataType) { switch ($dataType) {
case "s": case "s":
// Value is a shared string // Value is a shared string
if ((string)$c->v != '') { if ((string)$c->v != '') {
$value = $sharedStrings[intval($c->v)]; $value = $sharedStrings[intval($c->v)];
} else { } else {
$value = ''; $value = '';
} }
break; break;
case "b": case "b":
// Value is boolean // Value is boolean
$value = (string)$c->v;
if ($value == '0') {
$value = false;
} else if ($value == '1') {
$value = true;
} else {
$value = (bool)$c->v;
}
break;
case "inlineStr":
// Value is rich text inline
$value = $this->_parseRichText($c->is);
break;
case "e":
// Value is an error message
if ((string)$c->v != '') {
$value = (string)$c->v; $value = (string)$c->v;
if ($value == '0') { } else {
$value = false; $value = '';
} else if ($value == '1') { }
$value = true;
} else { break;
$value = (bool)$c->v;
} default:
// Value is a string
break; $value = (string)$c->v;
case "inlineStr": // Check for numeric values
// Value is rich text inline if (is_numeric($value) && $dataType != 's') {
$value = $this->_parseRichText($c->is); if ($value == (int)$value) { $value = (int)$value;
} elseif ($value == (float)$value) { $value = (float)$value;
break; } elseif ($value == (double)$value) { $value = (double)$value;
case "e":
// Value is an error message
if ((string)$c->v != '') {
$value = (string)$c->v;
} else {
$value = '';
}
break;
default:
// Value is a string
$value = (string)$c->v;
// Check for numeric values
if (is_numeric($value) && $dataType != 's') {
if ($value == (int)$value) $value = (int)$value;
elseif ($value == (float)$value) $value = (float)$value;
elseif ($value == (double)$value) $value = (double)$value;
} }
}
} }
$documentBody[] = $value; $documentBody[] = $value;
@ -223,8 +226,7 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
} }
// Store title (if not present in meta data) // Store title (if not present in meta data)
if (!isset($coreProperties['title'])) if (!isset($coreProperties['title'])) {
{
$this->addField(Zend_Search_Lucene_Field::Text('title', $fileName, 'UTF-8')); $this->addField(Zend_Search_Lucene_Field::Text('title', $fileName, 'UTF-8'));
} }
} }
@ -232,10 +234,11 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Parse rich text XML * Parse rich text XML
* *
* @param SimpleXMLElement $is * @param SimpleXMLElement $is
* @return string * @return string
*/ */
private function _parseRichText($is = null) { private function _parseRichText($is = null)
{
$value = array(); $value = array();
if (isset($is->t)) { if (isset($is->t)) {
@ -252,8 +255,8 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
/** /**
* Load Xlsx document from a file * Load Xlsx document from a file
* *
* @param string $fileName * @param string $fileName
* @param boolean $storeContent * @param boolean $storeContent
* @return Zend_Search_Lucene_Document_Xlsx * @return Zend_Search_Lucene_Document_Xlsx
*/ */
public static function loadXlsxFile($fileName, $storeContent = false) public static function loadXlsxFile($fileName, $storeContent = false)

View File

@ -12,11 +12,11 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
@ -33,5 +33,7 @@ require_once 'Zend/Search/Exception.php';
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_Exception extends Zend_Search_Exception class Zend_Search_Lucene_Exception extends Zend_Search_Exception
{} {
}

View File

@ -12,14 +12,16 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FSM.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: FSM.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_FSMAction */ /**
* Zend_Search_Lucene_FSMAction
*/
require_once 'Zend/Search/Lucene/FSMAction.php'; require_once 'Zend/Search/Lucene/FSMAction.php';
/** /**
@ -31,10 +33,10 @@ require_once 'Zend/Search/Lucene/FSMAction.php';
* process() methods invokes a specified actions which may construct FSM output. * process() methods invokes a specified actions which may construct FSM output.
* Actions may be also used to signal, that we have reached Accept State * Actions may be also used to signal, that we have reached Accept State
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
abstract class Zend_Search_Lucene_FSM abstract class Zend_Search_Lucene_FSM
{ {
@ -171,13 +173,13 @@ abstract class Zend_Search_Lucene_FSM
* Set FSM state. * Set FSM state.
* No any action is invoked * No any action is invoked
* *
* @param integer|string $state * @param integer|string $state
* @throws Zend_Search_Exception * @throws Zend_Search_Exception
*/ */
public function setState($state) public function setState($state)
{ {
if (!isset($this->_states[$state])) { if (!isset($this->_states[$state])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('State \'' . $state . '\' is not on of the possible FSM states.'); throw new Zend_Search_Exception('State \'' . $state . '\' is not on of the possible FSM states.');
} }
@ -239,24 +241,24 @@ abstract class Zend_Search_Lucene_FSM
/** /**
* Add symbol to the input alphabet * Add symbol to the input alphabet
* *
* @param integer|string $sourceState * @param integer|string $sourceState
* @param integer|string $input * @param integer|string $input
* @param integer|string $targetState * @param integer|string $targetState
* @param Zend_Search_Lucene_FSMAction|null $inputAction * @param Zend_Search_Lucene_FSMAction|null $inputAction
* @throws Zend_Search_Exception * @throws Zend_Search_Exception
*/ */
public function addRule($sourceState, $input, $targetState, $inputAction = null) public function addRule($sourceState, $input, $targetState, $inputAction = null)
{ {
if (!isset($this->_states[$sourceState])) { if (!isset($this->_states[$sourceState])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined source state (' . $sourceState . ').'); throw new Zend_Search_Exception('Undefined source state (' . $sourceState . ').');
} }
if (!isset($this->_states[$targetState])) { if (!isset($this->_states[$targetState])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined target state (' . $targetState . ').'); throw new Zend_Search_Exception('Undefined target state (' . $targetState . ').');
} }
if (!isset($this->_inputAphabet[$input])) { if (!isset($this->_inputAphabet[$input])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined input symbol (' . $input . ').'); throw new Zend_Search_Exception('Undefined input symbol (' . $input . ').');
} }
@ -264,7 +266,7 @@ abstract class Zend_Search_Lucene_FSM
$this->_rules[$sourceState] = array(); $this->_rules[$sourceState] = array();
} }
if (isset($this->_rules[$sourceState][$input])) { if (isset($this->_rules[$sourceState][$input])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Rule for {state,input} pair (' . $sourceState . ', '. $input . ') is already defined.'); throw new Zend_Search_Exception('Rule for {state,input} pair (' . $sourceState . ', '. $input . ') is already defined.');
} }
@ -282,13 +284,13 @@ abstract class Zend_Search_Lucene_FSM
* Several entry actions are allowed. * Several entry actions are allowed.
* Action execution order is defined by addEntryAction() calls * Action execution order is defined by addEntryAction() calls
* *
* @param integer|string $state * @param integer|string $state
* @param Zend_Search_Lucene_FSMAction $action * @param Zend_Search_Lucene_FSMAction $action
*/ */
public function addEntryAction($state, Zend_Search_Lucene_FSMAction $action) public function addEntryAction($state, Zend_Search_Lucene_FSMAction $action)
{ {
if (!isset($this->_states[$state])) { if (!isset($this->_states[$state])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined state (' . $state. ').'); throw new Zend_Search_Exception('Undefined state (' . $state. ').');
} }
@ -304,13 +306,13 @@ abstract class Zend_Search_Lucene_FSM
* Several exit actions are allowed. * Several exit actions are allowed.
* Action execution order is defined by addEntryAction() calls * Action execution order is defined by addEntryAction() calls
* *
* @param integer|string $state * @param integer|string $state
* @param Zend_Search_Lucene_FSMAction $action * @param Zend_Search_Lucene_FSMAction $action
*/ */
public function addExitAction($state, Zend_Search_Lucene_FSMAction $action) public function addExitAction($state, Zend_Search_Lucene_FSMAction $action)
{ {
if (!isset($this->_states[$state])) { if (!isset($this->_states[$state])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined state (' . $state. ').'); throw new Zend_Search_Exception('Undefined state (' . $state. ').');
} }
@ -326,18 +328,18 @@ abstract class Zend_Search_Lucene_FSM
* Several input actions are allowed. * Several input actions are allowed.
* Action execution order is defined by addInputAction() calls * Action execution order is defined by addInputAction() calls
* *
* @param integer|string $state * @param integer|string $state
* @param integer|string $input * @param integer|string $input
* @param Zend_Search_Lucene_FSMAction $action * @param Zend_Search_Lucene_FSMAction $action
*/ */
public function addInputAction($state, $inputSymbol, Zend_Search_Lucene_FSMAction $action) public function addInputAction($state, $inputSymbol, Zend_Search_Lucene_FSMAction $action)
{ {
if (!isset($this->_states[$state])) { if (!isset($this->_states[$state])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined state (' . $state. ').'); throw new Zend_Search_Exception('Undefined state (' . $state. ').');
} }
if (!isset($this->_inputAphabet[$inputSymbol])) { if (!isset($this->_inputAphabet[$inputSymbol])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined input symbol (' . $inputSymbol. ').'); throw new Zend_Search_Exception('Undefined input symbol (' . $inputSymbol. ').');
} }
@ -356,18 +358,18 @@ abstract class Zend_Search_Lucene_FSM
* Several transition actions are allowed. * Several transition actions are allowed.
* Action execution order is defined by addTransitionAction() calls * Action execution order is defined by addTransitionAction() calls
* *
* @param integer|string $sourceState * @param integer|string $sourceState
* @param integer|string $targetState * @param integer|string $targetState
* @param Zend_Search_Lucene_FSMAction $action * @param Zend_Search_Lucene_FSMAction $action
*/ */
public function addTransitionAction($sourceState, $targetState, Zend_Search_Lucene_FSMAction $action) public function addTransitionAction($sourceState, $targetState, Zend_Search_Lucene_FSMAction $action)
{ {
if (!isset($this->_states[$sourceState])) { if (!isset($this->_states[$sourceState])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined source state (' . $sourceState. ').'); throw new Zend_Search_Exception('Undefined source state (' . $sourceState. ').');
} }
if (!isset($this->_states[$targetState])) { if (!isset($this->_states[$targetState])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('Undefined source state (' . $targetState. ').'); throw new Zend_Search_Exception('Undefined source state (' . $targetState. ').');
} }
@ -385,17 +387,17 @@ abstract class Zend_Search_Lucene_FSM
/** /**
* Process an input * Process an input
* *
* @param mixed $input * @param mixed $input
* @throws Zend_Search_Exception * @throws Zend_Search_Exception
*/ */
public function process($input) public function process($input)
{ {
if (!isset($this->_rules[$this->_currentState])) { if (!isset($this->_rules[$this->_currentState])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('There is no any rule for current state (' . $this->_currentState . ').'); throw new Zend_Search_Exception('There is no any rule for current state (' . $this->_currentState . ').');
} }
if (!isset($this->_rules[$this->_currentState][$input])) { if (!isset($this->_rules[$this->_currentState][$input])) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('There is no any rule for {current state, input} pair (' . $this->_currentState . ', ' . $input . ').'); throw new Zend_Search_Exception('There is no any rule for {current state, input} pair (' . $this->_currentState . ', ' . $input . ').');
} }
@ -407,8 +409,9 @@ abstract class Zend_Search_Lucene_FSM
$action->doAction(); $action->doAction();
} }
} }
if (isset($this->_inputActions[$sourceState]) && if (isset($this->_inputActions[$sourceState])
isset($this->_inputActions[$sourceState][$input])) { && isset($this->_inputActions[$sourceState][$input])
) {
foreach ($this->_inputActions[$sourceState][$input] as $action) { foreach ($this->_inputActions[$sourceState][$input] as $action) {
$action->doAction(); $action->doAction();
} }
@ -417,8 +420,9 @@ abstract class Zend_Search_Lucene_FSM
$this->_currentState = $targetState; $this->_currentState = $targetState;
if (isset($this->_transitionActions[$sourceState]) && if (isset($this->_transitionActions[$sourceState])
isset($this->_transitionActions[$sourceState][$targetState])) { && isset($this->_transitionActions[$sourceState][$targetState])
) {
foreach ($this->_transitionActions[$sourceState][$targetState] as $action) { foreach ($this->_transitionActions[$sourceState][$targetState] as $action) {
$action->doAction(); $action->doAction();
} }
@ -433,7 +437,7 @@ abstract class Zend_Search_Lucene_FSM
public function reset() public function reset()
{ {
if (count($this->_states) == 0) { if (count($this->_states) == 0) {
require_once 'Zend/Search/Exception.php'; include_once 'Zend/Search/Exception.php';
throw new Zend_Search_Exception('There is no any state defined for FSM.'); throw new Zend_Search_Exception('There is no any state defined for FSM.');
} }

View File

@ -12,22 +12,21 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FSMAction.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: FSMAction.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** /**
* Abstract Finite State Machine * Abstract Finite State Machine
* *
* * @category Zend
* @category Zend * @package Zend_Search_Lucene
* @package Zend_Search_Lucene * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License
* @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_FSMAction class Zend_Search_Lucene_FSMAction
{ {

View File

@ -103,9 +103,9 @@ class Zend_Search_Lucene_Field
/** /**
* Object constructor * Object constructor
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param string $encoding * @param string $encoding
* @param boolean $isStored * @param boolean $isStored
* @param boolean $isIndexed * @param boolean $isIndexed
* @param boolean $isTokenized * @param boolean $isTokenized
@ -137,9 +137,9 @@ class Zend_Search_Lucene_Field
* Constructs a String-valued Field that is not tokenized, but is indexed * Constructs a String-valued Field that is not tokenized, but is indexed
* and stored. Useful for non-text fields, e.g. date or url. * and stored. Useful for non-text fields, e.g. date or url.
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Field * @return Zend_Search_Lucene_Field
*/ */
public static function keyword($name, $value, $encoding = '') public static function keyword($name, $value, $encoding = '')
@ -152,9 +152,9 @@ class Zend_Search_Lucene_Field
* Constructs a String-valued Field that is not tokenized nor indexed, * Constructs a String-valued Field that is not tokenized nor indexed,
* but is stored in the index, for return with hits. * but is stored in the index, for return with hits.
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Field * @return Zend_Search_Lucene_Field
*/ */
public static function unIndexed($name, $value, $encoding = '') public static function unIndexed($name, $value, $encoding = '')
@ -167,9 +167,9 @@ class Zend_Search_Lucene_Field
* Constructs a Binary String valued Field that is not tokenized nor indexed, * Constructs a Binary String valued Field that is not tokenized nor indexed,
* but is stored in the index, for return with hits. * but is stored in the index, for return with hits.
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Field * @return Zend_Search_Lucene_Field
*/ */
public static function binary($name, $value) public static function binary($name, $value)
@ -182,9 +182,9 @@ class Zend_Search_Lucene_Field
* and is stored in the index, for return with hits. Useful for short text * and is stored in the index, for return with hits. Useful for short text
* fields, like "title" or "subject". Term vector will not be stored for this field. * fields, like "title" or "subject". Term vector will not be stored for this field.
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Field * @return Zend_Search_Lucene_Field
*/ */
public static function text($name, $value, $encoding = '') public static function text($name, $value, $encoding = '')
@ -197,9 +197,9 @@ class Zend_Search_Lucene_Field
* Constructs a String-valued Field that is tokenized and indexed, * Constructs a String-valued Field that is tokenized and indexed,
* but that is not stored in the index. * but that is not stored in the index.
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Field * @return Zend_Search_Lucene_Field
*/ */
public static function unStored($name, $value, $encoding = '') public static function unStored($name, $value, $encoding = '')
@ -214,8 +214,9 @@ class Zend_Search_Lucene_Field
*/ */
public function getUtf8Value() public function getUtf8Value()
{ {
if (strcasecmp($this->encoding, 'utf8' ) == 0 || if (strcasecmp($this->encoding, 'utf8') == 0
strcasecmp($this->encoding, 'utf-8') == 0 ) { || strcasecmp($this->encoding, 'utf-8') == 0
) {
return $this->value; return $this->value;
} else { } else {

View File

@ -27,7 +27,6 @@
* Manual "method inlining" is performed to increase dictionary index loading operation * Manual "method inlining" is performed to increase dictionary index loading operation
* which is major bottelneck for search performance. * which is major bottelneck for search performance.
* *
*
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @subpackage Index * @subpackage Index
@ -44,7 +43,7 @@ class Zend_Search_Lucene_Index_DictionaryLoader
* *
* See Zend_Search_Lucene_Index_SegmintInfo class for details * See Zend_Search_Lucene_Index_SegmintInfo class for details
* *
* @param string $data * @param string $data
* @return array * @return array
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -57,9 +56,10 @@ class Zend_Search_Lucene_Index_DictionaryLoader
// $tiVersion = $tiiFile->readInt(); // $tiVersion = $tiiFile->readInt();
$tiVersion = ord($data[0]) << 24 | ord($data[1]) << 16 | ord($data[2]) << 8 | ord($data[3]); $tiVersion = ord($data[0]) << 24 | ord($data[1]) << 16 | ord($data[2]) << 8 | ord($data[3]);
$pos += 4; $pos += 4;
if ($tiVersion != (int)0xFFFFFFFE /* pre-2.1 format */ && if ($tiVersion != (int)0xFFFFFFFE /* pre-2.1 format */
$tiVersion != (int)0xFFFFFFFD /* 2.1+ format */) { && $tiVersion != (int)0xFFFFFFFD /* 2.1+ format */
require_once 'Zend/Search/Lucene/Exception.php'; ) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format'); throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format');
} }
@ -74,14 +74,15 @@ class Zend_Search_Lucene_Index_DictionaryLoader
ord($data[$pos+6]) << 8 | ord($data[$pos+6]) << 8 |
ord($data[$pos+7]); ord($data[$pos+7]);
} else { } else {
if ((ord($data[$pos]) != 0) || if ((ord($data[$pos]) != 0)
(ord($data[$pos+1]) != 0) || || (ord($data[$pos+1]) != 0)
(ord($data[$pos+2]) != 0) || || (ord($data[$pos+2]) != 0)
(ord($data[$pos+3]) != 0) || || (ord($data[$pos+3]) != 0)
((ord($data[$pos+4]) & 0x80) != 0)) { || ((ord($data[$pos+4]) & 0x80) != 0)
require_once 'Zend/Search/Lucene/Exception.php'; ) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Largest supported segment size (for 32-bit mode) is 2Gb'); throw new Zend_Search_Lucene_Exception('Largest supported segment size (for 32-bit mode) is 2Gb');
} }
$indexTermCount = ord($data[$pos+4]) << 24 | $indexTermCount = ord($data[$pos+4]) << 24 |
ord($data[$pos+5]) << 16 | ord($data[$pos+5]) << 16 |
@ -97,7 +98,7 @@ class Zend_Search_Lucene_Index_DictionaryLoader
$skipInterval = ord($data[$pos]) << 24 | ord($data[$pos+1]) << 16 | ord($data[$pos+2]) << 8 | ord($data[$pos+3]); $skipInterval = ord($data[$pos]) << 24 | ord($data[$pos+1]) << 16 | ord($data[$pos+2]) << 8 | ord($data[$pos+3]);
$pos += 4; $pos += 4;
if ($indexTermCount < 1) { if ($indexTermCount < 1) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wrong number of terms in a term dictionary index'); throw new Zend_Search_Lucene_Exception('Wrong number of terms in a term dictionary index');
} }
@ -149,11 +150,12 @@ class Zend_Search_Lucene_Index_DictionaryLoader
// Check for null character. Java2 encodes null character // Check for null character. Java2 encodes null character
// in two bytes. // in two bytes.
if (ord($termSuffix[$count1]) == 0xC0 && if (ord($termSuffix[$count1]) == 0xC0
ord($termSuffix[$count1+1]) == 0x80 ) { && ord($termSuffix[$count1+1]) == 0x80
) {
$termSuffix[$count1] = 0; $termSuffix[$count1] = 0;
$termSuffix = substr($termSuffix,0,$count1+1) $termSuffix = substr($termSuffix, 0, $count1+1)
. substr($termSuffix,$count1+2); . substr($termSuffix, $count1+2);
} }
$count1 += $addBytes; $count1 += $addBytes;
} }
@ -218,7 +220,7 @@ class Zend_Search_Lucene_Index_DictionaryLoader
} }
$proxPointer += $vint; $proxPointer += $vint;
if( $docFreq >= $skipInterval ) { if($docFreq >= $skipInterval ) {
// $skipDelta = $tiiFile->readVInt(); // $skipDelta = $tiiFile->readVInt();
$nbyte = ord($data[$pos++]); $nbyte = ord($data[$pos++]);
$vint = $nbyte & 0x7F; $vint = $nbyte & 0x7F;
@ -253,7 +255,7 @@ class Zend_Search_Lucene_Index_DictionaryLoader
// Check special index entry mark // Check special index entry mark
if ($termDictionary[0][0] != (int)0xFFFFFFFF) { if ($termDictionary[0][0] != (int)0xFFFFFFFF) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format'); throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format');
} }

View File

@ -20,7 +20,9 @@
* @version $Id: SegmentMerger.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: SegmentMerger.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Index_SegmentInfo */ /**
* Zend_Search_Lucene_Index_SegmentInfo
*/
require_once 'Zend/Search/Lucene/Index/SegmentInfo.php'; require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
@ -78,12 +80,14 @@ class Zend_Search_Lucene_Index_SegmentMerger
* and $name as a name of new segment * and $name as a name of new segment
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @param string $name * @param string $name
*/ */
public function __construct($directory, $name) public function __construct($directory, $name)
{ {
/** Zend_Search_Lucene_Index_SegmentWriter_StreamWriter */ /**
require_once 'Zend/Search/Lucene/Index/SegmentWriter/StreamWriter.php'; * Zend_Search_Lucene_Index_SegmentWriter_StreamWriter
*/
include_once 'Zend/Search/Lucene/Index/SegmentWriter/StreamWriter.php';
$this->_writer = new Zend_Search_Lucene_Index_SegmentWriter_StreamWriter($directory, $name); $this->_writer = new Zend_Search_Lucene_Index_SegmentWriter_StreamWriter($directory, $name);
} }
@ -110,15 +114,17 @@ class Zend_Search_Lucene_Index_SegmentMerger
public function merge() public function merge()
{ {
if ($this->_mergeDone) { if ($this->_mergeDone) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Merge is already done.'); throw new Zend_Search_Lucene_Exception('Merge is already done.');
} }
if (count($this->_segmentInfos) < 1) { if (count($this->_segmentInfos) < 1) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wrong number of segments to be merged (' throw new Zend_Search_Lucene_Exception(
'Wrong number of segments to be merged ('
. count($this->_segmentInfos) . count($this->_segmentInfos)
. ').'); . ').'
);
} }
$this->_mergeFields(); $this->_mergeFields();
@ -191,21 +197,25 @@ class Zend_Search_Lucene_Index_SegmentMerger
if (!($bits & 2)) { // Text data if (!($bits & 2)) { // Text data
$storedFields[] = $storedFields[] =
new Zend_Search_Lucene_Field($fieldInfo->name, new Zend_Search_Lucene_Field(
$fdtFile->readString(), $fieldInfo->name,
'UTF-8', $fdtFile->readString(),
true, 'UTF-8',
$fieldInfo->isIndexed, true,
$bits & 1 ); $fieldInfo->isIndexed,
$bits & 1
);
} else { // Binary data } else { // Binary data
$storedFields[] = $storedFields[] =
new Zend_Search_Lucene_Field($fieldInfo->name, new Zend_Search_Lucene_Field(
$fdtFile->readBinary(), $fieldInfo->name,
'', $fdtFile->readBinary(),
true, '',
$fieldInfo->isIndexed, true,
$bits & 1, $fieldInfo->isIndexed,
true); $bits & 1,
true
);
} }
} }
@ -223,8 +233,10 @@ class Zend_Search_Lucene_Index_SegmentMerger
*/ */
private function _mergeTerms() private function _mergeTerms()
{ {
/** Zend_Search_Lucene_Index_TermsPriorityQueue */ /**
require_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php'; * Zend_Search_Lucene_Index_TermsPriorityQueue
*/
include_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php';
$segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue(); $segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
@ -245,9 +257,9 @@ class Zend_Search_Lucene_Index_SegmentMerger
// Merge positions array // Merge positions array
$termDocs += $segmentInfo->currentTermPositions(); $termDocs += $segmentInfo->currentTermPositions();
if ($segmentInfoQueue->top() === null || if ($segmentInfoQueue->top() === null
$segmentInfoQueue->top()->currentTerm()->key() != || $segmentInfoQueue->top()->currentTerm()->key() != $segmentInfo->currentTerm()->key()
$segmentInfo->currentTerm()->key()) { ) {
// We got new term // We got new term
ksort($termDocs, SORT_NUMERIC); ksort($termDocs, SORT_NUMERIC);

View File

@ -21,13 +21,19 @@
*/ */
/** Zend_Search_Lucene_Index_FieldInfo */ /**
* Zend_Search_Lucene_Index_FieldInfo
*/
require_once 'Zend/Search/Lucene/Index/FieldInfo.php'; require_once 'Zend/Search/Lucene/Index/FieldInfo.php';
/** Zend_Search_Lucene_Index_Term */ /**
* Zend_Search_Lucene_Index_Term
*/
require_once 'Zend/Search/Lucene/Index/Term.php'; require_once 'Zend/Search/Lucene/Index/Term.php';
/** Zend_Search_Lucene_Index_TermInfo */ /**
* Zend_Search_Lucene_Index_TermInfo
*/
require_once 'Zend/Search/Lucene/Index/TermInfo.php'; require_once 'Zend/Search/Lucene/Index/TermInfo.php';
/** /**
@ -145,7 +151,7 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
* Object constructor. * Object constructor.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @param string $name * @param string $name
*/ */
public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name) public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name)
{ {
@ -159,7 +165,7 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
* *
* Returns actual field number * Returns actual field number
* *
* @param Zend_Search_Lucene_Field $field * @param Zend_Search_Lucene_Field $field
* @return integer * @return integer
*/ */
public function addField(Zend_Search_Lucene_Field $field) public function addField(Zend_Search_Lucene_Field $field)
@ -167,10 +173,12 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
if (!isset($this->_fields[$field->name])) { if (!isset($this->_fields[$field->name])) {
$fieldNumber = count($this->_fields); $fieldNumber = count($this->_fields);
$this->_fields[$field->name] = $this->_fields[$field->name] =
new Zend_Search_Lucene_Index_FieldInfo($field->name, new Zend_Search_Lucene_Index_FieldInfo(
$field->isIndexed, $field->name,
$fieldNumber, $field->isIndexed,
$field->storeTermVector); $fieldNumber,
$field->storeTermVector
);
return $fieldNumber; return $fieldNumber;
} else { } else {
@ -186,7 +194,7 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
* *
* Returns actual field number * Returns actual field number
* *
* @param Zend_Search_Lucene_Index_FieldInfo $fieldInfo * @param Zend_Search_Lucene_Index_FieldInfo $fieldInfo
* @return integer * @return integer
*/ */
public function addFieldInfo(Zend_Search_Lucene_Index_FieldInfo $fieldInfo) public function addFieldInfo(Zend_Search_Lucene_Index_FieldInfo $fieldInfo)
@ -194,10 +202,12 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
if (!isset($this->_fields[$fieldInfo->name])) { if (!isset($this->_fields[$fieldInfo->name])) {
$fieldNumber = count($this->_fields); $fieldNumber = count($this->_fields);
$this->_fields[$fieldInfo->name] = $this->_fields[$fieldInfo->name] =
new Zend_Search_Lucene_Index_FieldInfo($fieldInfo->name, new Zend_Search_Lucene_Index_FieldInfo(
$fieldInfo->isIndexed, $fieldInfo->name,
$fieldNumber, $fieldInfo->isIndexed,
$fieldInfo->storeTermVector); $fieldNumber,
$fieldInfo->storeTermVector
);
return $fieldNumber; return $fieldNumber;
} else { } else {
@ -288,11 +298,12 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
foreach ($this->_fields as $field) { foreach ($this->_fields as $field) {
$fnmFile->writeString($field->name); $fnmFile->writeString($field->name);
$fnmFile->writeByte(($field->isIndexed ? 0x01 : 0x00) | $fnmFile->writeByte(
($field->isIndexed ? 0x01 : 0x00) |
($field->storeTermVector ? 0x02 : 0x00) ($field->storeTermVector ? 0x02 : 0x00)
// not supported yet 0x04 /* term positions are stored with the term vectors */ | // not supported yet 0x04 /* term positions are stored with the term vectors */ |
// not supported yet 0x08 /* term offsets are stored with the term vectors */ | // not supported yet 0x08 /* term offsets are stored with the term vectors */ |
); );
if ($field->isIndexed) { if ($field->isIndexed) {
// pre-2.1 index mode (not used now) // pre-2.1 index mode (not used now)
@ -401,7 +412,9 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
$this->_tiiFile->writeInt(self::$skipInterval); $this->_tiiFile->writeInt(self::$skipInterval);
$this->_tiiFile->writeInt(self::$maxSkipLevels); $this->_tiiFile->writeInt(self::$maxSkipLevels);
/** Dump dictionary header */ /**
* Dump dictionary header
*/
$this->_tiiFile->writeVInt(0); // preffix length $this->_tiiFile->writeVInt(0); // preffix length
$this->_tiiFile->writeString(''); // suffix $this->_tiiFile->writeString(''); // suffix
$this->_tiiFile->writeInt((int)0xFFFFFFFF); // field number $this->_tiiFile->writeInt((int)0xFFFFFFFF); // field number
@ -434,7 +447,7 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
* Term positions is an array( docId => array(pos1, pos2, pos3, ...), ... ) * Term positions is an array( docId => array(pos1, pos2, pos3, ...), ... )
* *
* @param Zend_Search_Lucene_Index_Term $termEntry * @param Zend_Search_Lucene_Index_Term $termEntry
* @param array $termDocs * @param array $termDocs
*/ */
public function addTerm($termEntry, $termDocs) public function addTerm($termEntry, $termDocs)
{ {
@ -469,10 +482,14 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
$skipOffset = 0; $skipOffset = 0;
} }
$term = new Zend_Search_Lucene_Index_Term($termEntry->text, $term = new Zend_Search_Lucene_Index_Term(
$this->_fields[$termEntry->field]->number); $termEntry->text,
$termInfo = new Zend_Search_Lucene_Index_TermInfo(count($termDocs), $this->_fields[$termEntry->field]->number
$freqPointer, $proxPointer, $skipOffset); );
$termInfo = new Zend_Search_Lucene_Index_TermInfo(
count($termDocs),
$freqPointer, $proxPointer, $skipOffset
);
$this->_dumpTermDictEntry($this->_tisFile, $this->_prevTerm, $term, $this->_prevTermInfo, $termInfo); $this->_dumpTermDictEntry($this->_tisFile, $this->_prevTerm, $term, $this->_prevTermInfo, $termInfo);
@ -505,16 +522,17 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
* Dump Term Dictionary segment file entry. * Dump Term Dictionary segment file entry.
* Used to write entry to .tis or .tii files * Used to write entry to .tis or .tii files
* *
* @param Zend_Search_Lucene_Storage_File $dicFile * @param Zend_Search_Lucene_Storage_File $dicFile
* @param Zend_Search_Lucene_Index_Term $prevTerm * @param Zend_Search_Lucene_Index_Term $prevTerm
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_TermInfo $prevTermInfo * @param Zend_Search_Lucene_Index_TermInfo $prevTermInfo
* @param Zend_Search_Lucene_Index_TermInfo $termInfo * @param Zend_Search_Lucene_Index_TermInfo $termInfo
*/ */
protected function _dumpTermDictEntry(Zend_Search_Lucene_Storage_File $dicFile, protected function _dumpTermDictEntry(Zend_Search_Lucene_Storage_File $dicFile,
&$prevTerm, Zend_Search_Lucene_Index_Term $term, &$prevTerm, Zend_Search_Lucene_Index_Term $term,
&$prevTermInfo, Zend_Search_Lucene_Index_TermInfo $termInfo) &$prevTermInfo, Zend_Search_Lucene_Index_TermInfo $termInfo
{ ) {
if (isset($prevTerm) && $prevTerm->field == $term->field) { if (isset($prevTerm) && $prevTerm->field == $term->field) {
$matchedBytes = 0; $matchedBytes = 0;
$maxBytes = min(strlen($prevTerm->text), strlen($term->text)); $maxBytes = min(strlen($prevTerm->text), strlen($term->text));

View File

@ -20,7 +20,9 @@
* @version $Id: DocumentWriter.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: DocumentWriter.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Index_SegmentWriter */ /**
* Zend_Search_Lucene_Index_SegmentWriter
*/
require_once 'Zend/Search/Lucene/Index/SegmentWriter.php'; require_once 'Zend/Search/Lucene/Index/SegmentWriter.php';
/** /**
@ -52,7 +54,7 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
* Object constructor. * Object constructor.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @param string $name * @param string $name
*/ */
public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name) public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name)
{ {
@ -66,13 +68,15 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
/** /**
* Adds a document to this segment. * Adds a document to this segment.
* *
* @param Zend_Search_Lucene_Document $document * @param Zend_Search_Lucene_Document $document
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function addDocument(Zend_Search_Lucene_Document $document) public function addDocument(Zend_Search_Lucene_Document $document)
{ {
/** Zend_Search_Lucene_Search_Similarity */ /**
require_once 'Zend/Search/Lucene/Search/Similarity.php'; * Zend_Search_Lucene_Search_Similarity
*/
include_once 'Zend/Search/Lucene/Search/Similarity.php';
$storedFields = array(); $storedFields = array();
$docNorms = array(); $docNorms = array();
@ -85,14 +89,16 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
/** /**
* @todo term vector storing support * @todo term vector storing support
*/ */
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Store term vector functionality is not supported yet.'); throw new Zend_Search_Lucene_Exception('Store term vector functionality is not supported yet.');
} }
if ($field->isIndexed) { if ($field->isIndexed) {
if ($field->isTokenized) { if ($field->isTokenized) {
/** Zend_Search_Lucene_Analysis_Analyzer */ /**
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; * Zend_Search_Lucene_Analysis_Analyzer
*/
include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault(); $analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
$analyzer->setInput($field->value, $field->encoding); $analyzer->setInput($field->value, $field->encoding);
@ -123,10 +129,16 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
$field = clone($field); $field = clone($field);
$field->isIndexed = $field->isTokenized = false; $field->isIndexed = $field->isTokenized = false;
} else { } else {
$docNorms[$field->name] = chr($similarity->encodeNorm( $similarity->lengthNorm($field->name, $docNorms[$field->name] = chr(
$tokenCounter)* $similarity->encodeNorm(
$similarity->lengthNorm(
$field->name,
$tokenCounter
)*
$document->boost* $document->boost*
$field->boost )); $field->boost
)
);
} }
} else if (($fieldUtf8Value = $field->getUtf8Value()) == '') { } else if (($fieldUtf8Value = $field->getUtf8Value()) == '') {
// Field contains empty value. Treat it as non-indexed and non-tokenized // Field contains empty value. Treat it as non-indexed and non-tokenized
@ -147,9 +159,13 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
} }
$this->_termDocs[$termKey][$this->_docCount][] = 0; // position $this->_termDocs[$termKey][$this->_docCount][] = 0; // position
$docNorms[$field->name] = chr($similarity->encodeNorm( $similarity->lengthNorm($field->name, 1)* $docNorms[$field->name] = chr(
$similarity->encodeNorm(
$similarity->lengthNorm($field->name, 1)*
$document->boost* $document->boost*
$field->boost )); $field->boost
)
);
} }
} }
@ -166,14 +182,16 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
} }
if (!isset($this->_norms[$fieldName])) { if (!isset($this->_norms[$fieldName])) {
$this->_norms[$fieldName] = str_repeat(chr($similarity->encodeNorm( $similarity->lengthNorm($fieldName, 0) )), $this->_norms[$fieldName] = str_repeat(
$this->_docCount); chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, 0))),
$this->_docCount
);
} }
if (isset($docNorms[$fieldName])){ if (isset($docNorms[$fieldName])) {
$this->_norms[$fieldName] .= $docNorms[$fieldName]; $this->_norms[$fieldName] .= $docNorms[$fieldName];
} else { } else {
$this->_norms[$fieldName] .= chr($similarity->encodeNorm( $similarity->lengthNorm($fieldName, 0) )); $this->_norms[$fieldName] .= chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, 0)));
} }
} }
@ -214,16 +232,20 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
$this->_generateCFS(); $this->_generateCFS();
/** Zend_Search_Lucene_Index_SegmentInfo */ /**
require_once 'Zend/Search/Lucene/Index/SegmentInfo.php'; * Zend_Search_Lucene_Index_SegmentInfo
*/
include_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
return new Zend_Search_Lucene_Index_SegmentInfo($this->_directory, return new Zend_Search_Lucene_Index_SegmentInfo(
$this->_name, $this->_directory,
$this->_docCount, $this->_name,
-1, $this->_docCount,
null, -1,
true, null,
true); true,
true
);
} }
} }

View File

@ -20,7 +20,9 @@
* @version $Id: StreamWriter.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: StreamWriter.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Index_SegmentWriter */ /**
* Zend_Search_Lucene_Index_SegmentWriter
*/
require_once 'Zend/Search/Lucene/Index/SegmentWriter.php'; require_once 'Zend/Search/Lucene/Index/SegmentWriter.php';
/** /**
@ -36,7 +38,7 @@ class Zend_Search_Lucene_Index_SegmentWriter_StreamWriter extends Zend_Search_Lu
* Object constructor. * Object constructor.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @param string $name * @param string $name
*/ */
public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name) public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name)
{ {
@ -79,16 +81,20 @@ class Zend_Search_Lucene_Index_SegmentWriter_StreamWriter extends Zend_Search_Lu
$this->_dumpFNM(); $this->_dumpFNM();
$this->_generateCFS(); $this->_generateCFS();
/** Zend_Search_Lucene_Index_SegmentInfo */ /**
require_once 'Zend/Search/Lucene/Index/SegmentInfo.php'; * Zend_Search_Lucene_Index_SegmentInfo
*/
include_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
return new Zend_Search_Lucene_Index_SegmentInfo($this->_directory, return new Zend_Search_Lucene_Index_SegmentInfo(
$this->_name, $this->_directory,
$this->_docCount, $this->_name,
-1, $this->_docCount,
null, -1,
true, null,
true); true,
true
);
} }
} }

View File

@ -75,8 +75,8 @@ class Zend_Search_Lucene_Index_Term
/** /**
* Get term prefix * Get term prefix
* *
* @param string $str * @param string $str
* @param integer $length * @param integer $length
* @return string * @return string
*/ */
public static function getPrefix($str, $length) public static function getPrefix($str, $length)
@ -110,7 +110,7 @@ class Zend_Search_Lucene_Index_Term
/** /**
* Get UTF-8 string length * Get UTF-8 string length
* *
* @param string $str * @param string $str
* @return string * @return string
*/ */
public static function getLength($str) public static function getLength($str)

View File

@ -20,7 +20,9 @@
* @version $Id: TermsPriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: TermsPriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_PriorityQueue */ /**
* Zend_Search_Lucene_PriorityQueue
*/
require_once 'Zend/Search/Lucene/PriorityQueue.php'; require_once 'Zend/Search/Lucene/PriorityQueue.php';
/** /**
@ -37,8 +39,8 @@ class Zend_Search_Lucene_Index_TermsPriorityQueue extends Zend_Search_Lucene_Pri
* *
* Returns true, if $termsStream1 is "less" than $termsStream2; else otherwise * Returns true, if $termsStream1 is "less" than $termsStream2; else otherwise
* *
* @param mixed $termsStream1 * @param mixed $termsStream1
* @param mixed $termsStream2 * @param mixed $termsStream2
* @return boolean * @return boolean
*/ */
protected function _less($termsStream1, $termsStream2) protected function _less($termsStream1, $termsStream2)

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_LockManager */ /**
* Zend_Search_Lucene_LockManager
*/
require_once 'Zend/Search/Lucene/LockManager.php'; require_once 'Zend/Search/Lucene/LockManager.php';
@ -161,20 +163,21 @@ class Zend_Search_Lucene_Index_Writer
* Create empty index * Create empty index
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @param integer $generation * @param integer $generation
* @param integer $nameCount * @param integer $nameCount
*/ */
public static function createIndex(Zend_Search_Lucene_Storage_Directory $directory, $generation, $nameCount) public static function createIndex(Zend_Search_Lucene_Storage_Directory $directory, $generation, $nameCount)
{ {
if ($generation == 0) { if ($generation == 0) {
// Create index in pre-2.1 mode // Create index in pre-2.1 mode
foreach ($directory->fileList() as $file) { foreach ($directory->fileList() as $file) {
if ($file == 'deletable' || if ($file == 'deletable'
$file == 'segments' || || $file == 'segments'
isset(self::$_indexExtensions[ substr($file, strlen($file)-4)]) || || isset(self::$_indexExtensions[ substr($file, strlen($file)-4)])
preg_match('/\.f\d+$/i', $file) /* matches <segment_name>.f<decimal_nmber> file names */) { || preg_match('/\.f\d+$/i', $file) /* matches <segment_name>.f<decimal_nmber> file names */
) {
$directory->deleteFile($file); $directory->deleteFile($file);
} }
} }
$segmentsFile = $directory->createFile('segments'); $segmentsFile = $directory->createFile('segments');
@ -216,9 +219,9 @@ class Zend_Search_Lucene_Index_Writer
* Open the index for writing * Open the index for writing
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @param array $segmentInfos * @param array $segmentInfos
* @param integer $targetFormatVersion * @param integer $targetFormatVersion
* @param Zend_Search_Lucene_Storage_File $cleanUpLock * @param Zend_Search_Lucene_Storage_File $cleanUpLock
*/ */
public function __construct(Zend_Search_Lucene_Storage_Directory $directory, &$segmentInfos, $targetFormatVersion) public function __construct(Zend_Search_Lucene_Storage_Directory $directory, &$segmentInfos, $targetFormatVersion)
{ {
@ -234,8 +237,10 @@ class Zend_Search_Lucene_Index_Writer
*/ */
public function addDocument(Zend_Search_Lucene_Document $document) public function addDocument(Zend_Search_Lucene_Document $document)
{ {
/** Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter */ /**
require_once 'Zend/Search/Lucene/Index/SegmentWriter/DocumentWriter.php'; * Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter
*/
include_once 'Zend/Search/Lucene/Index/SegmentWriter/DocumentWriter.php';
if ($this->_currentSegment === null) { if ($this->_currentSegment === null) {
$this->_currentSegment = $this->_currentSegment =
@ -373,10 +378,14 @@ class Zend_Search_Lucene_Index_Writer
{ {
$newName = $this->_newSegmentName(); $newName = $this->_newSegmentName();
/** Zend_Search_Lucene_Index_SegmentMerger */ /**
require_once 'Zend/Search/Lucene/Index/SegmentMerger.php'; * Zend_Search_Lucene_Index_SegmentMerger
$merger = new Zend_Search_Lucene_Index_SegmentMerger($this->_directory, */
$newName); include_once 'Zend/Search/Lucene/Index/SegmentMerger.php';
$merger = new Zend_Search_Lucene_Index_SegmentMerger(
$this->_directory,
$newName
);
foreach ($segments as $segmentInfo) { foreach ($segments as $segmentInfo) {
$merger->addSource($segmentInfo); $merger->addSource($segmentInfo);
$this->_segmentsToDelete[$segmentInfo->getName()] = $segmentInfo->getName(); $this->_segmentsToDelete[$segmentInfo->getName()] = $segmentInfo->getName();
@ -517,16 +526,20 @@ class Zend_Search_Lucene_Index_Writer
$isCompound = true; $isCompound = true;
} }
/** Zend_Search_Lucene_Index_SegmentInfo */ /**
require_once 'Zend/Search/Lucene/Index/SegmentInfo.php'; * Zend_Search_Lucene_Index_SegmentInfo
*/
include_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
$this->_segmentInfos[$segName] = $this->_segmentInfos[$segName] =
new Zend_Search_Lucene_Index_SegmentInfo($this->_directory, new Zend_Search_Lucene_Index_SegmentInfo(
$segName, $this->_directory,
$segSize, $segName,
$delGen, $segSize,
$docStoreOptions, $delGen,
$hasSingleNormFile, $docStoreOptions,
$isCompound); $hasSingleNormFile,
$isCompound
);
} else { } else {
// Retrieve actual deletions file generation number // Retrieve actual deletions file generation number
$delGen = $this->_segmentInfos[$segName]->getDelGen(); $delGen = $this->_segmentInfos[$segName]->getDelGen();
@ -593,7 +606,9 @@ class Zend_Search_Lucene_Index_Writer
$newSegmentFile->writeInt($segmentsCount); // Update segments count $newSegmentFile->writeInt($segmentsCount); // Update segments count
$newSegmentFile->close(); $newSegmentFile->close();
} catch (Exception $e) { } catch (Exception $e) {
/** Restore previous index generation */ /**
* Restore previous index generation
*/
$generation--; $generation--;
$genFile->seek(4, SEEK_SET); $genFile->seek(4, SEEK_SET);
// Write generation number twice // Write generation number twice
@ -603,7 +618,7 @@ class Zend_Search_Lucene_Index_Writer
Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory); Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
// Throw the exception // Throw the exception
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e); throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
} }
@ -672,8 +687,9 @@ class Zend_Search_Lucene_Index_Writer
// one of per segment files ('<segment_name>.<ext>') // one of per segment files ('<segment_name>.<ext>')
$segmentName = substr($file, 0, strlen($file) - 4); $segmentName = substr($file, 0, strlen($file) - 4);
// Check if it's not one of the segments in the current segments set // Check if it's not one of the segments in the current segments set
if (!isset($segments[$segmentName]) && if (!isset($segments[$segmentName])
($this->_currentSegment === null || $this->_currentSegment->getName() != $segmentName)) { && ($this->_currentSegment === null || $this->_currentSegment->getName() != $segmentName)
) {
$filesToDelete[] = $file; $filesToDelete[] = $file;
$filesTypes[] = 3; // second group of files for deletions $filesTypes[] = 3; // second group of files for deletions
$filesNumbers[] = (int)base_convert(substr($file, 1 /* skip '_' */, strlen($file)-5), 36, 10); // order by segment number $filesNumbers[] = (int)base_convert(substr($file, 1 /* skip '_' */, strlen($file)-5), 36, 10); // order by segment number
@ -702,14 +718,20 @@ class Zend_Search_Lucene_Index_Writer
} }
// Reorder files for deleting // Reorder files for deleting
array_multisort($filesTypes, SORT_ASC, SORT_NUMERIC, array_multisort(
$filesNumbers, SORT_ASC, SORT_NUMERIC, $filesTypes, SORT_ASC, SORT_NUMERIC,
$filesToDelete, SORT_ASC, SORT_STRING); $filesNumbers, SORT_ASC, SORT_NUMERIC,
$filesToDelete, SORT_ASC, SORT_STRING
);
foreach ($filesToDelete as $file) { foreach ($filesToDelete as $file) {
try { try {
/** Skip shared docstore segments deleting */ /**
/** @todo Process '.cfx' files to check if them are already unused */ * Skip shared docstore segments deleting
*/
/**
* @todo Process '.cfx' files to check if them are already unused
*/
if (substr($file, strlen($file)-4) != '.cfx') { if (substr($file, strlen($file)-4) != '.cfx') {
$this->_directory->deleteFile($file); $this->_directory->deleteFile($file);
} }
@ -768,7 +790,7 @@ class Zend_Search_Lucene_Index_Writer
/** /**
* Merges the provided indexes into this index. * Merges the provided indexes into this index.
* *
* @param array $readers * @param array $readers
* @return void * @return void
*/ */
public function addIndexes($readers) public function addIndexes($readers)

View File

@ -12,27 +12,37 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Index_TermsStream_Interface */ /**
* Zend_Search_Lucene_Index_TermsStream_Interface
*/
require_once 'Zend/Search/Lucene/Index/TermsStream/Interface.php'; require_once 'Zend/Search/Lucene/Index/TermsStream/Interface.php';
/** Classes used within Zend_Search_Lucene_Interface API */ /**
* Classes used within Zend_Search_Lucene_Interface API
*/
/** Zend_Search_Lucene_Document */ /**
* Zend_Search_Lucene_Document
*/
require_once 'Zend/Search/Lucene/Document.php'; require_once 'Zend/Search/Lucene/Document.php';
/** Zend_Search_Lucene_Index_Term */ /**
* Zend_Search_Lucene_Index_Term
*/
require_once 'Zend/Search/Lucene/Index/Term.php'; require_once 'Zend/Search/Lucene/Index/Term.php';
/** Zend_Search_Lucene_Index_DocsFilter */ /**
* Zend_Search_Lucene_Index_DocsFilter
*/
require_once 'Zend/Search/Lucene/Index/DocsFilter.php'; require_once 'Zend/Search/Lucene/Index/DocsFilter.php';
@ -51,7 +61,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* 0 means pre-2.1 index format * 0 means pre-2.1 index format
* -1 means there are no segments files. * -1 means there are no segments files.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @return integer * @return integer
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -60,7 +70,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
/** /**
* Get segments file name * Get segments file name
* *
* @param integer $generation * @param integer $generation
* @return string * @return string
*/ */
public static function getSegmentFileName($generation); public static function getSegmentFileName($generation);
@ -76,7 +86,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* Set index format version. * Set index format version.
* Index is converted to this format at the nearest upfdate time * Index is converted to this format at the nearest upfdate time
* *
* @param int $formatVersion * @param int $formatVersion
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function setFormatVersion($formatVersion); public function setFormatVersion($formatVersion);
@ -114,7 +124,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
/** /**
* Checks, that document is deleted * Checks, that document is deleted
* *
* @param integer $id * @param integer $id
* @return boolean * @return boolean
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/ */
@ -253,7 +263,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* of Zend_Search_Lucene_Search_QueryHit objects. * of Zend_Search_Lucene_Search_QueryHit objects.
* Input is a string or Zend_Search_Lucene_Search_Query. * Input is a string or Zend_Search_Lucene_Search_Query.
* *
* @param mixed $query * @param mixed $query
* @return array Zend_Search_Lucene_Search_QueryHit * @return array Zend_Search_Lucene_Search_QueryHit
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -262,7 +272,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
/** /**
* Returns a list of all unique field names that exist in this index. * Returns a list of all unique field names that exist in this index.
* *
* @param boolean $indexed * @param boolean $indexed
* @return array * @return array
*/ */
public function getFieldNames($indexed = false); public function getFieldNames($indexed = false);
@ -271,7 +281,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* Returns a Zend_Search_Lucene_Document object for the document * Returns a Zend_Search_Lucene_Document object for the document
* number $id in this index. * number $id in this index.
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @return Zend_Search_Lucene_Document * @return Zend_Search_Lucene_Document
*/ */
public function getDocument($id); public function getDocument($id);
@ -281,7 +291,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* *
* Is used for query optimization. * Is used for query optimization.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return boolean * @return boolean
*/ */
public function hasTerm(Zend_Search_Lucene_Index_Term $term); public function hasTerm(Zend_Search_Lucene_Index_Term $term);
@ -289,8 +299,8 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
/** /**
* Returns IDs of all the documents containing term. * Returns IDs of all the documents containing term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
*/ */
public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null); public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
@ -301,8 +311,8 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* It performs the same operation as termDocs, but return result as * It performs the same operation as termDocs, but return result as
* Zend_Search_Lucene_Index_DocsFilter object * Zend_Search_Lucene_Index_DocsFilter object
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return Zend_Search_Lucene_Index_DocsFilter * @return Zend_Search_Lucene_Index_DocsFilter
*/ */
public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null); public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
@ -311,8 +321,8 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* Returns an array of all term freqs. * Returns an array of all term freqs.
* Return array structure: array( docId => freq, ...) * Return array structure: array( docId => freq, ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return integer * @return integer
*/ */
public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null); public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
@ -321,8 +331,8 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* Returns an array of all term positions in the documents. * Returns an array of all term positions in the documents.
* Return array structure: array( docId => array( pos1, pos2, ...), ...) * Return array structure: array( docId => array( pos1, pos2, ...), ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
*/ */
public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null); public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
@ -330,7 +340,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
/** /**
* Returns the number of documents in this index containing the $term. * Returns the number of documents in this index containing the $term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return integer * @return integer
*/ */
public function docFreq(Zend_Search_Lucene_Index_Term $term); public function docFreq(Zend_Search_Lucene_Index_Term $term);
@ -345,8 +355,8 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
/** /**
* Returns a normalization factor for "field, document" pair. * Returns a normalization factor for "field, document" pair.
* *
* @param integer $id * @param integer $id
* @param string $fieldName * @param string $fieldName
* @return float * @return float
*/ */
public function norm($id, $fieldName); public function norm($id, $fieldName);
@ -362,7 +372,7 @@ interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStr
* Deletes a document from the index. * Deletes a document from the index.
* $id is an internal document id * $id is an internal document id
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function delete($id); public function delete($id);

View File

@ -12,26 +12,30 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: LockManager.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: LockManager.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Storage_Directory */ /**
* Zend_Search_Lucene_Storage_Directory
*/
require_once 'Zend/Search/Lucene/Storage/Directory.php'; require_once 'Zend/Search/Lucene/Storage/Directory.php';
/** Zend_Search_Lucene_Storage_File */ /**
* Zend_Search_Lucene_Storage_File
*/
require_once 'Zend/Search/Lucene/Storage/File.php'; require_once 'Zend/Search/Lucene/Storage/File.php';
/** /**
* This is an utility class which provides index locks processing functionality * This is an utility class which provides index locks processing functionality
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_LockManager class Zend_Search_Lucene_LockManager
{ {
@ -46,7 +50,7 @@ class Zend_Search_Lucene_LockManager
/** /**
* Obtain exclusive write lock on the index * Obtain exclusive write lock on the index
* *
* @param Zend_Search_Lucene_Storage_Directory $lockDirectory * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -54,7 +58,7 @@ class Zend_Search_Lucene_LockManager
{ {
$lock = $lockDirectory->createFile(self::WRITE_LOCK_FILE); $lock = $lockDirectory->createFile(self::WRITE_LOCK_FILE);
if (!$lock->lock(LOCK_EX)) { if (!$lock->lock(LOCK_EX)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock'); throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock');
} }
return $lock; return $lock;
@ -91,7 +95,7 @@ class Zend_Search_Lucene_LockManager
* of opportunity for another process to gain an exclusive lock when * of opportunity for another process to gain an exclusive lock when
* it shoudln't be allowed to). * it shoudln't be allowed to).
* *
* @param Zend_Search_Lucene_Storage_Directory $lockDirectory * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -99,7 +103,7 @@ class Zend_Search_Lucene_LockManager
{ {
$lock = $lockDirectory->createFile(self::READ_LOCK_PROCESSING_LOCK_FILE); $lock = $lockDirectory->createFile(self::READ_LOCK_PROCESSING_LOCK_FILE);
if (!$lock->lock(LOCK_EX)) { if (!$lock->lock(LOCK_EX)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive lock for the read lock processing file'); throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive lock for the read lock processing file');
} }
return $lock; return $lock;
@ -125,7 +129,7 @@ class Zend_Search_Lucene_LockManager
* *
* It doesn't block other read or update processes, but prevent index from the premature cleaning-up * It doesn't block other read or update processes, but prevent index from the premature cleaning-up
* *
* @param Zend_Search_Lucene_Storage_Directory $defaultLockDirectory * @param Zend_Search_Lucene_Storage_Directory $defaultLockDirectory
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -133,7 +137,7 @@ class Zend_Search_Lucene_LockManager
{ {
$lock = $lockDirectory->createFile(self::READ_LOCK_FILE); $lock = $lockDirectory->createFile(self::READ_LOCK_FILE);
if (!$lock->lock(LOCK_SH)) { if (!$lock->lock(LOCK_SH)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Can\'t obtain shared reading index lock'); throw new Zend_Search_Lucene_Exception('Can\'t obtain shared reading index lock');
} }
return $lock; return $lock;
@ -153,7 +157,7 @@ class Zend_Search_Lucene_LockManager
/** /**
* Escalate Read lock to exclusive level * Escalate Read lock to exclusive level
* *
* @param Zend_Search_Lucene_Storage_Directory $lockDirectory * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
* @return boolean * @return boolean
*/ */
public static function escalateReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory) public static function escalateReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
@ -210,7 +214,7 @@ class Zend_Search_Lucene_LockManager
* *
* Returns lock object on success and false otherwise (doesn't block execution) * Returns lock object on success and false otherwise (doesn't block execution)
* *
* @param Zend_Search_Lucene_Storage_Directory $lockDirectory * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
* @return mixed * @return mixed
*/ */
public static function obtainOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory) public static function obtainOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)

View File

@ -12,24 +12,26 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: MultiSearcher.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: MultiSearcher.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Interface */ /**
* Zend_Search_Lucene_Interface
*/
require_once 'Zend/Search/Lucene/Interface.php'; require_once 'Zend/Search/Lucene/Interface.php';
/** /**
* Multisearcher allows to search through several independent indexes. * Multisearcher allows to search through several independent indexes.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_Interface class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_Interface
{ {
@ -44,7 +46,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Object constructor. * Object constructor.
* *
* @param array $indices Arrays of indices for search * @param array $indices Arrays of indices for search
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct($indices = array()) public function __construct($indices = array())
@ -53,7 +55,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if (!$index instanceof Zend_Search_Lucene_Interface) { if (!$index instanceof Zend_Search_Lucene_Interface) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('sub-index objects have to implement Zend_Search_Lucene_Interface.'); throw new Zend_Search_Lucene_Exception('sub-index objects have to implement Zend_Search_Lucene_Interface.');
} }
} }
@ -77,20 +79,20 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* 0 means pre-2.1 index format * 0 means pre-2.1 index format
* -1 means there are no segments files. * -1 means there are no segments files.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @return integer * @return integer
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory) public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception("Generation number can't be retrieved for multi-searcher"); throw new Zend_Search_Lucene_Exception("Generation number can't be retrieved for multi-searcher");
} }
/** /**
* Get segments file name * Get segments file name
* *
* @param integer $generation * @param integer $generation
* @return string * @return string
*/ */
public static function getSegmentFileName($generation) public static function getSegmentFileName($generation)
@ -106,7 +108,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
*/ */
public function getFormatVersion() public function getFormatVersion()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception("Format version can't be retrieved for multi-searcher"); throw new Zend_Search_Lucene_Exception("Format version can't be retrieved for multi-searcher");
} }
@ -130,7 +132,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
*/ */
public function getDirectory() public function getDirectory()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception("Index directory can't be retrieved for multi-searcher"); throw new Zend_Search_Lucene_Exception("Index directory can't be retrieved for multi-searcher");
} }
@ -181,7 +183,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Checks, that document is deleted * Checks, that document is deleted
* *
* @param integer $id * @param integer $id
* @return boolean * @return boolean
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/ */
@ -197,7 +199,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
$id -= $indexCount; $id -= $indexCount;
} }
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
} }
@ -229,7 +231,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public static function getDefaultSearchField() public static function getDefaultSearchField()
{ {
if (count($this->_indices) == 0) { if (count($this->_indices) == 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices list is empty'); throw new Zend_Search_Lucene_Exception('Indices list is empty');
} }
@ -237,7 +239,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if ($index->getDefaultSearchField() !== $defaultSearchField) { if ($index->getDefaultSearchField() !== $defaultSearchField) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices have different default search field.'); throw new Zend_Search_Lucene_Exception('Indices have different default search field.');
} }
} }
@ -270,7 +272,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public static function getResultSetLimit() public static function getResultSetLimit()
{ {
if (count($this->_indices) == 0) { if (count($this->_indices) == 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices list is empty'); throw new Zend_Search_Lucene_Exception('Indices list is empty');
} }
@ -278,7 +280,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if ($index->getResultSetLimit() !== $defaultResultSetLimit) { if ($index->getResultSetLimit() !== $defaultResultSetLimit) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices have different default search field.'); throw new Zend_Search_Lucene_Exception('Indices have different default search field.');
} }
} }
@ -300,7 +302,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public function getMaxBufferedDocs() public function getMaxBufferedDocs()
{ {
if (count($this->_indices) == 0) { if (count($this->_indices) == 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices list is empty'); throw new Zend_Search_Lucene_Exception('Indices list is empty');
} }
@ -308,7 +310,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if ($index->getMaxBufferedDocs() !== $maxBufferedDocs) { if ($index->getMaxBufferedDocs() !== $maxBufferedDocs) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices have different default search field.'); throw new Zend_Search_Lucene_Exception('Indices have different default search field.');
} }
} }
@ -349,7 +351,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public function getMaxMergeDocs() public function getMaxMergeDocs()
{ {
if (count($this->_indices) == 0) { if (count($this->_indices) == 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices list is empty'); throw new Zend_Search_Lucene_Exception('Indices list is empty');
} }
@ -357,7 +359,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if ($index->getMaxMergeDocs() !== $maxMergeDocs) { if ($index->getMaxMergeDocs() !== $maxMergeDocs) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices have different default search field.'); throw new Zend_Search_Lucene_Exception('Indices have different default search field.');
} }
} }
@ -405,7 +407,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public function getMergeFactor() public function getMergeFactor()
{ {
if (count($this->_indices) == 0) { if (count($this->_indices) == 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices list is empty'); throw new Zend_Search_Lucene_Exception('Indices list is empty');
} }
@ -413,7 +415,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if ($index->getMergeFactor() !== $mergeFactor) { if ($index->getMergeFactor() !== $mergeFactor) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices have different default search field.'); throw new Zend_Search_Lucene_Exception('Indices have different default search field.');
} }
} }
@ -450,7 +452,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* of Zend_Search_Lucene_Search_QueryHit objects. * of Zend_Search_Lucene_Search_QueryHit objects.
* Input is a string or Zend_Search_Lucene_Search_Query. * Input is a string or Zend_Search_Lucene_Search_Query.
* *
* @param mixed $query * @param mixed $query
* @return array Zend_Search_Lucene_Search_QueryHit * @return array Zend_Search_Lucene_Search_QueryHit
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -476,7 +478,9 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
$hitsList[] = $hits; $hitsList[] = $hits;
} }
/** @todo Implement advanced sorting */ /**
* @todo Implement advanced sorting
*/
return call_user_func_array('array_merge', $hitsList); return call_user_func_array('array_merge', $hitsList);
} }
@ -484,7 +488,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Returns a list of all unique field names that exist in this index. * Returns a list of all unique field names that exist in this index.
* *
* @param boolean $indexed * @param boolean $indexed
* @return array * @return array
*/ */
public function getFieldNames($indexed = false) public function getFieldNames($indexed = false)
@ -502,7 +506,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* Returns a Zend_Search_Lucene_Document object for the document * Returns a Zend_Search_Lucene_Document object for the document
* number $id in this index. * number $id in this index.
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @return Zend_Search_Lucene_Document * @return Zend_Search_Lucene_Document
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/ */
@ -523,7 +527,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
$id -= $indexCount; $id -= $indexCount;
} }
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
} }
@ -532,7 +536,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* *
* Is used for query optimization. * Is used for query optimization.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return boolean * @return boolean
*/ */
public function hasTerm(Zend_Search_Lucene_Index_Term $term) public function hasTerm(Zend_Search_Lucene_Index_Term $term)
@ -549,15 +553,15 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Returns IDs of all the documents containing term. * Returns IDs of all the documents containing term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
{ {
if ($docsFilter != null) { if ($docsFilter != null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher'); throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher');
} }
@ -586,14 +590,14 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* It performs the same operation as termDocs, but return result as * It performs the same operation as termDocs, but return result as
* Zend_Search_Lucene_Index_DocsFilter object * Zend_Search_Lucene_Index_DocsFilter object
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return Zend_Search_Lucene_Index_DocsFilter * @return Zend_Search_Lucene_Index_DocsFilter
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher'); throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher');
} }
@ -601,15 +605,15 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* Returns an array of all term freqs. * Returns an array of all term freqs.
* Return array structure: array( docId => freq, ...) * Return array structure: array( docId => freq, ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return integer * @return integer
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
{ {
if ($docsFilter != null) { if ($docsFilter != null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher'); throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher');
} }
@ -639,15 +643,15 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* Returns an array of all term positions in the documents. * Returns an array of all term positions in the documents.
* Return array structure: array( docId => array( pos1, pos2, ...), ...) * Return array structure: array( docId => array( pos1, pos2, ...), ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
{ {
if ($docsFilter != null) { if ($docsFilter != null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher'); throw new Zend_Search_Lucene_Exception('Document filters could not used with multi-searcher');
} }
@ -676,7 +680,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Returns the number of documents in this index containing the $term. * Returns the number of documents in this index containing the $term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return integer * @return integer
*/ */
public function docFreq(Zend_Search_Lucene_Index_Term $term) public function docFreq(Zend_Search_Lucene_Index_Term $term)
@ -699,7 +703,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public function getSimilarity() public function getSimilarity()
{ {
if (count($this->_indices) == 0) { if (count($this->_indices) == 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices list is empty'); throw new Zend_Search_Lucene_Exception('Indices list is empty');
} }
@ -707,7 +711,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
foreach ($this->_indices as $index) { foreach ($this->_indices as $index) {
if ($index->getSimilarity() !== $similarity) { if ($index->getSimilarity() !== $similarity) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Indices have different similarity.'); throw new Zend_Search_Lucene_Exception('Indices have different similarity.');
} }
} }
@ -718,8 +722,8 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Returns a normalization factor for "field, document" pair. * Returns a normalization factor for "field, document" pair.
* *
* @param integer $id * @param integer $id
* @param string $fieldName * @param string $fieldName
* @return float * @return float
*/ */
public function norm($id, $fieldName) public function norm($id, $fieldName)
@ -757,7 +761,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
* Deletes a document from the index. * Deletes a document from the index.
* $id is an internal document id * $id is an internal document id
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function delete($id) public function delete($id)
@ -773,7 +777,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
$id -= $indexCount; $id -= $indexCount;
} }
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
} }
@ -793,13 +797,13 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Set callback for choosing target index. * Set callback for choosing target index.
* *
* @param callback $callback * @param callback $callback
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function setDocumentDistributorCallback($callback) public function setDocumentDistributorCallback($callback)
{ {
if ($callback !== null && !is_callable($callback)) { if ($callback !== null && !is_callable($callback)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('$callback parameter must be a valid callback.'); throw new Zend_Search_Lucene_Exception('$callback parameter must be a valid callback.');
} }
@ -819,7 +823,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
/** /**
* Adds a document to this index. * Adds a document to this index.
* *
* @param Zend_Search_Lucene_Document $document * @param Zend_Search_Lucene_Document $document
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function addDocument(Zend_Search_Lucene_Document $document) public function addDocument(Zend_Search_Lucene_Document $document)
@ -885,8 +889,10 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
public function resetTermsStream() public function resetTermsStream()
{ {
if ($this->_termsStream === null) { if ($this->_termsStream === null) {
/** Zend_Search_Lucene_TermStreamsPriorityQueue */ /**
require_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php'; * Zend_Search_Lucene_TermStreamsPriorityQueue
*/
include_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php';
$this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_indices); $this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_indices);
} else { } else {

View File

@ -12,11 +12,11 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: PriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: PriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
@ -30,10 +30,10 @@
* *
* It provides O(log(N)) time of put/pop operations, where N is a size of queue * It provides O(log(N)) time of put/pop operations, where N is a size of queue
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
abstract class Zend_Search_Lucene_PriorityQueue abstract class Zend_Search_Lucene_PriorityQueue
{ {
@ -133,9 +133,9 @@ abstract class Zend_Search_Lucene_PriorityQueue
$childId = ($nodeId << 1) + 1; // First child $childId = ($nodeId << 1) + 1; // First child
// Choose smaller child // Choose smaller child
if (($childId+1) < $lastId && if (($childId+1) < $lastId
$this->_less($this->_heap[$childId+1], $this->_heap[$childId]) && $this->_less($this->_heap[$childId+1], $this->_heap[$childId])
) { ) {
$childId++; $childId++;
} }
} }
@ -162,8 +162,8 @@ abstract class Zend_Search_Lucene_PriorityQueue
* *
* Returns true, if $el1 is less than $el2; else otherwise * Returns true, if $el1 is less than $el2; else otherwise
* *
* @param mixed $el1 * @param mixed $el1
* @param mixed $el2 * @param mixed $el2
* @return boolean * @return boolean
*/ */
abstract protected function _less($el1, $el2); abstract protected function _less($el1, $el2);

View File

@ -12,14 +12,16 @@
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately. * to license@zend.com so we can send you a copy immediately.
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Proxy.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Proxy.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Interface */ /**
* Zend_Search_Lucene_Interface
*/
require_once 'Zend/Search/Lucene/Interface.php'; require_once 'Zend/Search/Lucene/Interface.php';
@ -28,10 +30,10 @@ require_once 'Zend/Search/Lucene/Interface.php';
* *
* It tracks, when index object goes out of scope and forces ndex closing * It tracks, when index object goes out of scope and forces ndex closing
* *
* @category Zend * @category Zend
* @package Zend_Search_Lucene * @package Zend_Search_Lucene
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
{ {
@ -72,7 +74,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* 0 means pre-2.1 index format * 0 means pre-2.1 index format
* -1 means there are no segments files. * -1 means there are no segments files.
* *
* @param Zend_Search_Lucene_Storage_Directory $directory * @param Zend_Search_Lucene_Storage_Directory $directory
* @return integer * @return integer
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -84,7 +86,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
/** /**
* Get segments file name * Get segments file name
* *
* @param integer $generation * @param integer $generation
* @return string * @return string
*/ */
public static function getSegmentFileName($generation) public static function getSegmentFileName($generation)
@ -106,7 +108,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* Set index format version. * Set index format version.
* Index is converted to this format at the nearest upfdate time * Index is converted to this format at the nearest upfdate time
* *
* @param int $formatVersion * @param int $formatVersion
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function setFormatVersion($formatVersion) public function setFormatVersion($formatVersion)
@ -159,7 +161,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
/** /**
* Checks, that document is deleted * Checks, that document is deleted
* *
* @param integer $id * @param integer $id
* @return boolean * @return boolean
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/ */
@ -333,7 +335,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* of Zend_Search_Lucene_Search_QueryHit objects. * of Zend_Search_Lucene_Search_QueryHit objects.
* Input is a string or Zend_Search_Lucene_Search_Query. * Input is a string or Zend_Search_Lucene_Search_Query.
* *
* @param mixed $query * @param mixed $query
* @return array Zend_Search_Lucene_Search_QueryHit * @return array Zend_Search_Lucene_Search_QueryHit
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -349,7 +351,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
/** /**
* Returns a list of all unique field names that exist in this index. * Returns a list of all unique field names that exist in this index.
* *
* @param boolean $indexed * @param boolean $indexed
* @return array * @return array
*/ */
public function getFieldNames($indexed = false) public function getFieldNames($indexed = false)
@ -361,7 +363,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* Returns a Zend_Search_Lucene_Document object for the document * Returns a Zend_Search_Lucene_Document object for the document
* number $id in this index. * number $id in this index.
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @return Zend_Search_Lucene_Document * @return Zend_Search_Lucene_Document
*/ */
public function getDocument($id) public function getDocument($id)
@ -374,7 +376,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* *
* Is used for query optimization. * Is used for query optimization.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return boolean * @return boolean
*/ */
public function hasTerm(Zend_Search_Lucene_Index_Term $term) public function hasTerm(Zend_Search_Lucene_Index_Term $term)
@ -385,8 +387,8 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
/** /**
* Returns IDs of all the documents containing term. * Returns IDs of all the documents containing term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
*/ */
public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -400,8 +402,8 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* It performs the same operation as termDocs, but return result as * It performs the same operation as termDocs, but return result as
* Zend_Search_Lucene_Index_DocsFilter object * Zend_Search_Lucene_Index_DocsFilter object
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return Zend_Search_Lucene_Index_DocsFilter * @return Zend_Search_Lucene_Index_DocsFilter
*/ */
public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -413,8 +415,8 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* Returns an array of all term freqs. * Returns an array of all term freqs.
* Return array structure: array( docId => freq, ...) * Return array structure: array( docId => freq, ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return integer * @return integer
*/ */
public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -426,8 +428,8 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* Returns an array of all term positions in the documents. * Returns an array of all term positions in the documents.
* Return array structure: array( docId => array( pos1, pos2, ...), ...) * Return array structure: array( docId => array( pos1, pos2, ...), ...)
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @return array * @return array
*/ */
public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null) public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
@ -438,7 +440,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
/** /**
* Returns the number of documents in this index containing the $term. * Returns the number of documents in this index containing the $term.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @return integer * @return integer
*/ */
public function docFreq(Zend_Search_Lucene_Index_Term $term) public function docFreq(Zend_Search_Lucene_Index_Term $term)
@ -459,8 +461,8 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
/** /**
* Returns a normalization factor for "field, document" pair. * Returns a normalization factor for "field, document" pair.
* *
* @param integer $id * @param integer $id
* @param string $fieldName * @param string $fieldName
* @return float * @return float
*/ */
public function norm($id, $fieldName) public function norm($id, $fieldName)
@ -482,7 +484,7 @@ class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
* Deletes a document from the index. * Deletes a document from the index.
* $id is an internal document id * $id is an internal document id
* *
* @param integer|Zend_Search_Lucene_Search_QueryHit $id * @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function delete($id) public function delete($id)

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_FSM */ /**
* Zend_Search_Lucene_FSM
*/
require_once 'Zend/Search/Lucene/FSM.php'; require_once 'Zend/Search/Lucene/FSM.php';
/** /**
@ -33,14 +35,18 @@ require_once 'Zend/Search/Lucene/FSM.php';
*/ */
class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_Lucene_FSM class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_Lucene_FSM
{ {
/** State Machine states */ /**
* State Machine states
*/
const ST_START = 0; const ST_START = 0;
const ST_LITERAL = 1; const ST_LITERAL = 1;
const ST_NOT_OPERATOR = 2; const ST_NOT_OPERATOR = 2;
const ST_AND_OPERATOR = 3; const ST_AND_OPERATOR = 3;
const ST_OR_OPERATOR = 4; const ST_OR_OPERATOR = 4;
/** Input symbols */ /**
* Input symbols
*/
const IN_LITERAL = 0; const IN_LITERAL = 0;
const IN_NOT_OPERATOR = 1; const IN_NOT_OPERATOR = 1;
const IN_AND_OPERATOR = 2; const IN_AND_OPERATOR = 2;
@ -100,20 +106,23 @@ class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_
*/ */
public function __construct() public function __construct()
{ {
parent::__construct( array(self::ST_START, parent::__construct(
array(self::ST_START,
self::ST_LITERAL, self::ST_LITERAL,
self::ST_NOT_OPERATOR, self::ST_NOT_OPERATOR,
self::ST_AND_OPERATOR, self::ST_AND_OPERATOR,
self::ST_OR_OPERATOR), self::ST_OR_OPERATOR),
array(self::IN_LITERAL, array(self::IN_LITERAL,
self::IN_NOT_OPERATOR, self::IN_NOT_OPERATOR,
self::IN_AND_OPERATOR, self::IN_AND_OPERATOR,
self::IN_OR_OPERATOR)); self::IN_OR_OPERATOR)
);
$emptyOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'emptyOperatorAction'); $emptyOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'emptyOperatorAction');
$emptyNotOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'emptyNotOperatorAction'); $emptyNotOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'emptyNotOperatorAction');
$this->addRules(array( array(self::ST_START, self::IN_LITERAL, self::ST_LITERAL), $this->addRules(
array( array(self::ST_START, self::IN_LITERAL, self::ST_LITERAL),
array(self::ST_START, self::IN_NOT_OPERATOR, self::ST_NOT_OPERATOR), array(self::ST_START, self::IN_NOT_OPERATOR, self::ST_NOT_OPERATOR),
array(self::ST_LITERAL, self::IN_AND_OPERATOR, self::ST_AND_OPERATOR), array(self::ST_LITERAL, self::IN_AND_OPERATOR, self::ST_AND_OPERATOR),
@ -128,7 +137,8 @@ class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_
array(self::ST_OR_OPERATOR, self::IN_LITERAL, self::ST_LITERAL), array(self::ST_OR_OPERATOR, self::IN_LITERAL, self::ST_LITERAL),
array(self::ST_OR_OPERATOR, self::IN_NOT_OPERATOR, self::ST_NOT_OPERATOR), array(self::ST_OR_OPERATOR, self::IN_NOT_OPERATOR, self::ST_NOT_OPERATOR),
)); )
);
$notOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'notOperatorAction'); $notOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'notOperatorAction');
$orOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'orOperatorAction'); $orOperatorAction = new Zend_Search_Lucene_FSMAction($this, 'orOperatorAction');
@ -194,7 +204,7 @@ class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_
public function finishExpression() public function finishExpression()
{ {
if ($this->getState() != self::ST_LITERAL) { if ($this->getState() != self::ST_LITERAL) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Literal expected.'); throw new Zend_Search_Lucene_Exception('Literal expected.');
} }
@ -214,8 +224,10 @@ class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_
*/ */
public function emptyOperatorAction() public function emptyOperatorAction()
{ {
/** Zend_Search_Lucene_Search_QueryParser */ /**
require_once 'Zend/Search/Lucene/Search/QueryParser.php'; * Zend_Search_Lucene_Search_QueryParser
*/
include_once 'Zend/Search/Lucene/Search/QueryParser.php';
if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) { if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) {
// Do nothing // Do nothing
@ -232,8 +244,10 @@ class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_
*/ */
public function emptyNotOperatorAction() public function emptyNotOperatorAction()
{ {
/** Zend_Search_Lucene_Search_QueryParser */ /**
require_once 'Zend/Search/Lucene/Search/QueryParser.php'; * Zend_Search_Lucene_Search_QueryParser
*/
include_once 'Zend/Search/Lucene/Search/QueryParser.php';
if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) { if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) {
// Do nothing // Do nothing

View File

@ -20,7 +20,9 @@
* @version $Id: Default.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Default.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** @see Zend_Search_Lucene_Search_Highlighter_Interface */ /**
* @see Zend_Search_Lucene_Search_Highlighter_Interface
*/
require_once 'Zend/Search/Lucene/Search/Highlighter/Interface.php'; require_once 'Zend/Search/Lucene/Search/Highlighter/Interface.php';
/** /**
* @category Zend * @category Zend
@ -81,7 +83,7 @@ class Zend_Search_Lucene_Search_Highlighter_Default implements Zend_Search_Lucen
/** /**
* Highlight specified words * Highlight specified words
* *
* @param string|array $words Words to highlight. They could be organized using the array or string. * @param string|array $words Words to highlight. They could be organized using the array or string.
*/ */
public function highlight($words) public function highlight($words)
{ {

View File

@ -47,7 +47,7 @@ interface Zend_Search_Lucene_Search_Highlighter_Interface
/** /**
* Highlight specified words (method is invoked once per subquery) * Highlight specified words (method is invoked once per subquery)
* *
* @param string|array $words Words to highlight. They could be organized using the array or string. * @param string|array $words Words to highlight. They could be organized using the array or string.
*/ */
public function highlight($words); public function highlight($words);
} }

View File

@ -76,8 +76,8 @@ abstract class Zend_Search_Lucene_Search_Query
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
abstract public function score($docId, Zend_Search_Lucene_Interface $reader); abstract public function score($docId, Zend_Search_Lucene_Interface $reader);
@ -97,7 +97,7 @@ abstract class Zend_Search_Lucene_Search_Query
* *
* Query specific implementation * Query specific implementation
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
abstract public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null); abstract public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null);
@ -105,7 +105,7 @@ abstract class Zend_Search_Lucene_Search_Query
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
abstract public function createWeight(Zend_Search_Lucene_Interface $reader); abstract public function createWeight(Zend_Search_Lucene_Interface $reader);
@ -131,7 +131,7 @@ abstract class Zend_Search_Lucene_Search_Query
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
abstract public function rewrite(Zend_Search_Lucene_Interface $index); abstract public function rewrite(Zend_Search_Lucene_Interface $index);
@ -139,7 +139,7 @@ abstract class Zend_Search_Lucene_Search_Query
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
abstract public function optimize(Zend_Search_Lucene_Interface $index); abstract public function optimize(Zend_Search_Lucene_Interface $index);
@ -171,27 +171,29 @@ abstract class Zend_Search_Lucene_Search_Query
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for highlighting) * @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for highlighting)
*/ */
abstract protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter); abstract protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter);
/** /**
* Highlight matches in $inputHTML * Highlight matches in $inputHTML
* *
* @param string $inputHTML * @param string $inputHTML
* @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag. * @param string $defaultEncoding HTML encoding, is used if it's not specified using Content-type HTTP-EQUIV meta tag.
* @param Zend_Search_Lucene_Search_Highlighter_Interface|null $highlighter * @param Zend_Search_Lucene_Search_Highlighter_Interface|null $highlighter
* @return string * @return string
*/ */
public function highlightMatches($inputHTML, $defaultEncoding = '', $highlighter = null) public function highlightMatches($inputHTML, $defaultEncoding = '', $highlighter = null)
{ {
if ($highlighter === null) { if ($highlighter === null) {
require_once 'Zend/Search/Lucene/Search/Highlighter/Default.php'; include_once 'Zend/Search/Lucene/Search/Highlighter/Default.php';
$highlighter = new Zend_Search_Lucene_Search_Highlighter_Default(); $highlighter = new Zend_Search_Lucene_Search_Highlighter_Default();
} }
/** Zend_Search_Lucene_Document_Html */ /**
require_once 'Zend/Search/Lucene/Document/Html.php'; * Zend_Search_Lucene_Document_Html
*/
include_once 'Zend/Search/Lucene/Document/Html.php';
$doc = Zend_Search_Lucene_Document_Html::loadHTML($inputHTML, false, $defaultEncoding); $doc = Zend_Search_Lucene_Document_Html::loadHTML($inputHTML, false, $defaultEncoding);
$highlighter->setDocument($doc); $highlighter->setDocument($doc);
@ -204,23 +206,25 @@ abstract class Zend_Search_Lucene_Search_Query
/** /**
* Highlight matches in $inputHtmlFragment and return it (without HTML header and body tag) * Highlight matches in $inputHtmlFragment and return it (without HTML header and body tag)
* *
* @param string $inputHtmlFragment * @param string $inputHtmlFragment
* @param string $encoding Input HTML string encoding * @param string $encoding Input HTML string encoding
* @param Zend_Search_Lucene_Search_Highlighter_Interface|null $highlighter * @param Zend_Search_Lucene_Search_Highlighter_Interface|null $highlighter
* @return string * @return string
*/ */
public function htmlFragmentHighlightMatches($inputHtmlFragment, $encoding = 'UTF-8', $highlighter = null) public function htmlFragmentHighlightMatches($inputHtmlFragment, $encoding = 'UTF-8', $highlighter = null)
{ {
if ($highlighter === null) { if ($highlighter === null) {
require_once 'Zend/Search/Lucene/Search/Highlighter/Default.php'; include_once 'Zend/Search/Lucene/Search/Highlighter/Default.php';
$highlighter = new Zend_Search_Lucene_Search_Highlighter_Default(); $highlighter = new Zend_Search_Lucene_Search_Highlighter_Default();
} }
$inputHTML = '<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>' $inputHTML = '<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>'
. iconv($encoding, 'UTF-8//IGNORE', $inputHtmlFragment) . '</body></html>'; . iconv($encoding, 'UTF-8//IGNORE', $inputHtmlFragment) . '</body></html>';
/** Zend_Search_Lucene_Document_Html */ /**
require_once 'Zend/Search/Lucene/Document/Html.php'; * Zend_Search_Lucene_Document_Html
*/
include_once 'Zend/Search/Lucene/Document/Html.php';
$doc = Zend_Search_Lucene_Document_Html::loadHTML($inputHTML); $doc = Zend_Search_Lucene_Document_Html::loadHTML($inputHTML);
$highlighter->setDocument($doc); $highlighter->setDocument($doc);

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -79,8 +81,8 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
* if $signs array is omitted then all subqueries are required * if $signs array is omitted then all subqueries are required
* it differs from addSubquery() behavior, but should never be used * it differs from addSubquery() behavior, but should never be used
* *
* @param array $subqueries Array of Zend_Search_Search_Query objects * @param array $subqueries Array of Zend_Search_Search_Query objects
* @param array $signs Array of signs. Sign is boolean|null. * @param array $signs Array of signs. Sign is boolean|null.
* @return void * @return void
*/ */
public function __construct($subqueries = null, $signs = null) public function __construct($subqueries = null, $signs = null)
@ -111,10 +113,11 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
* NULL - subquery is neither prohibited, nor required * NULL - subquery is neither prohibited, nor required
* *
* @param Zend_Search_Lucene_Search_Query $subquery * @param Zend_Search_Lucene_Search_Query $subquery
* @param boolean|null $sign * @param boolean|null $sign
* @return void * @return void
*/ */
public function addSubquery(Zend_Search_Lucene_Search_Query $subquery, $sign=null) { public function addSubquery(Zend_Search_Lucene_Search_Query $subquery, $sign=null)
{
if ($sign !== true || $this->_signs !== null) { // Skip, if all subqueries are required if ($sign !== true || $this->_signs !== null) { // Skip, if all subqueries are required
if ($this->_signs === null) { // Check, If all previous subqueries are required if ($this->_signs === null) { // Check, If all previous subqueries are required
$this->_signs = array(); $this->_signs = array();
@ -131,7 +134,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Re-write queries into primitive queries * Re-write queries into primitive queries
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
@ -140,8 +143,10 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
foreach ($this->_subqueries as $subqueryId => $subquery) { foreach ($this->_subqueries as $subqueryId => $subquery) {
$query->addSubquery($subquery->rewrite($index), $query->addSubquery(
($this->_signs === null)? true : $this->_signs[$subqueryId]); $subquery->rewrite($index),
($this->_signs === null)? true : $this->_signs[$subqueryId]
);
} }
return $query; return $query;
@ -150,7 +155,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
@ -174,7 +179,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
} }
if (count($subqueries) == 0) { if (count($subqueries) == 0) {
// Boolean query doesn't has non-insignificant subqueries // Boolean query doesn't has non-insignificant subqueries
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
// Check if all non-insignificant subqueries are prohibited // Check if all non-insignificant subqueries are prohibited
@ -186,7 +191,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
} }
} }
if ($allProhibited) { if ($allProhibited) {
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
@ -196,7 +201,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
if ($subquery instanceof Zend_Search_Lucene_Search_Query_Empty) { if ($subquery instanceof Zend_Search_Lucene_Search_Query_Empty) {
if ($signs[$id] === true) { if ($signs[$id] === true) {
// Matching is required, but is actually empty // Matching is required, but is actually empty
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} else { } else {
// Matching is optional or prohibited, but is empty // Matching is optional or prohibited, but is empty
@ -209,7 +214,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
// Check, if reduced subqueries list is empty // Check, if reduced subqueries list is empty
if (count($subqueries) == 0) { if (count($subqueries) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -222,7 +227,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
} }
} }
if ($allProhibited) { if ($allProhibited) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -262,7 +267,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
// remove subquery from a subqueries list // remove subquery from a subqueries list
unset($subqueries[$id]); unset($subqueries[$id]);
unset($signs[$id]); unset($signs[$id]);
} else if ($subquery instanceof Zend_Search_Lucene_Search_Query_MultiTerm) { } else if ($subquery instanceof Zend_Search_Lucene_Search_Query_MultiTerm) {
$subTerms = $subquery->getTerms(); $subTerms = $subquery->getTerms();
$subSigns = $subquery->getSigns(); $subSigns = $subquery->getSigns();
@ -330,14 +335,14 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
// Continue if non-optional terms are presented in this multi-term subquery // Continue if non-optional terms are presented in this multi-term subquery
if (!$onlyOptional) { if (!$onlyOptional) {
continue; continue;
} }
foreach ($subTerms as $termId => $term) { foreach ($subTerms as $termId => $term) {
$terms[] = $term; $terms[] = $term;
$tsigns[] = ($signs[$id] === null)? null /* optional */ : $tsigns[] = ($signs[$id] === null)? null /* optional */ :
false /* prohibited */; false /* prohibited */;
$boostFactors[] = $subquery->getBoost(); $boostFactors[] = $subquery->getBoost();
} }
// remove subquery from a subqueries list // remove subquery from a subqueries list
@ -357,7 +362,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
// Check, if all subqueries have been decomposed and all terms has the same boost factor // Check, if all subqueries have been decomposed and all terms has the same boost factor
if (count($subqueries) == 0 && count(array_unique($boostFactors)) == 1) { if (count($subqueries) == 0 && count(array_unique($boostFactors)) == 1) {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$optimizedQuery = new Zend_Search_Lucene_Search_Query_MultiTerm($terms, $tsigns); $optimizedQuery = new Zend_Search_Lucene_Search_Query_MultiTerm($terms, $tsigns);
$optimizedQuery->setBoost(reset($boostFactors)*$this->getBoost()); $optimizedQuery->setBoost(reset($boostFactors)*$this->getBoost());
@ -381,7 +386,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
} }
if (count($terms) == 1) { if (count($terms) == 1) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$clause = new Zend_Search_Lucene_Search_Query_Term(reset($terms)); $clause = new Zend_Search_Lucene_Search_Query_Term(reset($terms));
$clause->setBoost(reset($boostFactors)); $clause->setBoost(reset($boostFactors));
@ -391,7 +396,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
// Clear terms list // Clear terms list
$terms = array(); $terms = array();
} else if (count($terms) > 1 && count(array_unique($boostFactors)) == 1) { } else if (count($terms) > 1 && count(array_unique($boostFactors)) == 1) {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$clause = new Zend_Search_Lucene_Search_Query_MultiTerm($terms, $tsigns); $clause = new Zend_Search_Lucene_Search_Query_MultiTerm($terms, $tsigns);
$clause->setBoost(reset($boostFactors)); $clause->setBoost(reset($boostFactors));
@ -405,7 +410,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
if (count($prohibitedTerms) == 1) { if (count($prohibitedTerms) == 1) {
// (boost factors are not significant for prohibited clauses) // (boost factors are not significant for prohibited clauses)
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$subqueries[] = new Zend_Search_Lucene_Search_Query_Term(reset($prohibitedTerms)); $subqueries[] = new Zend_Search_Lucene_Search_Query_Term(reset($prohibitedTerms));
$signs[] = false; $signs[] = false;
@ -420,7 +425,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
} }
// (boost factors are not significant for prohibited clauses) // (boost factors are not significant for prohibited clauses)
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$subqueries[] = new Zend_Search_Lucene_Search_Query_MultiTerm($prohibitedTerms, $prohibitedSigns); $subqueries[] = new Zend_Search_Lucene_Search_Query_MultiTerm($prohibitedTerms, $prohibitedSigns);
// Clause sign is 'prohibited' // Clause sign is 'prohibited'
$signs[] = false; $signs[] = false;
@ -429,7 +434,9 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
$prohibitedTerms = array(); $prohibitedTerms = array();
} }
/** @todo Group terms with the same boost factors together */ /**
* @todo Group terms with the same boost factors together
*/
// Check, that all terms are processed // Check, that all terms are processed
// Replace candidate for optimized query // Replace candidate for optimized query
@ -466,12 +473,12 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Search/Weight/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Weight/Boolean.php';
$this->_weight = new Zend_Search_Lucene_Search_Weight_Boolean($this, $reader); $this->_weight = new Zend_Search_Lucene_Search_Weight_Boolean($this, $reader);
return $this->_weight; return $this->_weight;
} }
@ -498,9 +505,11 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
$resVectorsIds[] = $subqueryId; $resVectorsIds[] = $subqueryId;
} }
// sort resvectors in order of subquery cardinality increasing // sort resvectors in order of subquery cardinality increasing
array_multisort($resVectorsSizes, SORT_ASC, SORT_NUMERIC, array_multisort(
$resVectorsIds, SORT_ASC, SORT_NUMERIC, $resVectorsSizes, SORT_ASC, SORT_NUMERIC,
$resVectors); $resVectorsIds, SORT_ASC, SORT_NUMERIC,
$resVectors
);
foreach ($resVectors as $nextResVector) { foreach ($resVectors as $nextResVector) {
if($this->_resVector === null) { if($this->_resVector === null) {
@ -562,9 +571,11 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
} }
// sort resvectors in order of subquery cardinality increasing // sort resvectors in order of subquery cardinality increasing
array_multisort($requiredVectorsSizes, SORT_ASC, SORT_NUMERIC, array_multisort(
$requiredVectorsIds, SORT_ASC, SORT_NUMERIC, $requiredVectorsSizes, SORT_ASC, SORT_NUMERIC,
$requiredVectors); $requiredVectorsIds, SORT_ASC, SORT_NUMERIC,
$requiredVectors
);
$required = null; $required = null;
foreach ($requiredVectors as $nextResVector) { foreach ($requiredVectors as $nextResVector) {
@ -605,15 +616,17 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Score calculator for conjunction queries (all subqueries are required) * Score calculator for conjunction queries (all subqueries are required)
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function _conjunctionScore($docId, Zend_Search_Lucene_Interface $reader) public function _conjunctionScore($docId, Zend_Search_Lucene_Interface $reader)
{ {
if ($this->_coord === null) { if ($this->_coord === null) {
$this->_coord = $reader->getSimilarity()->coord(count($this->_subqueries), $this->_coord = $reader->getSimilarity()->coord(
count($this->_subqueries) ); count($this->_subqueries),
count($this->_subqueries)
);
} }
$score = 0; $score = 0;
@ -635,8 +648,8 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Score calculator for non conjunction queries (not all subqueries are required) * Score calculator for non conjunction queries (not all subqueries are required)
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function _nonConjunctionScore($docId, Zend_Search_Lucene_Interface $reader) public function _nonConjunctionScore($docId, Zend_Search_Lucene_Interface $reader)
@ -684,7 +697,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
@ -694,7 +707,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
if ($docsFilter === null) { if ($docsFilter === null) {
// Create local documents filter if it's not provided by upper query // Create local documents filter if it's not provided by upper query
require_once 'Zend/Search/Lucene/Index/DocsFilter.php'; include_once 'Zend/Search/Lucene/Index/DocsFilter.php';
$docsFilter = new Zend_Search_Lucene_Index_DocsFilter(); $docsFilter = new Zend_Search_Lucene_Index_DocsFilter();
} }
@ -731,8 +744,8 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
@ -769,7 +782,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -37,7 +39,7 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
@ -48,7 +50,7 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
@ -60,12 +62,12 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Search/Weight/Empty.php'; include_once 'Zend/Search/Lucene/Search/Weight/Empty.php';
return new Zend_Search_Lucene_Search_Weight_Empty(); return new Zend_Search_Lucene_Search_Weight_Empty();
} }
@ -73,7 +75,7 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
@ -96,8 +98,8 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
@ -118,7 +120,7 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -34,7 +36,9 @@ require_once 'Zend/Search/Lucene/Search/Query.php';
*/ */
class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Query class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Query
{ {
/** Default minimum similarity */ /**
* Default minimum similarity
*/
const DEFAULT_MIN_SIMILARITY = 0.5; const DEFAULT_MIN_SIMILARITY = 0.5;
/** /**
@ -114,23 +118,23 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
/** /**
* Zend_Search_Lucene_Search_Query_Wildcard constructor. * Zend_Search_Lucene_Search_Query_Wildcard constructor.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param float $minimumSimilarity * @param float $minimumSimilarity
* @param integer $prefixLength * @param integer $prefixLength
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct(Zend_Search_Lucene_Index_Term $term, $minimumSimilarity = self::DEFAULT_MIN_SIMILARITY, $prefixLength = null) public function __construct(Zend_Search_Lucene_Index_Term $term, $minimumSimilarity = self::DEFAULT_MIN_SIMILARITY, $prefixLength = null)
{ {
if ($minimumSimilarity < 0) { if ($minimumSimilarity < 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('minimumSimilarity cannot be less than 0'); throw new Zend_Search_Lucene_Exception('minimumSimilarity cannot be less than 0');
} }
if ($minimumSimilarity >= 1) { if ($minimumSimilarity >= 1) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('minimumSimilarity cannot be greater than or equal to 1'); throw new Zend_Search_Lucene_Exception('minimumSimilarity cannot be greater than or equal to 1');
} }
if ($prefixLength < 0) { if ($prefixLength < 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('prefixLength cannot be less than 0'); throw new Zend_Search_Lucene_Exception('prefixLength cannot be less than 0');
} }
@ -162,9 +166,9 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
/** /**
* Calculate maximum distance for specified word length * Calculate maximum distance for specified word length
* *
* @param integer $prefixLength * @param integer $prefixLength
* @param integer $termLength * @param integer $termLength
* @param integer $length * @param integer $length
* @return integer * @return integer
*/ */
private function _calculateMaxDistance($prefixLength, $termLength, $length) private function _calculateMaxDistance($prefixLength, $termLength, $length)
@ -176,7 +180,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -193,7 +197,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$fields = array($this->_term->field); $fields = array($this->_term->field);
} }
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$prefix = Zend_Search_Lucene_Index_Term::getPrefix($this->_term->text, $this->_prefixLength); $prefix = Zend_Search_Lucene_Index_Term::getPrefix($this->_term->text, $this->_prefixLength);
$prefixByteLength = strlen($prefix); $prefixByteLength = strlen($prefix);
$prefixUtf8Length = Zend_Search_Lucene_Index_Term::getLength($prefix); $prefixUtf8Length = Zend_Search_Lucene_Index_Term::getLength($prefix);
@ -206,12 +210,12 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$scaleFactor = 1/(1 - $this->_minimumSimilarity); $scaleFactor = 1/(1 - $this->_minimumSimilarity);
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
$maxTerms = Zend_Search_Lucene::getTermsPerQueryLimit(); $maxTerms = Zend_Search_Lucene::getTermsPerQueryLimit();
foreach ($fields as $field) { foreach ($fields as $field) {
$index->resetTermsStream(); $index->resetTermsStream();
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
if ($prefix != '') { if ($prefix != '') {
$index->skipTo(new Zend_Search_Lucene_Index_Term($prefix, $field)); $index->skipTo(new Zend_Search_Lucene_Index_Term($prefix, $field));
@ -231,7 +235,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$similarity = (($prefixUtf8Length == 0)? 0 : 1 - strlen($target)/$prefixUtf8Length); $similarity = (($prefixUtf8Length == 0)? 0 : 1 - strlen($target)/$prefixUtf8Length);
} else if (strlen($target) == 0) { } else if (strlen($target) == 0) {
$similarity = (($prefixUtf8Length == 0)? 0 : 1 - $termRestLength/$prefixUtf8Length); $similarity = (($prefixUtf8Length == 0)? 0 : 1 - $termRestLength/$prefixUtf8Length);
} else if ($maxDistance < abs($termRestLength - strlen($target))){ } else if ($maxDistance < abs($termRestLength - strlen($target))) {
//just adding the characters of term to target or vice-versa results in too many edits //just adding the characters of term to target or vice-versa results in too many edits
//for example "pre" length is 3 and "prefixes" length is 8. We can see that //for example "pre" length is 3 and "prefixes" length is 8. We can see that
//given this optimal circumstance, the edit distance cannot be less than 5. //given this optimal circumstance, the edit distance cannot be less than 5.
@ -249,7 +253,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$this->_scores[] = ($similarity - $this->_minimumSimilarity)*$scaleFactor; $this->_scores[] = ($similarity - $this->_minimumSimilarity)*$scaleFactor;
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) { if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
} }
@ -267,7 +271,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$this->_maxDistances[strlen($target)] : $this->_maxDistances[strlen($target)] :
$this->_calculateMaxDistance(0, $termRestLength, strlen($target)); $this->_calculateMaxDistance(0, $termRestLength, strlen($target));
if ($maxDistance < abs($termRestLength - strlen($target))){ if ($maxDistance < abs($termRestLength - strlen($target))) {
//just adding the characters of term to target or vice-versa results in too many edits //just adding the characters of term to target or vice-versa results in too many edits
//for example "pre" length is 3 and "prefixes" length is 8. We can see that //for example "pre" length is 3 and "prefixes" length is 8. We can see that
//given this optimal circumstance, the edit distance cannot be less than 5. //given this optimal circumstance, the edit distance cannot be less than 5.
@ -285,7 +289,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$this->_scores[] = ($similarity - $this->_minimumSimilarity)*$scaleFactor; $this->_scores[] = ($similarity - $this->_minimumSimilarity)*$scaleFactor;
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) { if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
} }
@ -298,21 +302,23 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
} }
if (count($this->_matches) == 0) { if (count($this->_matches) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} else if (count($this->_matches) == 1) { } else if (count($this->_matches) == 1) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches)); return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$rewrittenQuery = new Zend_Search_Lucene_Search_Query_Boolean(); $rewrittenQuery = new Zend_Search_Lucene_Search_Query_Boolean();
array_multisort($this->_scores, SORT_DESC, SORT_NUMERIC, array_multisort(
$this->_termKeys, SORT_ASC, SORT_STRING, $this->_scores, SORT_DESC, SORT_NUMERIC,
$this->_matches); $this->_termKeys, SORT_ASC, SORT_STRING,
$this->_matches
);
$termCount = 0; $termCount = 0;
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
foreach ($this->_matches as $id => $matchedTerm) { foreach ($this->_matches as $id => $matchedTerm) {
$subquery = new Zend_Search_Lucene_Search_Query_Term($matchedTerm); $subquery = new Zend_Search_Lucene_Search_Query_Term($matchedTerm);
$subquery->setBoost($this->_scores[$id]); $subquery->setBoost($this->_scores[$id]);
@ -332,12 +338,12 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -350,7 +356,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
public function getQueryTerms() public function getQueryTerms()
{ {
if ($this->_matches === null) { if ($this->_matches === null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Search or rewrite operations have to be performed before.'); throw new Zend_Search_Lucene_Exception('Search or rewrite operations have to be performed before.');
} }
@ -360,13 +366,13 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -375,13 +381,13 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -395,34 +401,34 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
*/ */
public function matchedDocs() public function matchedDocs()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)');
} }
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Fuzzy query should not be directly used for search. Use $query->rewrite($index)');
} }
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {
$words = array(); $words = array();
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$prefix = Zend_Search_Lucene_Index_Term::getPrefix($this->_term->text, $this->_prefixLength); $prefix = Zend_Search_Lucene_Index_Term::getPrefix($this->_term->text, $this->_prefixLength);
$prefixByteLength = strlen($prefix); $prefixByteLength = strlen($prefix);
$prefixUtf8Length = Zend_Search_Lucene_Index_Term::getLength($prefix); $prefixUtf8Length = Zend_Search_Lucene_Index_Term::getLength($prefix);
@ -436,7 +442,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$scaleFactor = 1/(1 - $this->_minimumSimilarity); $scaleFactor = 1/(1 - $this->_minimumSimilarity);
$docBody = $highlighter->getDocument()->getFieldUtf8Value('body'); $docBody = $highlighter->getDocument()->getFieldUtf8Value('body');
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8'); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8');
foreach ($tokens as $token) { foreach ($tokens as $token) {
$termText = $token->getTermText(); $termText = $token->getTermText();
@ -455,7 +461,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
$similarity = (($prefixUtf8Length == 0)? 0 : 1 - strlen($target)/$prefixUtf8Length); $similarity = (($prefixUtf8Length == 0)? 0 : 1 - strlen($target)/$prefixUtf8Length);
} else if (strlen($target) == 0) { } else if (strlen($target) == 0) {
$similarity = (($prefixUtf8Length == 0)? 0 : 1 - $termRestLength/$prefixUtf8Length); $similarity = (($prefixUtf8Length == 0)? 0 : 1 - $termRestLength/$prefixUtf8Length);
} else if ($maxDistance < abs($termRestLength - strlen($target))){ } else if ($maxDistance < abs($termRestLength - strlen($target))) {
//just adding the characters of term to target or vice-versa results in too many edits //just adding the characters of term to target or vice-versa results in too many edits
//for example "pre" length is 3 and "prefixes" length is 8. We can see that //for example "pre" length is 3 and "prefixes" length is 8. We can see that
//given this optimal circumstance, the edit distance cannot be less than 5. //given this optimal circumstance, the edit distance cannot be less than 5.

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -39,7 +41,7 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
@ -50,7 +52,7 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
@ -61,12 +63,12 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Search/Weight/Empty.php'; include_once 'Zend/Search/Lucene/Search/Weight/Empty.php';
return new Zend_Search_Lucene_Search_Weight_Empty(); return new Zend_Search_Lucene_Search_Weight_Empty();
} }
@ -74,7 +76,7 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
@ -97,8 +99,8 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
@ -119,7 +121,7 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -99,14 +101,14 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
* if $signs array is omitted then all terms are required * if $signs array is omitted then all terms are required
* it differs from addTerm() behavior, but should never be used * it differs from addTerm() behavior, but should never be used
* *
* @param array $terms Array of Zend_Search_Lucene_Index_Term objects * @param array $terms Array of Zend_Search_Lucene_Index_Term objects
* @param array $signs Array of signs. Sign is boolean|null. * @param array $signs Array of signs. Sign is boolean|null.
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct($terms = null, $signs = null) public function __construct($terms = null, $signs = null)
{ {
if (is_array($terms)) { if (is_array($terms)) {
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
if (count($terms) > Zend_Search_Lucene::getTermsPerQueryLimit()) { if (count($terms) > Zend_Search_Lucene::getTermsPerQueryLimit()) {
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
@ -136,10 +138,11 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
* NULL - term is neither prohibited, nor required * NULL - term is neither prohibited, nor required
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param boolean|null $sign * @param boolean|null $sign
* @return void * @return void
*/ */
public function addTerm(Zend_Search_Lucene_Index_Term $term, $sign = null) { public function addTerm(Zend_Search_Lucene_Index_Term $term, $sign = null)
{
if ($sign !== true || $this->_signs !== null) { // Skip, if all terms are required if ($sign !== true || $this->_signs !== null) { // Skip, if all terms are required
if ($this->_signs === null) { // Check, If all previous terms are required if ($this->_signs === null) { // Check, If all previous terms are required
$this->_signs = array(); $this->_signs = array();
@ -157,13 +160,13 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
{ {
if (count($this->_terms) == 0) { if (count($this->_terms) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -179,17 +182,21 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
if ($allQualified) { if ($allQualified) {
return $this; return $this;
} else { } else {
/** transform multiterm query to boolean and apply rewrite() method to subqueries. */ /**
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; * transform multiterm query to boolean and apply rewrite() method to subqueries.
*/
include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$query = new Zend_Search_Lucene_Search_Query_Boolean(); $query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
foreach ($this->_terms as $termId => $term) { foreach ($this->_terms as $termId => $term) {
$subquery = new Zend_Search_Lucene_Search_Query_Term($term); $subquery = new Zend_Search_Lucene_Search_Query_Term($term);
$query->addSubquery($subquery->rewrite($index), $query->addSubquery(
($this->_signs === null)? true : $this->_signs[$termId]); $subquery->rewrite($index),
($this->_signs === null)? true : $this->_signs[$termId]
);
} }
return $query; return $query;
@ -199,7 +206,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
@ -211,7 +218,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
if (!$index->hasTerm($term)) { if (!$index->hasTerm($term)) {
if ($signs === null || $signs[$id] === true) { if ($signs === null || $signs[$id] === true) {
// Term is required // Term is required
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} else { } else {
// Term is optional or prohibited // Term is optional or prohibited
@ -235,7 +242,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
} }
} }
if ($allProhibited) { if ($allProhibited) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -248,7 +255,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
// It's already checked, that it's not a prohibited term // It's already checked, that it's not a prohibited term
// It's one term query with one required or optional element // It's one term query with one required or optional element
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$optimizedQuery = new Zend_Search_Lucene_Search_Query_Term(reset($terms)); $optimizedQuery = new Zend_Search_Lucene_Search_Query_Term(reset($terms));
$optimizedQuery->setBoost($this->getBoost()); $optimizedQuery->setBoost($this->getBoost());
@ -256,7 +263,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
} }
if (count($terms) == 0) { if (count($terms) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -291,7 +298,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Set weight for specified term * Set weight for specified term
* *
* @param integer $num * @param integer $num
* @param Zend_Search_Lucene_Search_Weight_Term $weight * @param Zend_Search_Lucene_Search_Weight_Term $weight
*/ */
public function setWeight($num, $weight) public function setWeight($num, $weight)
@ -303,12 +310,12 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Search/Weight/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Weight/MultiTerm.php';
$this->_weight = new Zend_Search_Lucene_Search_Weight_MultiTerm($this, $reader); $this->_weight = new Zend_Search_Lucene_Search_Weight_MultiTerm($this, $reader);
return $this->_weight; return $this->_weight;
} }
@ -335,11 +342,13 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
$docFreqs[] = $reader->docFreq($term); $docFreqs[] = $reader->docFreq($term);
$ids[] = $id; // Used to keep original order for terms with the same selectivity and omit terms comparison $ids[] = $id; // Used to keep original order for terms with the same selectivity and omit terms comparison
} }
array_multisort($docFreqs, SORT_ASC, SORT_NUMERIC, array_multisort(
$ids, SORT_ASC, SORT_NUMERIC, $docFreqs, SORT_ASC, SORT_NUMERIC,
$this->_terms); $ids, SORT_ASC, SORT_NUMERIC,
$this->_terms
);
require_once 'Zend/Search/Lucene/Index/DocsFilter.php'; include_once 'Zend/Search/Lucene/Index/DocsFilter.php';
$docsFilter = new Zend_Search_Lucene_Index_DocsFilter(); $docsFilter = new Zend_Search_Lucene_Index_DocsFilter();
foreach ($this->_terms as $termId => $term) { foreach ($this->_terms as $termId => $term) {
$termDocs = $reader->termDocs($term, $docsFilter); $termDocs = $reader->termDocs($term, $docsFilter);
@ -394,9 +403,11 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
} }
// sort resvectors in order of subquery cardinality increasing // sort resvectors in order of subquery cardinality increasing
array_multisort($requiredVectorsSizes, SORT_ASC, SORT_NUMERIC, array_multisort(
$requiredVectorsIds, SORT_ASC, SORT_NUMERIC, $requiredVectorsSizes, SORT_ASC, SORT_NUMERIC,
$requiredVectors); $requiredVectorsIds, SORT_ASC, SORT_NUMERIC,
$requiredVectors
);
$required = null; $required = null;
foreach ($requiredVectors as $nextResVector) { foreach ($requiredVectors as $nextResVector) {
@ -459,15 +470,17 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Score calculator for conjunction queries (all terms are required) * Score calculator for conjunction queries (all terms are required)
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function _conjunctionScore($docId, Zend_Search_Lucene_Interface $reader) public function _conjunctionScore($docId, Zend_Search_Lucene_Interface $reader)
{ {
if ($this->_coord === null) { if ($this->_coord === null) {
$this->_coord = $reader->getSimilarity()->coord(count($this->_terms), $this->_coord = $reader->getSimilarity()->coord(
count($this->_terms) ); count($this->_terms),
count($this->_terms)
);
} }
$score = 0.0; $score = 0.0;
@ -489,8 +502,8 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Score calculator for non conjunction queries (not all terms are required) * Score calculator for non conjunction queries (not all terms are required)
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function _nonConjunctionScore($docId, $reader) public function _nonConjunctionScore($docId, $reader)
@ -514,9 +527,9 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
$matchedTerms = 0; $matchedTerms = 0;
foreach ($this->_terms as $termId=>$term) { foreach ($this->_terms as $termId=>$term) {
// Check if term is // Check if term is
if ($this->_signs[$termId] !== false && // not prohibited if ($this->_signs[$termId] !== false // not prohibited
isset($this->_termsFreqs[$termId][$docId]) // matched && isset($this->_termsFreqs[$termId][$docId]) // matched
) { ) {
$matchedTerms++; $matchedTerms++;
/** /**
@ -537,7 +550,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
@ -567,8 +580,8 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
@ -609,7 +622,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -91,9 +93,9 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Class constructor. Create a new prase query. * Class constructor. Create a new prase query.
* *
* @param string $field Field to search. * @param string $field Field to search.
* @param array $terms Terms to search Array of strings. * @param array $terms Terms to search Array of strings.
* @param array $offsets Relative term positions. Array of integers. * @param array $offsets Relative term positions. Array of integers.
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct($terms = null, $offsets = null, $field = null) public function __construct($terms = null, $offsets = null, $field = null)
@ -102,7 +104,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
if (is_array($terms)) { if (is_array($terms)) {
$this->_terms = array(); $this->_terms = array();
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
foreach ($terms as $termId => $termText) { foreach ($terms as $termId => $termText) {
$this->_terms[$termId] = ($field !== null)? new Zend_Search_Lucene_Index_Term($termText, $field): $this->_terms[$termId] = ($field !== null)? new Zend_Search_Lucene_Index_Term($termText, $field):
new Zend_Search_Lucene_Index_Term($termText); new Zend_Search_Lucene_Index_Term($termText);
@ -110,13 +112,13 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
} else if ($terms === null) { } else if ($terms === null) {
$this->_terms = array(); $this->_terms = array();
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('terms argument must be array of strings or null'); throw new Zend_Search_Lucene_Exception('terms argument must be array of strings or null');
} }
if (is_array($offsets)) { if (is_array($offsets)) {
if (count($this->_terms) != count($offsets)) { if (count($this->_terms) != count($offsets)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('terms and offsets arguments must have the same size.'); throw new Zend_Search_Lucene_Exception('terms and offsets arguments must have the same size.');
} }
$this->_offsets = $offsets; $this->_offsets = $offsets;
@ -127,7 +129,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
$this->_offsets[$termId] = $position; $this->_offsets[$termId] = $position;
} }
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('offsets argument must be array of strings or null'); throw new Zend_Search_Lucene_Exception('offsets argument must be array of strings or null');
} }
} }
@ -160,13 +162,16 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
* after the last term added. * after the last term added.
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param integer $position * @param integer $position
*/ */
public function addTerm(Zend_Search_Lucene_Index_Term $term, $position = null) { public function addTerm(Zend_Search_Lucene_Index_Term $term, $position = null)
{
if ((count($this->_terms) != 0)&&(end($this->_terms)->field != $term->field)) { if ((count($this->_terms) != 0)&&(end($this->_terms)->field != $term->field)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('All phrase terms must be in the same field: ' . throw new Zend_Search_Lucene_Exception(
$term->field . ':' . $term->text); 'All phrase terms must be in the same field: ' .
$term->field . ':' . $term->text
);
} }
$this->_terms[] = $term; $this->_terms[] = $term;
@ -183,18 +188,18 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
{ {
if (count($this->_terms) == 0) { if (count($this->_terms) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} else if ($this->_terms[0]->field !== null) { } else if ($this->_terms[0]->field !== null) {
return $this; return $this;
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$query = new Zend_Search_Lucene_Search_Query_Boolean(); $query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -202,7 +207,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
$subquery = new Zend_Search_Lucene_Search_Query_Phrase(); $subquery = new Zend_Search_Lucene_Search_Query_Phrase();
$subquery->setSlop($this->getSlop()); $subquery->setSlop($this->getSlop());
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
foreach ($this->_terms as $termId => $term) { foreach ($this->_terms as $termId => $term) {
$qualifiedTerm = new Zend_Search_Lucene_Index_Term($term->text, $fieldName); $qualifiedTerm = new Zend_Search_Lucene_Index_Term($term->text, $fieldName);
@ -219,7 +224,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
@ -227,14 +232,14 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
// Check, that index contains all phrase terms // Check, that index contains all phrase terms
foreach ($this->_terms as $term) { foreach ($this->_terms as $term) {
if (!$index->hasTerm($term)) { if (!$index->hasTerm($term)) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
} }
if (count($this->_terms) == 1) { if (count($this->_terms) == 1) {
// It's one term query // It's one term query
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$optimizedQuery = new Zend_Search_Lucene_Search_Query_Term(reset($this->_terms)); $optimizedQuery = new Zend_Search_Lucene_Search_Query_Term(reset($this->_terms));
$optimizedQuery->setBoost($this->getBoost()); $optimizedQuery->setBoost($this->getBoost());
@ -242,7 +247,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
} }
if (count($this->_terms) == 0) { if (count($this->_terms) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -264,7 +269,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Set weight for specified term * Set weight for specified term
* *
* @param integer $num * @param integer $num
* @param Zend_Search_Lucene_Search_Weight_Term $weight * @param Zend_Search_Lucene_Search_Weight_Term $weight
*/ */
public function setWeight($num, $weight) public function setWeight($num, $weight)
@ -276,12 +281,12 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Search/Weight/Phrase.php'; include_once 'Zend/Search/Lucene/Search/Weight/Phrase.php';
$this->_weight = new Zend_Search_Lucene_Search_Weight_Phrase($this, $reader); $this->_weight = new Zend_Search_Lucene_Search_Weight_Phrase($this, $reader);
return $this->_weight; return $this->_weight;
} }
@ -290,7 +295,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Score calculator for exact phrase queries (terms sequence is fixed) * Score calculator for exact phrase queries (terms sequence is fixed)
* *
* @param integer $docId * @param integer $docId
* @return float * @return float
*/ */
public function _exactPhraseFreq($docId) public function _exactPhraseFreq($docId)
@ -302,11 +307,11 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
// Calculate $lowCardTermId // Calculate $lowCardTermId
foreach ($this->_terms as $termId => $term) { foreach ($this->_terms as $termId => $term) {
if ($lowCardTermId === null || if ($lowCardTermId === null
count($this->_termsPositions[$termId][$docId]) < || count($this->_termsPositions[$termId][$docId]) <count($this->_termsPositions[$lowCardTermId][$docId])
count($this->_termsPositions[$lowCardTermId][$docId]) ) { ) {
$lowCardTermId = $termId; $lowCardTermId = $termId;
} }
} }
// Walk through positions of the term with lowest cardinality // Walk through positions of the term with lowest cardinality
@ -335,8 +340,8 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Score calculator for sloppy phrase queries (terms sequence is fixed) * Score calculator for sloppy phrase queries (terms sequence is fixed)
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function _sloppyPhraseFreq($docId, Zend_Search_Lucene_Interface $reader) public function _sloppyPhraseFreq($docId, Zend_Search_Lucene_Interface $reader)
@ -361,9 +366,11 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
} }
} else { } else {
for ($count = 0; $count < $queueSize; $count++) { for ($count = 0; $count < $queueSize; $count++) {
if ($lastTerm !== null && if ($lastTerm !== null
abs( $termPosition - $phraseQueue[$count][$lastTerm] - && abs(
($this->_offsets[$termId] - $this->_offsets[$lastTerm])) > $this->_slop) { $termPosition - $phraseQueue[$count][$lastTerm] -
($this->_offsets[$termId] - $this->_offsets[$lastTerm])
) > $this->_slop) {
continue; continue;
} }
@ -412,7 +419,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
@ -434,9 +441,11 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
$this->_termsPositions[$termId] = $reader->termPositions($term); $this->_termsPositions[$termId] = $reader->termPositions($term);
} }
// sort resvectors in order of subquery cardinality increasing // sort resvectors in order of subquery cardinality increasing
array_multisort($resVectorsSizes, SORT_ASC, SORT_NUMERIC, array_multisort(
$resVectorsIds, SORT_ASC, SORT_NUMERIC, $resVectorsSizes, SORT_ASC, SORT_NUMERIC,
$resVectors); $resVectorsIds, SORT_ASC, SORT_NUMERIC,
$resVectors
);
foreach ($resVectors as $nextResVector) { foreach ($resVectors as $nextResVector) {
if($this->_resVector === null) { if($this->_resVector === null) {
@ -484,8 +493,8 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
@ -525,7 +534,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -53,24 +55,24 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.'); throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.');
} }
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.'); throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.');
} }
@ -78,12 +80,12 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.'); throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.');
} }
@ -96,20 +98,20 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
*/ */
public function matchedDocs() public function matchedDocs()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.'); throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.');
} }
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.'); throw new Zend_Search_Lucene_Exception('This query is not intended to be executed.');
} }
@ -120,7 +122,7 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
*/ */
public function getQueryTerms() public function getQueryTerms()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Rewrite operation has to be done before retrieving query terms.'); throw new Zend_Search_Lucene_Exception('Rewrite operation has to be done before retrieving query terms.');
} }
} }

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query_Processing */ /**
* Zend_Search_Lucene_Search_Query_Processing
*/
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing.php'; require_once 'Zend/Search/Lucene/Search/Query/Preprocessing.php';
@ -74,9 +76,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
/** /**
* Class constructor. Create a new preprocessing object for prase query. * Class constructor. Create a new preprocessing object for prase query.
* *
* @param string $word Non-tokenized word (query parser lexeme) to search. * @param string $word Non-tokenized word (query parser lexeme) to search.
* @param string $encoding Word encoding. * @param string $encoding Word encoding.
* @param string $fieldName Field name. * @param string $fieldName Field name.
* @param float $minimumSimilarity minimum similarity * @param float $minimumSimilarity minimum similarity
*/ */
public function __construct($word, $encoding, $fieldName, $minimumSimilarity) public function __construct($word, $encoding, $fieldName, $minimumSimilarity)
@ -90,35 +92,38 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
{ {
if ($this->_field === null) { if ($this->_field === null) {
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$query = new Zend_Search_Lucene_Search_Query_Boolean(); $query = new Zend_Search_Lucene_Search_Query_Boolean();
$hasInsignificantSubqueries = false; $hasInsignificantSubqueries = false;
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
if (Zend_Search_Lucene::getDefaultSearchField() === null) { if (Zend_Search_Lucene::getDefaultSearchField() === null) {
$searchFields = $index->getFieldNames(true); $searchFields = $index->getFieldNames(true);
} else { } else {
$searchFields = array(Zend_Search_Lucene::getDefaultSearchField()); $searchFields = array(Zend_Search_Lucene::getDefaultSearchField());
} }
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Fuzzy.php'; include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Fuzzy.php';
foreach ($searchFields as $fieldName) { foreach ($searchFields as $fieldName) {
$subquery = new Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy($this->_word, $subquery = new Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy(
$this->_encoding, $this->_word,
$fieldName, $this->_encoding,
$this->_minimumSimilarity); $fieldName,
$this->_minimumSimilarity
);
$rewrittenSubquery = $subquery->rewrite($index); $rewrittenSubquery = $subquery->rewrite($index);
if ( !($rewrittenSubquery instanceof Zend_Search_Lucene_Search_Query_Insignificant || if (!($rewrittenSubquery instanceof Zend_Search_Lucene_Search_Query_Insignificant
$rewrittenSubquery instanceof Zend_Search_Lucene_Search_Query_Empty) ) { || $rewrittenSubquery instanceof Zend_Search_Lucene_Search_Query_Empty)
) {
$query->addSubquery($rewrittenSubquery); $query->addSubquery($rewrittenSubquery);
} }
@ -132,10 +137,10 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
if (count($subqueries) == 0) { if (count($subqueries) == 0) {
$this->_matches = array(); $this->_matches = array();
if ($hasInsignificantSubqueries) { if ($hasInsignificantSubqueries) {
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
} }
@ -153,10 +158,10 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
// ------------------------------------- // -------------------------------------
// Recognize exact term matching (it corresponds to Keyword fields stored in the index) // Recognize exact term matching (it corresponds to Keyword fields stored in the index)
// encoding is not used since we expect binary matching // encoding is not used since we expect binary matching
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($this->_word, $this->_field); $term = new Zend_Search_Lucene_Index_Term($this->_word, $this->_field);
if ($index->hasTerm($term)) { if ($index->hasTerm($term)) {
require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php'; include_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php';
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_minimumSimilarity); $query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_minimumSimilarity);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -171,33 +176,35 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
// ------------------------------------- // -------------------------------------
// Recognize wildcard queries // Recognize wildcard queries
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */ /**
* @todo check for PCRE unicode support may be performed through Zend_Environment in some future
*/
if (@preg_match('/\pL/u', 'a') == 1) { if (@preg_match('/\pL/u', 'a') == 1) {
$subPatterns = preg_split('/[*?]/u', iconv($this->_encoding, 'UTF-8', $this->_word)); $subPatterns = preg_split('/[*?]/u', iconv($this->_encoding, 'UTF-8', $this->_word));
} else { } else {
$subPatterns = preg_split('/[*?]/', $this->_word); $subPatterns = preg_split('/[*?]/', $this->_word);
} }
if (count($subPatterns) > 1) { if (count($subPatterns) > 1) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search doesn\'t support wildcards (except within Keyword fields).'); throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search doesn\'t support wildcards (except within Keyword fields).');
} }
// ------------------------------------- // -------------------------------------
// Recognize one-term multi-term and "insignificant" queries // Recognize one-term multi-term and "insignificant" queries
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding);
if (count($tokens) == 0) { if (count($tokens) == 0) {
$this->_matches = array(); $this->_matches = array();
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
if (count($tokens) == 1) { if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field); $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php'; include_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php';
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_minimumSimilarity); $query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_minimumSimilarity);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -209,25 +216,31 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
} }
// Word is tokenized into several tokens // Word is tokenized into several tokens
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is supported only for non-multiple word terms'); throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is supported only for non-multiple word terms');
} }
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) 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 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 */ /**
* Skip exact term matching recognition, keyword fields highlighting is not supported
*/
// ------------------------------------- // -------------------------------------
// Recognize wildcard queries // Recognize wildcard queries
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */ /**
* @todo check for PCRE unicode support may be performed through Zend_Environment in some future
*/
if (@preg_match('/\pL/u', 'a') == 1) { if (@preg_match('/\pL/u', 'a') == 1) {
$subPatterns = preg_split('/[*?]/u', iconv($this->_encoding, 'UTF-8', $this->_word)); $subPatterns = preg_split('/[*?]/u', iconv($this->_encoding, 'UTF-8', $this->_word));
} else { } else {
@ -241,16 +254,16 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
// ------------------------------------- // -------------------------------------
// Recognize one-term multi-term and "insignificant" queries // Recognize one-term multi-term and "insignificant" queries
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding);
if (count($tokens) == 0) { if (count($tokens) == 0) {
// Do nothing // Do nothing
return; return;
} }
if (count($tokens) == 1) { if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field); $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php'; include_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php';
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_minimumSimilarity); $query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_minimumSimilarity);
$query->_highlightMatches($highlighter); $query->_highlightMatches($highlighter);

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query_Processing */ /**
* Zend_Search_Lucene_Search_Query_Processing
*/
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing.php'; require_once 'Zend/Search/Lucene/Search/Query/Preprocessing.php';
/** /**
@ -81,9 +83,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
/** /**
* Class constructor. Create a new preprocessing object for prase query. * Class constructor. Create a new preprocessing object for prase query.
* *
* @param string $phrase Phrase to search. * @param string $phrase Phrase to search.
* @param string $phraseEncoding Phrase encoding. * @param string $phraseEncoding Phrase encoding.
* @param string $fieldName Field name. * @param string $fieldName Field name.
*/ */
public function __construct($phrase, $phraseEncoding, $fieldName) public function __construct($phrase, $phraseEncoding, $fieldName)
{ {
@ -116,26 +118,26 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
{ {
// Allow to use wildcards within phrases // Allow to use wildcards within phrases
// They are either removed by text analyzer or used as a part of keyword for keyword fields // They are either removed by text analyzer or used as a part of keyword for keyword fields
// //
// if (strpos($this->_phrase, '?') !== false || strpos($this->_phrase, '*') !== false) { // if (strpos($this->_phrase, '?') !== false || strpos($this->_phrase, '*') !== false) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; // require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
// throw new Zend_Search_Lucene_Search_QueryParserException('Wildcards are only allowed in a single terms.'); // throw new Zend_Search_Lucene_Search_QueryParserException('Wildcards are only allowed in a single terms.');
// } // }
// Split query into subqueries if field name is not specified // Split query into subqueries if field name is not specified
if ($this->_field === null) { if ($this->_field === null) {
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$query = new Zend_Search_Lucene_Search_Query_Boolean(); $query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
if (Zend_Search_Lucene::getDefaultSearchField() === null) { if (Zend_Search_Lucene::getDefaultSearchField() === null) {
$searchFields = $index->getFieldNames(true); $searchFields = $index->getFieldNames(true);
} else { } else {
@ -143,9 +145,11 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
} }
foreach ($searchFields as $fieldName) { foreach ($searchFields as $fieldName) {
$subquery = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase($this->_phrase, $subquery = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase(
$this->_phraseEncoding, $this->_phrase,
$fieldName); $this->_phraseEncoding,
$fieldName
);
$subquery->setSlop($this->getSlop()); $subquery->setSlop($this->getSlop());
$query->addSubquery($subquery->rewrite($index)); $query->addSubquery($subquery->rewrite($index));
@ -157,10 +161,10 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
// Recognize exact term matching (it corresponds to Keyword fields stored in the index) // Recognize exact term matching (it corresponds to Keyword fields stored in the index)
// encoding is not used since we expect binary matching // encoding is not used since we expect binary matching
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($this->_phrase, $this->_field); $term = new Zend_Search_Lucene_Index_Term($this->_phrase, $this->_field);
if ($index->hasTerm($term)) { if ($index->hasTerm($term)) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$query = new Zend_Search_Lucene_Search_Query_Term($term); $query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -170,19 +174,19 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
// tokenize phrase using current analyzer and process it as a phrase query // tokenize phrase using current analyzer and process it as a phrase query
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_phrase, $this->_phraseEncoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_phrase, $this->_phraseEncoding);
if (count($tokens) == 0) { if (count($tokens) == 0) {
$this->_matches = array(); $this->_matches = array();
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
if (count($tokens) == 1) { if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field); $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$query = new Zend_Search_Lucene_Search_Query_Term($term); $query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -192,9 +196,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
//It's non-trivial phrase query //It's non-trivial phrase query
$position = -1; $position = -1;
require_once 'Zend/Search/Lucene/Search/Query/Phrase.php'; include_once 'Zend/Search/Lucene/Search/Query/Phrase.php';
$query = new Zend_Search_Lucene_Search_Query_Phrase(); $query = new Zend_Search_Lucene_Search_Query_Phrase();
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
foreach ($tokens as $token) { foreach ($tokens as $token) {
$position += $token->getPositionIncrement(); $position += $token->getPositionIncrement();
$term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field); $term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field);
@ -208,19 +212,25 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) 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 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 */ /**
* Skip exact term matching recognition, keyword fields highlighting is not supported
*/
/** Skip wildcard queries recognition. Supported wildcards are removed by text analyzer */ /**
* Skip wildcard queries recognition. Supported wildcards are removed by text analyzer
*/
// tokenize phrase using current analyzer and process it as a phrase query // tokenize phrase using current analyzer and process it as a phrase query
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_phrase, $this->_phraseEncoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_phrase, $this->_phraseEncoding);
if (count($tokens) == 0) { if (count($tokens) == 0) {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query_Processing */ /**
* Zend_Search_Lucene_Search_Query_Processing
*/
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing.php'; require_once 'Zend/Search/Lucene/Search/Query/Preprocessing.php';
@ -63,9 +65,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
/** /**
* Class constructor. Create a new preprocessing object for prase query. * Class constructor. Create a new preprocessing object for prase query.
* *
* @param string $word Non-tokenized word (query parser lexeme) to search. * @param string $word Non-tokenized word (query parser lexeme) to search.
* @param string $encoding Word encoding. * @param string $encoding Word encoding.
* @param string $fieldName Field name. * @param string $fieldName Field name.
*/ */
public function __construct($word, $encoding, $fieldName) public function __construct($word, $encoding, $fieldName)
{ {
@ -77,30 +79,32 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
{ {
if ($this->_field === null) { if ($this->_field === null) {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$query = new Zend_Search_Lucene_Search_Query_MultiTerm(); $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
$hasInsignificantSubqueries = false; $hasInsignificantSubqueries = false;
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
if (Zend_Search_Lucene::getDefaultSearchField() === null) { if (Zend_Search_Lucene::getDefaultSearchField() === null) {
$searchFields = $index->getFieldNames(true); $searchFields = $index->getFieldNames(true);
} else { } else {
$searchFields = array(Zend_Search_Lucene::getDefaultSearchField()); $searchFields = array(Zend_Search_Lucene::getDefaultSearchField());
} }
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Term.php';
foreach ($searchFields as $fieldName) { foreach ($searchFields as $fieldName) {
$subquery = new Zend_Search_Lucene_Search_Query_Preprocessing_Term($this->_word, $subquery = new Zend_Search_Lucene_Search_Query_Preprocessing_Term(
$this->_encoding, $this->_word,
$fieldName); $this->_encoding,
$fieldName
);
$rewrittenSubquery = $subquery->rewrite($index); $rewrittenSubquery = $subquery->rewrite($index);
foreach ($rewrittenSubquery->getQueryTerms() as $term) { foreach ($rewrittenSubquery->getQueryTerms() as $term) {
$query->addTerm($term); $query->addTerm($term);
@ -114,10 +118,10 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
if (count($query->getTerms()) == 0) { if (count($query->getTerms()) == 0) {
$this->_matches = array(); $this->_matches = array();
if ($hasInsignificantSubqueries) { if ($hasInsignificantSubqueries) {
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
} }
@ -129,10 +133,10 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
// ------------------------------------- // -------------------------------------
// Recognize exact term matching (it corresponds to Keyword fields stored in the index) // Recognize exact term matching (it corresponds to Keyword fields stored in the index)
// encoding is not used since we expect binary matching // encoding is not used since we expect binary matching
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($this->_word, $this->_field); $term = new Zend_Search_Lucene_Index_Term($this->_word, $this->_field);
if ($index->hasTerm($term)) { if ($index->hasTerm($term)) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$query = new Zend_Search_Lucene_Search_Query_Term($term); $query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -144,7 +148,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
// ------------------------------------- // -------------------------------------
// Recognize wildcard queries // Recognize wildcard queries
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */ /**
* @todo check for PCRE unicode support may be performed through Zend_Environment in some future
*/
if (@preg_match('/\pL/u', 'a') == 1) { if (@preg_match('/\pL/u', 'a') == 1) {
$word = iconv($this->_encoding, 'UTF-8', $this->_word); $word = iconv($this->_encoding, 'UTF-8', $this->_word);
$wildcardsPattern = '/[*?]/u'; $wildcardsPattern = '/[*?]/u';
@ -162,7 +168,7 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
$pattern = ''; $pattern = '';
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
foreach ($subPatterns as $id => $subPattern) { foreach ($subPatterns as $id => $subPattern) {
// Append corresponding wildcard character to the pattern before each sub-pattern (except first) // Append corresponding wildcard character to the pattern before each sub-pattern (except first)
if ($id != 0) { if ($id != 0) {
@ -172,7 +178,7 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
// Check if each subputtern is a single word in terms of current analyzer // Check if each subputtern is a single word in terms of current analyzer
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPattern[0], $subPatternsEncoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPattern[0], $subPatternsEncoding);
if (count($tokens) > 1) { if (count($tokens) > 1) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard search is supported only for non-multiple word terms'); throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard search is supported only for non-multiple word terms');
} }
foreach ($tokens as $token) { foreach ($tokens as $token) {
@ -180,9 +186,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
} }
} }
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field); $term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Wildcard.php'; include_once 'Zend/Search/Lucene/Search/Query/Wildcard.php';
$query = new Zend_Search_Lucene_Search_Query_Wildcard($term); $query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -196,19 +202,19 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
// ------------------------------------- // -------------------------------------
// Recognize one-term multi-term and "insignificant" queries // Recognize one-term multi-term and "insignificant" queries
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding);
if (count($tokens) == 0) { if (count($tokens) == 0) {
$this->_matches = array(); $this->_matches = array();
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
if (count($tokens) == 1) { if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field); $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
$query = new Zend_Search_Lucene_Search_Query_Term($term); $query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
@ -217,14 +223,14 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
} }
//It's not insignificant or one term query //It's not insignificant or one term query
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$query = new Zend_Search_Lucene_Search_Query_MultiTerm(); $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
/** /**
* @todo Process $token->getPositionIncrement() to support stemming, synonyms and other * @todo Process $token->getPositionIncrement() to support stemming, synonyms and other
* analizer design features * analizer design features
*/ */
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
foreach ($tokens as $token) { foreach ($tokens as $token) {
$term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field); $term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field);
$query->addTerm($term, true); // all subterms are required $query->addTerm($term, true); // all subterms are required
@ -239,17 +245,23 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) 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 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 */ /**
* Skip exact term matching recognition, keyword fields highlighting is not supported
*/
// ------------------------------------- // -------------------------------------
// Recognize wildcard queries // Recognize wildcard queries
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */ /**
* @todo check for PCRE unicode support may be performed through Zend_Environment in some future
*/
if (@preg_match('/\pL/u', 'a') == 1) { if (@preg_match('/\pL/u', 'a') == 1) {
$word = iconv($this->_encoding, 'UTF-8', $this->_word); $word = iconv($this->_encoding, 'UTF-8', $this->_word);
$wildcardsPattern = '/[*?]/u'; $wildcardsPattern = '/[*?]/u';
@ -265,7 +277,7 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
$pattern = ''; $pattern = '';
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
foreach ($subPatterns as $id => $subPattern) { foreach ($subPatterns as $id => $subPattern) {
// Append corresponding wildcard character to the pattern before each sub-pattern (except first) // Append corresponding wildcard character to the pattern before each sub-pattern (except first)
if ($id != 0) { if ($id != 0) {
@ -283,9 +295,9 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
} }
} }
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field); $term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
require_once 'Zend/Search/Lucene/Search/Query/Wildcard.php'; include_once 'Zend/Search/Lucene/Search/Query/Wildcard.php';
$query = new Zend_Search_Lucene_Search_Query_Wildcard($term); $query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
$query->_highlightMatches($highlighter); $query->_highlightMatches($highlighter);
@ -295,7 +307,7 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
// ------------------------------------- // -------------------------------------
// Recognize one-term multi-term and "insignificant" queries // Recognize one-term multi-term and "insignificant" queries
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_word, $this->_encoding);
if (count($tokens) == 0) { if (count($tokens) == 0) {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -80,19 +82,19 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
/** /**
* Zend_Search_Lucene_Search_Query_Range constructor. * Zend_Search_Lucene_Search_Query_Range constructor.
* *
* @param Zend_Search_Lucene_Index_Term|null $lowerTerm * @param Zend_Search_Lucene_Index_Term|null $lowerTerm
* @param Zend_Search_Lucene_Index_Term|null $upperTerm * @param Zend_Search_Lucene_Index_Term|null $upperTerm
* @param boolean $inclusive * @param boolean $inclusive
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct($lowerTerm, $upperTerm, $inclusive) public function __construct($lowerTerm, $upperTerm, $inclusive)
{ {
if ($lowerTerm === null && $upperTerm === null) { if ($lowerTerm === null && $upperTerm === null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('At least one term must be non-null'); throw new Zend_Search_Lucene_Exception('At least one term must be non-null');
} }
if ($lowerTerm !== null && $upperTerm !== null && $lowerTerm->field != $upperTerm->field) { if ($lowerTerm !== null && $upperTerm !== null && $lowerTerm->field != $upperTerm->field) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Both terms must be for the same field'); throw new Zend_Search_Lucene_Exception('Both terms must be for the same field');
} }
@ -145,7 +147,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
@ -159,19 +161,20 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
$fields = array($this->_field); $fields = array($this->_field);
} }
require_once 'Zend/Search/Lucene.php'; include_once 'Zend/Search/Lucene.php';
$maxTerms = Zend_Search_Lucene::getTermsPerQueryLimit(); $maxTerms = Zend_Search_Lucene::getTermsPerQueryLimit();
foreach ($fields as $field) { foreach ($fields as $field) {
$index->resetTermsStream(); $index->resetTermsStream();
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
if ($this->_lowerTerm !== null) { if ($this->_lowerTerm !== null) {
$lowerTerm = new Zend_Search_Lucene_Index_Term($this->_lowerTerm->text, $field); $lowerTerm = new Zend_Search_Lucene_Index_Term($this->_lowerTerm->text, $field);
$index->skipTo($lowerTerm); $index->skipTo($lowerTerm);
if (!$this->_inclusive && if (!$this->_inclusive
$index->currentTerm() == $lowerTerm) { && $index->currentTerm() == $lowerTerm
) {
// Skip lower term // Skip lower term
$index->nextTerm(); $index->nextTerm();
} }
@ -190,7 +193,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
$this->_matches[] = $index->currentTerm(); $this->_matches[] = $index->currentTerm();
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) { if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
@ -207,7 +210,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
$this->_matches[] = $index->currentTerm(); $this->_matches[] = $index->currentTerm();
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) { if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
@ -219,13 +222,13 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
} }
if (count($this->_matches) == 0) { if (count($this->_matches) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} else if (count($this->_matches) == 1) { } else if (count($this->_matches) == 1) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches)); return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm(); $rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($this->_matches as $matchedTerm) { foreach ($this->_matches as $matchedTerm) {
@ -239,12 +242,12 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -257,7 +260,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
public function getQueryTerms() public function getQueryTerms()
{ {
if ($this->_matches === null) { if ($this->_matches === null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Search or rewrite operations have to be performed before.'); throw new Zend_Search_Lucene_Exception('Search or rewrite operations have to be performed before.');
} }
@ -267,13 +270,13 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -282,13 +285,13 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -302,35 +305,35 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
*/ */
public function matchedDocs() public function matchedDocs()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)');
} }
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Range query should not be directly used for search. Use $query->rewrite($index)');
} }
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {
$words = array(); $words = array();
$docBody = $highlighter->getDocument()->getFieldUtf8Value('body'); $docBody = $highlighter->getDocument()->getFieldUtf8Value('body');
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8'); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8');
$lowerTermText = ($this->_lowerTerm !== null)? $this->_lowerTerm->text : null; $lowerTermText = ($this->_lowerTerm !== null)? $this->_lowerTerm->text : null;
@ -339,16 +342,18 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
if ($this->_inclusive) { if ($this->_inclusive) {
foreach ($tokens as $token) { foreach ($tokens as $token) {
$termText = $token->getTermText(); $termText = $token->getTermText();
if (($lowerTermText == null || $lowerTermText <= $termText) && if (($lowerTermText == null || $lowerTermText <= $termText)
($upperTermText == null || $termText <= $upperTermText)) { && ($upperTermText == null || $termText <= $upperTermText)
) {
$words[] = $termText; $words[] = $termText;
} }
} }
} else { } else {
foreach ($tokens as $token) { foreach ($tokens as $token) {
$termText = $token->getTermText(); $termText = $token->getTermText();
if (($lowerTermText == null || $lowerTermText < $termText) && if (($lowerTermText == null || $lowerTermText < $termText)
($upperTermText == null || $termText < $upperTermText)) { && ($upperTermText == null || $termText < $upperTermText)
) {
$words[] = $termText; $words[] = $termText;
} }
} }

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -61,7 +63,7 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
* Zend_Search_Lucene_Search_Query_Term constructor * Zend_Search_Lucene_Search_Query_Term constructor
* *
* @param Zend_Search_Lucene_Index_Term $term * @param Zend_Search_Lucene_Index_Term $term
* @param boolean $sign * @param boolean $sign
*/ */
public function __construct(Zend_Search_Lucene_Index_Term $term) public function __construct(Zend_Search_Lucene_Index_Term $term)
{ {
@ -71,7 +73,7 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function rewrite(Zend_Search_Lucene_Interface $index) public function rewrite(Zend_Search_Lucene_Interface $index)
@ -79,11 +81,11 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
if ($this->_term->field != null) { if ($this->_term->field != null) {
return $this; return $this;
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$query = new Zend_Search_Lucene_Search_Query_MultiTerm(); $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->setBoost($this->getBoost()); $query->setBoost($this->getBoost());
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
foreach ($index->getFieldNames(true) as $fieldName) { foreach ($index->getFieldNames(true) as $fieldName) {
$term = new Zend_Search_Lucene_Index_Term($this->_term->text, $fieldName); $term = new Zend_Search_Lucene_Index_Term($this->_term->text, $fieldName);
@ -97,14 +99,14 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
{ {
// Check, that index contains specified term // Check, that index contains specified term
if (!$index->hasTerm($this->_term)) { if (!$index->hasTerm($this->_term)) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} }
@ -115,12 +117,12 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Search/Weight/Term.php'; include_once 'Zend/Search/Lucene/Search/Weight/Term.php';
$this->_weight = new Zend_Search_Lucene_Search_Weight_Term($this->_term, $this, $reader); $this->_weight = new Zend_Search_Lucene_Search_Weight_Term($this->_term, $this, $reader);
return $this->_weight; return $this->_weight;
} }
@ -129,7 +131,7 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
@ -156,8 +158,8 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
@ -195,7 +197,7 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Query */ /**
* Zend_Search_Lucene_Search_Query
*/
require_once 'Zend/Search/Lucene/Search/Query.php'; require_once 'Zend/Search/Lucene/Search/Query.php';
@ -97,7 +99,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
/** /**
* Get terms prefix * Get terms prefix
* *
* @param string $word * @param string $word
* @return string * @return string
*/ */
private static function _getPrefix($word) private static function _getPrefix($word)
@ -121,7 +123,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
/** /**
* Re-write query into primitive queries in the context of specified index * Re-write query into primitive queries in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -138,14 +140,16 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
$prefix = self::_getPrefix($this->_pattern->text); $prefix = self::_getPrefix($this->_pattern->text);
$prefixLength = strlen($prefix); $prefixLength = strlen($prefix);
$matchExpression = '/^' . str_replace(array('\\?', '\\*'), array('.', '.*') , preg_quote($this->_pattern->text, '/')) . '$/'; $matchExpression = '/^' . str_replace(array('\\?', '\\*'), array('.', '.*'), preg_quote($this->_pattern->text, '/')) . '$/';
if ($prefixLength < self::$_minPrefixLength) { if ($prefixLength < self::$_minPrefixLength) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('At least ' . self::$_minPrefixLength . ' non-wildcard characters are required at the beginning of pattern.'); throw new Zend_Search_Lucene_Exception('At least ' . self::$_minPrefixLength . ' non-wildcard characters are required at the beginning of pattern.');
} }
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */ /**
* @todo check for PCRE unicode support may be performed through Zend_Environment in some future
*/
if (@preg_match('/\pL/u', 'a') == 1) { if (@preg_match('/\pL/u', 'a') == 1) {
// PCRE unicode support is turned on // PCRE unicode support is turned on
// add Unicode modifier to the match expression // add Unicode modifier to the match expression
@ -156,7 +160,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
foreach ($fields as $field) { foreach ($fields as $field) {
$index->resetTermsStream(); $index->resetTermsStream();
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
if ($prefix != '') { if ($prefix != '') {
$index->skipTo(new Zend_Search_Lucene_Index_Term($prefix, $field)); $index->skipTo(new Zend_Search_Lucene_Index_Term($prefix, $field));
@ -167,7 +171,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
$this->_matches[] = $index->currentTerm(); $this->_matches[] = $index->currentTerm();
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) { if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
} }
@ -182,7 +186,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
$this->_matches[] = $index->currentTerm(); $this->_matches[] = $index->currentTerm();
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) { if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.'); throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
} }
} }
@ -195,13 +199,13 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
} }
if (count($this->_matches) == 0) { if (count($this->_matches) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Empty.php'; include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty(); return new Zend_Search_Lucene_Search_Query_Empty();
} else if (count($this->_matches) == 1) { } else if (count($this->_matches) == 1) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php'; include_once 'Zend/Search/Lucene/Search/Query/Term.php';
return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches)); return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm(); $rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($this->_matches as $matchedTerm) { foreach ($this->_matches as $matchedTerm) {
@ -215,12 +219,12 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
/** /**
* Optimize query in the context of specified index * Optimize query in the context of specified index
* *
* @param Zend_Search_Lucene_Interface $index * @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function optimize(Zend_Search_Lucene_Interface $index) public function optimize(Zend_Search_Lucene_Interface $index)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -245,7 +249,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
public function getQueryTerms() public function getQueryTerms()
{ {
if ($this->_matches === null) { if ($this->_matches === null) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Search has to be performed first to get matched terms'); throw new Zend_Search_Lucene_Exception('Search has to be performed first to get matched terms');
} }
@ -255,13 +259,13 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
/** /**
* Constructs an appropriate Weight implementation for this query. * Constructs an appropriate Weight implementation for this query.
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return Zend_Search_Lucene_Search_Weight * @return Zend_Search_Lucene_Search_Weight
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function createWeight(Zend_Search_Lucene_Interface $reader) public function createWeight(Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -270,13 +274,13 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
* Execute query in context of index reader * Execute query in context of index reader
* It also initializes necessary internal structures * It also initializes necessary internal structures
* *
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null) public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)');
} }
@ -290,34 +294,34 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
*/ */
public function matchedDocs() public function matchedDocs()
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)');
} }
/** /**
* Score specified document * Score specified document
* *
* @param integer $docId * @param integer $docId
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return float * @return float
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function score($docId, Zend_Search_Lucene_Interface $reader) public function score($docId, Zend_Search_Lucene_Interface $reader)
{ {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)'); throw new Zend_Search_Lucene_Exception('Wildcard query should not be directly used for search. Use $query->rewrite($index)');
} }
/** /**
* Query specific matches highlighting * Query specific matches highlighting
* *
* @param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for 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) protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{ {
$words = array(); $words = array();
$matchExpression = '/^' . str_replace(array('\\?', '\\*'), array('.', '.*') , preg_quote($this->_pattern->text, '/')) . '$/'; $matchExpression = '/^' . str_replace(array('\\?', '\\*'), array('.', '.*'), preg_quote($this->_pattern->text, '/')) . '$/';
if (@preg_match('/\pL/u', 'a') == 1) { if (@preg_match('/\pL/u', 'a') == 1) {
// PCRE unicode support is turned on // PCRE unicode support is turned on
// add Unicode modifier to the match expression // add Unicode modifier to the match expression
@ -325,7 +329,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
} }
$docBody = $highlighter->getDocument()->getFieldUtf8Value('body'); $docBody = $highlighter->getDocument()->getFieldUtf8Value('body');
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8'); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8');
foreach ($tokens as $token) { foreach ($tokens as $token) {
if (preg_match($matchExpression, $token->getTermText()) === 1) { if (preg_match($matchExpression, $token->getTermText()) === 1) {

View File

@ -48,7 +48,7 @@ abstract class Zend_Search_Lucene_Search_QueryEntry
/** /**
* Transform entry to a subquery * Transform entry to a subquery
* *
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
abstract public function getQuery($encoding); abstract public function getQuery($encoding);

View File

@ -20,7 +20,9 @@
* @version $Id: Phrase.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Phrase.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Search_QueryEntry */ /**
* Zend_Search_Lucene_Search_QueryEntry
*/
require_once 'Zend/Search/Lucene/Search/QueryEntry.php'; require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
/** /**
@ -91,19 +93,23 @@ class Zend_Search_Lucene_Search_QueryEntry_Phrase extends Zend_Search_Lucene_Sea
/** /**
* Transform entry to a subquery * Transform entry to a subquery
* *
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException * @throws Zend_Search_Lucene_Search_QueryParserException
*/ */
public function getQuery($encoding) public function getQuery($encoding)
{ {
/** Zend_Search_Lucene_Search_Query_Preprocessing_Phrase */ /**
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Phrase.php'; * Zend_Search_Lucene_Search_Query_Preprocessing_Phrase
$query = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase($this->_phrase, */
$encoding, include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Phrase.php';
($this->_field !== null)? $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase(
$this->_phrase,
$encoding,
($this->_field !== null)?
iconv($encoding, 'UTF-8', $this->_field) : iconv($encoding, 'UTF-8', $this->_field) :
null); null
);
if ($this->_proximityQuery) { if ($this->_proximityQuery) {
$query->setSlop($this->_wordsDistance); $query->setSlop($this->_wordsDistance);

View File

@ -20,7 +20,9 @@
* @version $Id: Subquery.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Subquery.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Search_QueryEntry */ /**
* Zend_Search_Lucene_Search_QueryEntry
*/
require_once 'Zend/Search/Lucene/Search/QueryEntry.php'; require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
/** /**
@ -52,12 +54,12 @@ class Zend_Search_Lucene_Search_QueryEntry_Subquery extends Zend_Search_Lucene_S
/** /**
* Process modifier ('~') * Process modifier ('~')
* *
* @param mixed $parameter * @param mixed $parameter
* @throws Zend_Search_Lucene_Search_QueryParserException * @throws Zend_Search_Lucene_Search_QueryParserException
*/ */
public function processFuzzyProximityModifier($parameter = null) public function processFuzzyProximityModifier($parameter = null)
{ {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('\'~\' sign must follow term or phrase'); throw new Zend_Search_Lucene_Search_QueryParserException('\'~\' sign must follow term or phrase');
} }
@ -65,7 +67,7 @@ class Zend_Search_Lucene_Search_QueryEntry_Subquery extends Zend_Search_Lucene_S
/** /**
* Transform entry to a subquery * Transform entry to a subquery
* *
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
*/ */
public function getQuery($encoding) public function getQuery($encoding)

View File

@ -20,7 +20,9 @@
* @version $Id: Term.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Term.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Search_QueryEntry */ /**
* Zend_Search_Lucene_Search_QueryEntry
*/
require_once 'Zend/Search/Lucene/Search/QueryEntry.php'; require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
/** /**
@ -86,8 +88,10 @@ class Zend_Search_Lucene_Search_QueryEntry_Term extends Zend_Search_Lucene_Searc
if ($parameter !== null) { if ($parameter !== null) {
$this->_similarity = $parameter; $this->_similarity = $parameter;
} else { } else {
/** Zend_Search_Lucene_Search_Query_Fuzzy */ /**
require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php'; * Zend_Search_Lucene_Search_Query_Fuzzy
*/
include_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php';
$this->_similarity = Zend_Search_Lucene_Search_Query_Fuzzy::DEFAULT_MIN_SIMILARITY; $this->_similarity = Zend_Search_Lucene_Search_Query_Fuzzy::DEFAULT_MIN_SIMILARITY;
} }
} }
@ -95,35 +99,41 @@ class Zend_Search_Lucene_Search_QueryEntry_Term extends Zend_Search_Lucene_Searc
/** /**
* Transform entry to a subquery * Transform entry to a subquery
* *
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException * @throws Zend_Search_Lucene_Search_QueryParserException
*/ */
public function getQuery($encoding) public function getQuery($encoding)
{ {
if ($this->_fuzzyQuery) { if ($this->_fuzzyQuery) {
/** Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy */ /**
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Fuzzy.php'; * Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy
$query = new Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy($this->_term, */
$encoding, include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Fuzzy.php';
($this->_field !== null)? $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy(
$this->_term,
$encoding,
($this->_field !== null)?
iconv($encoding, 'UTF-8', $this->_field) : iconv($encoding, 'UTF-8', $this->_field) :
null, null,
$this->_similarity $this->_similarity
); );
$query->setBoost($this->_boost); $query->setBoost($this->_boost);
return $query; return $query;
} }
/** Zend_Search_Lucene_Search_Query_Preprocessing_Term */ /**
require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Term.php'; * Zend_Search_Lucene_Search_Query_Preprocessing_Term
$query = new Zend_Search_Lucene_Search_Query_Preprocessing_Term($this->_term, */
$encoding, include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Term.php';
($this->_field !== null)? $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Term(
$this->_term,
$encoding,
($this->_field !== null)?
iconv($encoding, 'UTF-8', $this->_field) : iconv($encoding, 'UTF-8', $this->_field) :
null null
); );
$query->setBoost($this->_boost); $query->setBoost($this->_boost);
return $query; return $query;
} }

View File

@ -32,24 +32,28 @@ class Zend_Search_Lucene_Search_QueryHit
{ {
/** /**
* Object handle of the index * Object handle of the index
*
* @var Zend_Search_Lucene_Interface * @var Zend_Search_Lucene_Interface
*/ */
protected $_index = null; protected $_index = null;
/** /**
* Object handle of the document associated with this hit * Object handle of the document associated with this hit
*
* @var Zend_Search_Lucene_Document * @var Zend_Search_Lucene_Document
*/ */
protected $_document = null; protected $_document = null;
/** /**
* Number of the document in the index * Number of the document in the index
*
* @var integer * @var integer
*/ */
public $id; public $id;
/** /**
* Score of the hit * Score of the hit
*
* @var float * @var float
*/ */
public $score; public $score;
@ -64,7 +68,7 @@ class Zend_Search_Lucene_Search_QueryHit
public function __construct(Zend_Search_Lucene_Interface $index) public function __construct(Zend_Search_Lucene_Interface $index)
{ {
require_once 'Zend/Search/Lucene/Proxy.php'; include_once 'Zend/Search/Lucene/Proxy.php';
$this->_index = new Zend_Search_Lucene_Proxy($index); $this->_index = new Zend_Search_Lucene_Proxy($index);
} }
@ -73,7 +77,7 @@ class Zend_Search_Lucene_Search_QueryHit
* Convenience function for getting fields from the document * Convenience function for getting fields from the document
* associated with this hit. * associated with this hit.
* *
* @param string $offset * @param string $offset
* @return string * @return string
*/ */
public function __get($offset) public function __get($offset)

View File

@ -20,10 +20,14 @@
* @version $Id: QueryLexer.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: QueryLexer.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_FSM */ /**
* Zend_Search_Lucene_FSM
*/
require_once 'Zend/Search/Lucene/FSM.php'; require_once 'Zend/Search/Lucene/FSM.php';
/** Zend_Search_Lucene_Search_QueryParser */ /**
* Zend_Search_Lucene_Search_QueryParser
*/
require_once 'Zend/Search/Lucene/Search/QueryToken.php'; require_once 'Zend/Search/Lucene/Search/QueryToken.php';
/** /**
@ -35,7 +39,9 @@ require_once 'Zend/Search/Lucene/Search/QueryToken.php';
*/ */
class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
{ {
/** State Machine states */ /**
* State Machine states
*/
const ST_WHITE_SPACE = 0; const ST_WHITE_SPACE = 0;
const ST_SYNT_LEXEME = 1; const ST_SYNT_LEXEME = 1;
const ST_LEXEME = 2; const ST_LEXEME = 2;
@ -47,7 +53,9 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
const ST_MANTISSA = 8; const ST_MANTISSA = 8;
const ST_ERROR = 9; const ST_ERROR = 9;
/** Input symbols */ /**
* Input symbols
*/
const IN_WHITE_SPACE = 0; const IN_WHITE_SPACE = 0;
const IN_SYNT_CHAR = 1; const IN_SYNT_CHAR = 1;
const IN_LEXEME_MODIFIER = 2; const IN_LEXEME_MODIFIER = 2;
@ -96,7 +104,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
public function __construct() public function __construct()
{ {
parent::__construct( array(self::ST_WHITE_SPACE, parent::__construct(
array(self::ST_WHITE_SPACE,
self::ST_SYNT_LEXEME, self::ST_SYNT_LEXEME,
self::ST_LEXEME, self::ST_LEXEME,
self::ST_QUOTED_LEXEME, self::ST_QUOTED_LEXEME,
@ -106,7 +115,7 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
self::ST_NUMBER, self::ST_NUMBER,
self::ST_MANTISSA, self::ST_MANTISSA,
self::ST_ERROR), self::ST_ERROR),
array(self::IN_WHITE_SPACE, array(self::IN_WHITE_SPACE,
self::IN_SYNT_CHAR, self::IN_SYNT_CHAR,
self::IN_MUTABLE_CHAR, self::IN_MUTABLE_CHAR,
self::IN_LEXEME_MODIFIER, self::IN_LEXEME_MODIFIER,
@ -114,7 +123,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
self::IN_QUOTE, self::IN_QUOTE,
self::IN_DECIMAL_POINT, self::IN_DECIMAL_POINT,
self::IN_ASCII_DIGIT, self::IN_ASCII_DIGIT,
self::IN_CHAR)); self::IN_CHAR)
);
$lexemeModifierErrorAction = new Zend_Search_Lucene_FSMAction($this, 'lexModifierErrException'); $lexemeModifierErrorAction = new Zend_Search_Lucene_FSMAction($this, 'lexModifierErrException');
@ -123,7 +133,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$this->addRules(array( array(self::ST_WHITE_SPACE, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE), $this->addRules(
array( array(self::ST_WHITE_SPACE, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE),
array(self::ST_WHITE_SPACE, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME), array(self::ST_WHITE_SPACE, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_WHITE_SPACE, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME), array(self::ST_WHITE_SPACE, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_WHITE_SPACE, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER), array(self::ST_WHITE_SPACE, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER),
@ -132,8 +143,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
array(self::ST_WHITE_SPACE, self::IN_DECIMAL_POINT, self::ST_LEXEME), array(self::ST_WHITE_SPACE, self::IN_DECIMAL_POINT, self::ST_LEXEME),
array(self::ST_WHITE_SPACE, self::IN_ASCII_DIGIT, self::ST_LEXEME), array(self::ST_WHITE_SPACE, self::IN_ASCII_DIGIT, self::ST_LEXEME),
array(self::ST_WHITE_SPACE, self::IN_CHAR, self::ST_LEXEME) array(self::ST_WHITE_SPACE, self::IN_CHAR, self::ST_LEXEME)
)); )
$this->addRules(array( array(self::ST_SYNT_LEXEME, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE), );
$this->addRules(
array( array(self::ST_SYNT_LEXEME, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE),
array(self::ST_SYNT_LEXEME, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME), array(self::ST_SYNT_LEXEME, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_SYNT_LEXEME, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME), array(self::ST_SYNT_LEXEME, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_SYNT_LEXEME, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER), array(self::ST_SYNT_LEXEME, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER),
@ -142,8 +155,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
array(self::ST_SYNT_LEXEME, self::IN_DECIMAL_POINT, self::ST_LEXEME), array(self::ST_SYNT_LEXEME, self::IN_DECIMAL_POINT, self::ST_LEXEME),
array(self::ST_SYNT_LEXEME, self::IN_ASCII_DIGIT, self::ST_LEXEME), array(self::ST_SYNT_LEXEME, self::IN_ASCII_DIGIT, self::ST_LEXEME),
array(self::ST_SYNT_LEXEME, self::IN_CHAR, self::ST_LEXEME) array(self::ST_SYNT_LEXEME, self::IN_CHAR, self::ST_LEXEME)
)); )
$this->addRules(array( array(self::ST_LEXEME, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE), );
$this->addRules(
array( array(self::ST_LEXEME, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE),
array(self::ST_LEXEME, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME), array(self::ST_LEXEME, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_LEXEME, self::IN_MUTABLE_CHAR, self::ST_LEXEME), array(self::ST_LEXEME, self::IN_MUTABLE_CHAR, self::ST_LEXEME),
array(self::ST_LEXEME, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER), array(self::ST_LEXEME, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER),
@ -155,8 +170,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
array(self::ST_LEXEME, self::IN_DECIMAL_POINT, self::ST_LEXEME), array(self::ST_LEXEME, self::IN_DECIMAL_POINT, self::ST_LEXEME),
array(self::ST_LEXEME, self::IN_ASCII_DIGIT, self::ST_LEXEME), array(self::ST_LEXEME, self::IN_ASCII_DIGIT, self::ST_LEXEME),
array(self::ST_LEXEME, self::IN_CHAR, self::ST_LEXEME) array(self::ST_LEXEME, self::IN_CHAR, self::ST_LEXEME)
)); )
$this->addRules(array( array(self::ST_QUOTED_LEXEME, self::IN_WHITE_SPACE, self::ST_QUOTED_LEXEME), );
$this->addRules(
array( array(self::ST_QUOTED_LEXEME, self::IN_WHITE_SPACE, self::ST_QUOTED_LEXEME),
array(self::ST_QUOTED_LEXEME, self::IN_SYNT_CHAR, self::ST_QUOTED_LEXEME), array(self::ST_QUOTED_LEXEME, self::IN_SYNT_CHAR, self::ST_QUOTED_LEXEME),
array(self::ST_QUOTED_LEXEME, self::IN_MUTABLE_CHAR, self::ST_QUOTED_LEXEME), array(self::ST_QUOTED_LEXEME, self::IN_MUTABLE_CHAR, self::ST_QUOTED_LEXEME),
array(self::ST_QUOTED_LEXEME, self::IN_LEXEME_MODIFIER, self::ST_QUOTED_LEXEME), array(self::ST_QUOTED_LEXEME, self::IN_LEXEME_MODIFIER, self::ST_QUOTED_LEXEME),
@ -165,8 +182,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
array(self::ST_QUOTED_LEXEME, self::IN_DECIMAL_POINT, self::ST_QUOTED_LEXEME), array(self::ST_QUOTED_LEXEME, self::IN_DECIMAL_POINT, self::ST_QUOTED_LEXEME),
array(self::ST_QUOTED_LEXEME, self::IN_ASCII_DIGIT, self::ST_QUOTED_LEXEME), array(self::ST_QUOTED_LEXEME, self::IN_ASCII_DIGIT, self::ST_QUOTED_LEXEME),
array(self::ST_QUOTED_LEXEME, self::IN_CHAR, self::ST_QUOTED_LEXEME) array(self::ST_QUOTED_LEXEME, self::IN_CHAR, self::ST_QUOTED_LEXEME)
)); )
$this->addRules(array( array(self::ST_ESCAPED_CHAR, self::IN_WHITE_SPACE, self::ST_LEXEME), );
$this->addRules(
array( array(self::ST_ESCAPED_CHAR, self::IN_WHITE_SPACE, self::ST_LEXEME),
array(self::ST_ESCAPED_CHAR, self::IN_SYNT_CHAR, self::ST_LEXEME), array(self::ST_ESCAPED_CHAR, self::IN_SYNT_CHAR, self::ST_LEXEME),
array(self::ST_ESCAPED_CHAR, self::IN_MUTABLE_CHAR, self::ST_LEXEME), array(self::ST_ESCAPED_CHAR, self::IN_MUTABLE_CHAR, self::ST_LEXEME),
array(self::ST_ESCAPED_CHAR, self::IN_LEXEME_MODIFIER, self::ST_LEXEME), array(self::ST_ESCAPED_CHAR, self::IN_LEXEME_MODIFIER, self::ST_LEXEME),
@ -175,8 +194,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
array(self::ST_ESCAPED_CHAR, self::IN_DECIMAL_POINT, self::ST_LEXEME), array(self::ST_ESCAPED_CHAR, self::IN_DECIMAL_POINT, self::ST_LEXEME),
array(self::ST_ESCAPED_CHAR, self::IN_ASCII_DIGIT, self::ST_LEXEME), array(self::ST_ESCAPED_CHAR, self::IN_ASCII_DIGIT, self::ST_LEXEME),
array(self::ST_ESCAPED_CHAR, self::IN_CHAR, self::ST_LEXEME) array(self::ST_ESCAPED_CHAR, self::IN_CHAR, self::ST_LEXEME)
)); )
$this->addRules(array( array(self::ST_ESCAPED_QCHAR, self::IN_WHITE_SPACE, self::ST_QUOTED_LEXEME), );
$this->addRules(
array( array(self::ST_ESCAPED_QCHAR, self::IN_WHITE_SPACE, self::ST_QUOTED_LEXEME),
array(self::ST_ESCAPED_QCHAR, self::IN_SYNT_CHAR, self::ST_QUOTED_LEXEME), array(self::ST_ESCAPED_QCHAR, self::IN_SYNT_CHAR, self::ST_QUOTED_LEXEME),
array(self::ST_ESCAPED_QCHAR, self::IN_MUTABLE_CHAR, self::ST_QUOTED_LEXEME), array(self::ST_ESCAPED_QCHAR, self::IN_MUTABLE_CHAR, self::ST_QUOTED_LEXEME),
array(self::ST_ESCAPED_QCHAR, self::IN_LEXEME_MODIFIER, self::ST_QUOTED_LEXEME), array(self::ST_ESCAPED_QCHAR, self::IN_LEXEME_MODIFIER, self::ST_QUOTED_LEXEME),
@ -185,8 +206,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
array(self::ST_ESCAPED_QCHAR, self::IN_DECIMAL_POINT, self::ST_QUOTED_LEXEME), array(self::ST_ESCAPED_QCHAR, self::IN_DECIMAL_POINT, self::ST_QUOTED_LEXEME),
array(self::ST_ESCAPED_QCHAR, self::IN_ASCII_DIGIT, self::ST_QUOTED_LEXEME), array(self::ST_ESCAPED_QCHAR, self::IN_ASCII_DIGIT, self::ST_QUOTED_LEXEME),
array(self::ST_ESCAPED_QCHAR, self::IN_CHAR, self::ST_QUOTED_LEXEME) array(self::ST_ESCAPED_QCHAR, self::IN_CHAR, self::ST_QUOTED_LEXEME)
)); )
$this->addRules(array( array(self::ST_LEXEME_MODIFIER, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE), );
$this->addRules(
array( array(self::ST_LEXEME_MODIFIER, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE),
array(self::ST_LEXEME_MODIFIER, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME), array(self::ST_LEXEME_MODIFIER, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_LEXEME_MODIFIER, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME), array(self::ST_LEXEME_MODIFIER, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_LEXEME_MODIFIER, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER), array(self::ST_LEXEME_MODIFIER, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER),
@ -203,8 +226,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
// IN_CHAR not allowed // IN_CHAR not allowed
array(self::ST_LEXEME_MODIFIER, self::IN_CHAR, self::ST_ERROR, $lexemeModifierErrorAction), array(self::ST_LEXEME_MODIFIER, self::IN_CHAR, self::ST_ERROR, $lexemeModifierErrorAction),
)); )
$this->addRules(array( array(self::ST_NUMBER, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE), );
$this->addRules(
array( array(self::ST_NUMBER, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE),
array(self::ST_NUMBER, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME), array(self::ST_NUMBER, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_NUMBER, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME), array(self::ST_NUMBER, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_NUMBER, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER), array(self::ST_NUMBER, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER),
@ -220,8 +245,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
// IN_CHAR not allowed // IN_CHAR not allowed
array(self::ST_NUMBER, self::IN_CHAR, self::ST_ERROR, $wrongNumberErrorAction), array(self::ST_NUMBER, self::IN_CHAR, self::ST_ERROR, $wrongNumberErrorAction),
)); )
$this->addRules(array( array(self::ST_MANTISSA, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE), );
$this->addRules(
array( array(self::ST_MANTISSA, self::IN_WHITE_SPACE, self::ST_WHITE_SPACE),
array(self::ST_MANTISSA, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME), array(self::ST_MANTISSA, self::IN_SYNT_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_MANTISSA, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME), array(self::ST_MANTISSA, self::IN_MUTABLE_CHAR, self::ST_SYNT_LEXEME),
array(self::ST_MANTISSA, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER), array(self::ST_MANTISSA, self::IN_LEXEME_MODIFIER, self::ST_LEXEME_MODIFIER),
@ -239,10 +266,13 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
// IN_CHAR not allowed // IN_CHAR not allowed
array(self::ST_MANTISSA, self::IN_CHAR, self::ST_ERROR, $wrongNumberErrorAction), array(self::ST_MANTISSA, self::IN_CHAR, self::ST_ERROR, $wrongNumberErrorAction),
)); )
);
/** Actions */ /**
* Actions
*/
$syntaxLexemeAction = new Zend_Search_Lucene_FSMAction($this, 'addQuerySyntaxLexeme'); $syntaxLexemeAction = new Zend_Search_Lucene_FSMAction($this, 'addQuerySyntaxLexeme');
$lexemeModifierAction = new Zend_Search_Lucene_FSMAction($this, 'addLexemeModifier'); $lexemeModifierAction = new Zend_Search_Lucene_FSMAction($this, 'addLexemeModifier');
$addLexemeAction = new Zend_Search_Lucene_FSMAction($this, 'addLexeme'); $addLexemeAction = new Zend_Search_Lucene_FSMAction($this, 'addLexeme');
@ -251,13 +281,17 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$addLexemeCharAction = new Zend_Search_Lucene_FSMAction($this, 'addLexemeChar'); $addLexemeCharAction = new Zend_Search_Lucene_FSMAction($this, 'addLexemeChar');
/** Syntax lexeme */ /**
* Syntax lexeme
*/
$this->addEntryAction(self::ST_SYNT_LEXEME, $syntaxLexemeAction); $this->addEntryAction(self::ST_SYNT_LEXEME, $syntaxLexemeAction);
// Two lexemes in succession // Two lexemes in succession
$this->addTransitionAction(self::ST_SYNT_LEXEME, self::ST_SYNT_LEXEME, $syntaxLexemeAction); $this->addTransitionAction(self::ST_SYNT_LEXEME, self::ST_SYNT_LEXEME, $syntaxLexemeAction);
/** Lexeme */ /**
* Lexeme
*/
$this->addEntryAction(self::ST_LEXEME, $addLexemeCharAction); $this->addEntryAction(self::ST_LEXEME, $addLexemeCharAction);
$this->addTransitionAction(self::ST_LEXEME, self::ST_LEXEME, $addLexemeCharAction); $this->addTransitionAction(self::ST_LEXEME, self::ST_LEXEME, $addLexemeCharAction);
// ST_ESCAPED_CHAR => ST_LEXEME transition is covered by ST_LEXEME entry action // ST_ESCAPED_CHAR => ST_LEXEME transition is covered by ST_LEXEME entry action
@ -270,7 +304,9 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$this->addTransitionAction(self::ST_LEXEME, self::ST_MANTISSA, $addLexemeAction); $this->addTransitionAction(self::ST_LEXEME, self::ST_MANTISSA, $addLexemeAction);
/** Quoted lexeme */ /**
* Quoted lexeme
*/
// We don't need entry action (skeep quote) // We don't need entry action (skeep quote)
$this->addTransitionAction(self::ST_QUOTED_LEXEME, self::ST_QUOTED_LEXEME, $addLexemeCharAction); $this->addTransitionAction(self::ST_QUOTED_LEXEME, self::ST_QUOTED_LEXEME, $addLexemeCharAction);
$this->addTransitionAction(self::ST_ESCAPED_QCHAR, self::ST_QUOTED_LEXEME, $addLexemeCharAction); $this->addTransitionAction(self::ST_ESCAPED_QCHAR, self::ST_QUOTED_LEXEME, $addLexemeCharAction);
@ -278,11 +314,15 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$this->addTransitionAction(self::ST_QUOTED_LEXEME, self::ST_WHITE_SPACE, $addQuotedLexemeAction); $this->addTransitionAction(self::ST_QUOTED_LEXEME, self::ST_WHITE_SPACE, $addQuotedLexemeAction);
/** Lexeme modifier */ /**
* Lexeme modifier
*/
$this->addEntryAction(self::ST_LEXEME_MODIFIER, $lexemeModifierAction); $this->addEntryAction(self::ST_LEXEME_MODIFIER, $lexemeModifierAction);
/** Number */ /**
* Number
*/
$this->addEntryAction(self::ST_NUMBER, $addLexemeCharAction); $this->addEntryAction(self::ST_NUMBER, $addLexemeCharAction);
$this->addEntryAction(self::ST_MANTISSA, $addLexemeCharAction); $this->addEntryAction(self::ST_MANTISSA, $addLexemeCharAction);
$this->addTransitionAction(self::ST_NUMBER, self::ST_NUMBER, $addLexemeCharAction); $this->addTransitionAction(self::ST_NUMBER, self::ST_NUMBER, $addLexemeCharAction);
@ -303,7 +343,7 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
/** /**
* Translate input char to an input symbol of state machine * Translate input char to an input symbol of state machine
* *
* @param string $char * @param string $char
* @return integer * @return integer
*/ */
private function _translateInput($char) private function _translateInput($char)
@ -313,9 +353,9 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
} else if (strpos(self::QUERY_MUTABLE_CHARS, $char) !== false) { return self::IN_MUTABLE_CHAR; } else if (strpos(self::QUERY_MUTABLE_CHARS, $char) !== false) { return self::IN_MUTABLE_CHAR;
} else if (strpos(self::QUERY_LEXEMEMODIFIER_CHARS, $char) !== false) { return self::IN_LEXEME_MODIFIER; } else if (strpos(self::QUERY_LEXEMEMODIFIER_CHARS, $char) !== false) { return self::IN_LEXEME_MODIFIER;
} else if (strpos(self::QUERY_ASCIIDIGITS_CHARS, $char) !== false) { return self::IN_ASCII_DIGIT; } else if (strpos(self::QUERY_ASCIIDIGITS_CHARS, $char) !== false) { return self::IN_ASCII_DIGIT;
} else if ($char === '"' ) { return self::IN_QUOTE; } else if ($char === '"' ) { return self::IN_QUOTE;
} else if ($char === '.' ) { return self::IN_DECIMAL_POINT; } else if ($char === '.' ) { return self::IN_DECIMAL_POINT;
} else if ($char === '\\') { return self::IN_ESCAPE_CHAR; } else if ($char === '\\') { return self::IN_ESCAPE_CHAR;
} else { return self::IN_CHAR; } else { return self::IN_CHAR;
} }
} }
@ -324,8 +364,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
/** /**
* This method is used to tokenize query string into lexemes * This method is used to tokenize query string into lexemes
* *
* @param string $inputString * @param string $inputString
* @param string $encoding * @param string $encoding
* @return array * @return array
* @throws Zend_Search_Lucene_Search_QueryParserException * @throws Zend_Search_Lucene_Search_QueryParserException
*/ */
@ -357,7 +397,7 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$this->process(self::IN_WHITE_SPACE); $this->process(self::IN_WHITE_SPACE);
if ($this->getState() != self::ST_WHITE_SPACE) { if ($this->getState() != self::ST_WHITE_SPACE) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Unexpected end of query'); throw new Zend_Search_Lucene_Search_QueryParserException('Unexpected end of query');
} }
@ -389,26 +429,28 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$this->_queryStringPosition++; $this->_queryStringPosition++;
// check, // check,
if ($this->_queryStringPosition == count($this->_queryString) || if ($this->_queryStringPosition == count($this->_queryString)
$this->_queryString[$this->_queryStringPosition] != $lexeme) { || $this->_queryString[$this->_queryStringPosition] != $lexeme
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; ) {
include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Two chars lexeme expected. ' . $this->_positionMsg()); throw new Zend_Search_Lucene_Search_QueryParserException('Two chars lexeme expected. ' . $this->_positionMsg());
} }
// duplicate character // duplicate character
$lexeme .= $lexeme; $lexeme .= $lexeme;
} }
$token = new Zend_Search_Lucene_Search_QueryToken( $token = new Zend_Search_Lucene_Search_QueryToken(
Zend_Search_Lucene_Search_QueryToken::TC_SYNTAX_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TC_SYNTAX_ELEMENT,
$lexeme, $lexeme,
$this->_queryStringPosition); $this->_queryStringPosition
);
// Skip this lexeme if it's a field indicator ':' and treat previous as 'field' instead of 'word' // Skip this lexeme if it's a field indicator ':' and treat previous as 'field' instead of 'word'
if ($token->type == Zend_Search_Lucene_Search_QueryToken::TT_FIELD_INDICATOR) { if ($token->type == Zend_Search_Lucene_Search_QueryToken::TT_FIELD_INDICATOR) {
$token = array_pop($this->_lexemes); $token = array_pop($this->_lexemes);
if ($token === null || $token->type != Zend_Search_Lucene_Search_QueryToken::TT_WORD) { if ($token === null || $token->type != Zend_Search_Lucene_Search_QueryToken::TT_WORD) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Field mark \':\' must follow field name. ' . $this->_positionMsg()); throw new Zend_Search_Lucene_Search_QueryParserException('Field mark \':\' must follow field name. ' . $this->_positionMsg());
} }
@ -424,9 +466,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
public function addLexemeModifier() public function addLexemeModifier()
{ {
$this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken( $this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken(
Zend_Search_Lucene_Search_QueryToken::TC_SYNTAX_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TC_SYNTAX_ELEMENT,
$this->_queryString[$this->_queryStringPosition], $this->_queryString[$this->_queryStringPosition],
$this->_queryStringPosition); $this->_queryStringPosition
);
} }
@ -436,9 +479,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
public function addLexeme() public function addLexeme()
{ {
$this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken( $this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken(
Zend_Search_Lucene_Search_QueryToken::TC_WORD, Zend_Search_Lucene_Search_QueryToken::TC_WORD,
$this->_currentLexeme, $this->_currentLexeme,
$this->_queryStringPosition - 1); $this->_queryStringPosition - 1
);
$this->_currentLexeme = ''; $this->_currentLexeme = '';
} }
@ -449,9 +493,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
public function addQuotedLexeme() public function addQuotedLexeme()
{ {
$this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken( $this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken(
Zend_Search_Lucene_Search_QueryToken::TC_PHRASE, Zend_Search_Lucene_Search_QueryToken::TC_PHRASE,
$this->_currentLexeme, $this->_currentLexeme,
$this->_queryStringPosition); $this->_queryStringPosition
);
$this->_currentLexeme = ''; $this->_currentLexeme = '';
} }
@ -462,9 +507,10 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
public function addNumberLexeme() public function addNumberLexeme()
{ {
$this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken( $this->_lexemes[] = new Zend_Search_Lucene_Search_QueryToken(
Zend_Search_Lucene_Search_QueryToken::TC_NUMBER, Zend_Search_Lucene_Search_QueryToken::TC_NUMBER,
$this->_currentLexeme, $this->_currentLexeme,
$this->_queryStringPosition - 1); $this->_queryStringPosition - 1
);
$this->_currentLexeme = ''; $this->_currentLexeme = '';
} }
@ -493,17 +539,17 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
*********************************************************************/ *********************************************************************/
public function lexModifierErrException() public function lexModifierErrException()
{ {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Lexeme modifier character can be followed only by number, white space or query syntax element. ' . $this->_positionMsg()); throw new Zend_Search_Lucene_Search_QueryParserException('Lexeme modifier character can be followed only by number, white space or query syntax element. ' . $this->_positionMsg());
} }
public function quoteWithinLexemeErrException() public function quoteWithinLexemeErrException()
{ {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Quote within lexeme must be escaped by \'\\\' char. ' . $this->_positionMsg()); throw new Zend_Search_Lucene_Search_QueryParserException('Quote within lexeme must be escaped by \'\\\' char. ' . $this->_positionMsg());
} }
public function wrongNumberErrException() public function wrongNumberErrException()
{ {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Wrong number syntax.' . $this->_positionMsg()); throw new Zend_Search_Lucene_Search_QueryParserException('Wrong number syntax.' . $this->_positionMsg());
} }
} }

View File

@ -21,17 +21,25 @@
*/ */
/** Internally used classes */ /**
* Internally used classes
*/
/** Zend_Search_Lucene_Analysis_Analyzer */ /**
* Zend_Search_Lucene_Analysis_Analyzer
*/
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php'; require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
/** Zend_Search_Lucene_Search_QueryToken */ /**
* Zend_Search_Lucene_Search_QueryToken
*/
require_once 'Zend/Search/Lucene/Search/QueryToken.php'; require_once 'Zend/Search/Lucene/Search/QueryToken.php';
/** Zend_Search_Lucene_FSM */ /**
* Zend_Search_Lucene_FSM
*/
require_once 'Zend/Search/Lucene/FSM.php'; require_once 'Zend/Search/Lucene/FSM.php';
/** /**
@ -152,7 +160,9 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
private $_defaultOperator = self::B_OR; private $_defaultOperator = self::B_OR;
/** Query parser State Machine states */ /**
* Query parser State Machine states
*/
const ST_COMMON_QUERY_ELEMENT = 0; // Terms, phrases, operators const ST_COMMON_QUERY_ELEMENT = 0; // Terms, phrases, operators
const ST_CLOSEDINT_RQ_START = 1; // Range query start (closed interval) - '[' const ST_CLOSEDINT_RQ_START = 1; // Range query start (closed interval) - '['
const ST_CLOSEDINT_RQ_FIRST_TERM = 2; // First term in '[term1 to term2]' construction const ST_CLOSEDINT_RQ_FIRST_TERM = 2; // First term in '[term1 to term2]' construction
@ -170,7 +180,8 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
*/ */
public function __construct() public function __construct()
{ {
parent::__construct(array(self::ST_COMMON_QUERY_ELEMENT, parent::__construct(
array(self::ST_COMMON_QUERY_ELEMENT,
self::ST_CLOSEDINT_RQ_START, self::ST_CLOSEDINT_RQ_START,
self::ST_CLOSEDINT_RQ_FIRST_TERM, self::ST_CLOSEDINT_RQ_FIRST_TERM,
self::ST_CLOSEDINT_RQ_TO_TERM, self::ST_CLOSEDINT_RQ_TO_TERM,
@ -182,10 +193,11 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
self::ST_OPENEDINT_RQ_LAST_TERM, self::ST_OPENEDINT_RQ_LAST_TERM,
self::ST_OPENEDINT_RQ_END self::ST_OPENEDINT_RQ_END
), ),
Zend_Search_Lucene_Search_QueryToken::getTypes()); Zend_Search_Lucene_Search_QueryToken::getTypes()
);
$this->addRules( $this->addRules(
array(array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_COMMON_QUERY_ELEMENT), array(array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_COMMON_QUERY_ELEMENT),
array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_PHRASE, self::ST_COMMON_QUERY_ELEMENT), array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_PHRASE, self::ST_COMMON_QUERY_ELEMENT),
array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_FIELD, self::ST_COMMON_QUERY_ELEMENT), array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_FIELD, self::ST_COMMON_QUERY_ELEMENT),
array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_REQUIRED, self::ST_COMMON_QUERY_ELEMENT), array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_REQUIRED, self::ST_COMMON_QUERY_ELEMENT),
@ -200,19 +212,22 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_OR_LEXEME, self::ST_COMMON_QUERY_ELEMENT), array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_OR_LEXEME, self::ST_COMMON_QUERY_ELEMENT),
array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_NOT_LEXEME, self::ST_COMMON_QUERY_ELEMENT), array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_NOT_LEXEME, self::ST_COMMON_QUERY_ELEMENT),
array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_NUMBER, self::ST_COMMON_QUERY_ELEMENT) array(self::ST_COMMON_QUERY_ELEMENT, Zend_Search_Lucene_Search_QueryToken::TT_NUMBER, self::ST_COMMON_QUERY_ELEMENT)
)); )
);
$this->addRules( $this->addRules(
array(array(self::ST_CLOSEDINT_RQ_START, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_CLOSEDINT_RQ_FIRST_TERM), array(array(self::ST_CLOSEDINT_RQ_START, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_CLOSEDINT_RQ_FIRST_TERM),
array(self::ST_CLOSEDINT_RQ_FIRST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_TO_LEXEME, self::ST_CLOSEDINT_RQ_TO_TERM), array(self::ST_CLOSEDINT_RQ_FIRST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_TO_LEXEME, self::ST_CLOSEDINT_RQ_TO_TERM),
array(self::ST_CLOSEDINT_RQ_TO_TERM, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_CLOSEDINT_RQ_LAST_TERM), array(self::ST_CLOSEDINT_RQ_TO_TERM, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_CLOSEDINT_RQ_LAST_TERM),
array(self::ST_CLOSEDINT_RQ_LAST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_RANGE_INCL_END, self::ST_COMMON_QUERY_ELEMENT) array(self::ST_CLOSEDINT_RQ_LAST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_RANGE_INCL_END, self::ST_COMMON_QUERY_ELEMENT)
)); )
);
$this->addRules( $this->addRules(
array(array(self::ST_OPENEDINT_RQ_START, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_OPENEDINT_RQ_FIRST_TERM), array(array(self::ST_OPENEDINT_RQ_START, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_OPENEDINT_RQ_FIRST_TERM),
array(self::ST_OPENEDINT_RQ_FIRST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_TO_LEXEME, self::ST_OPENEDINT_RQ_TO_TERM), array(self::ST_OPENEDINT_RQ_FIRST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_TO_LEXEME, self::ST_OPENEDINT_RQ_TO_TERM),
array(self::ST_OPENEDINT_RQ_TO_TERM, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_OPENEDINT_RQ_LAST_TERM), array(self::ST_OPENEDINT_RQ_TO_TERM, Zend_Search_Lucene_Search_QueryToken::TT_WORD, self::ST_OPENEDINT_RQ_LAST_TERM),
array(self::ST_OPENEDINT_RQ_LAST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_RANGE_EXCL_END, self::ST_COMMON_QUERY_ELEMENT) array(self::ST_OPENEDINT_RQ_LAST_TERM, Zend_Search_Lucene_Search_QueryToken::TT_RANGE_EXCL_END, self::ST_COMMON_QUERY_ELEMENT)
)); )
);
@ -250,7 +265,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
$this->addEntryAction(self::ST_CLOSEDINT_RQ_LAST_TERM, $closedRQLastTermAction); $this->addEntryAction(self::ST_CLOSEDINT_RQ_LAST_TERM, $closedRQLastTermAction);
require_once 'Zend/Search/Lucene/Search/QueryLexer.php'; include_once 'Zend/Search/Lucene/Search/QueryLexer.php';
$this->_lexer = new Zend_Search_Lucene_Search_QueryLexer(); $this->_lexer = new Zend_Search_Lucene_Search_QueryLexer();
} }
@ -284,7 +299,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
*/ */
public static function getDefaultEncoding() public static function getDefaultEncoding()
{ {
return self::_getInstance()->_defaultEncoding; return self::_getInstance()->_defaultEncoding;
} }
/** /**
@ -323,6 +338,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
} }
/** /**
* Check 'suppress query parser exceptions' mode. * Check 'suppress query parser exceptions' mode.
*
* @return boolean * @return boolean
*/ */
public static function queryParsingExceptionsSuppressed() public static function queryParsingExceptionsSuppressed()
@ -334,7 +350,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
/** /**
* Escape keyword to force it to be parsed as one term * Escape keyword to force it to be parsed as one term
* *
* @param string $keyword * @param string $keyword
* @return string * @return string
*/ */
public static function escape($keyword) public static function escape($keyword)
@ -345,8 +361,8 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
/** /**
* Parses a query string * Parses a query string
* *
* @param string $strQuery * @param string $strQuery
* @param string $encoding * @param string $encoding
* @return Zend_Search_Lucene_Search_Query * @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException * @throws Zend_Search_Lucene_Search_QueryParserException
*/ */
@ -357,9 +373,9 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
// Reset FSM if previous parse operation didn't return it into a correct state // Reset FSM if previous parse operation didn't return it into a correct state
self::$_instance->reset(); self::$_instance->reset();
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
try { try {
require_once 'Zend/Search/Lucene/Search/QueryParserContext.php'; include_once 'Zend/Search/Lucene/Search/QueryParserContext.php';
self::$_instance->_encoding = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding; self::$_instance->_encoding = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding;
self::$_instance->_lastToken = null; self::$_instance->_lastToken = null;
@ -369,7 +385,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
// Empty query // Empty query
if (count(self::$_instance->_tokens) == 0) { if (count(self::$_instance->_tokens) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
@ -382,16 +398,16 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
self::$_instance->_lastToken = $token; self::$_instance->_lastToken = $token;
} catch (Exception $e) { } catch (Exception $e) {
if (strpos($e->getMessage(), 'There is no any rule for') !== false) { if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
throw new Zend_Search_Lucene_Search_QueryParserException( 'Syntax error at char position ' . $token->position . '.', 0, $e); throw new Zend_Search_Lucene_Search_QueryParserException('Syntax error at char position ' . $token->position . '.', 0, $e);
} }
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e); throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
} }
} }
if (count(self::$_instance->_contextStack) != 0) { if (count(self::$_instance->_contextStack) != 0) {
throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.' ); throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.');
} }
return self::$_instance->_context->getQuery(); return self::$_instance->_context->getQuery();
@ -399,12 +415,12 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
if (self::$_instance->_suppressQueryParsingExceptions) { if (self::$_instance->_suppressQueryParsingExceptions) {
$queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding); $queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding);
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php'; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$query = new Zend_Search_Lucene_Search_Query_MultiTerm(); $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ : $termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
null /* optional term */; null /* optional term */;
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
foreach ($queryTokens as $token) { foreach ($queryTokens as $token) {
$query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign); $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
} }
@ -412,7 +428,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
return $query; return $query;
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e); throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
} }
} }
@ -429,7 +445,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
*/ */
public function addTermEntry() public function addTermEntry()
{ {
require_once 'Zend/Search/Lucene/Search/QueryEntry/Term.php'; include_once 'Zend/Search/Lucene/Search/QueryEntry/Term.php';
$entry = new Zend_Search_Lucene_Search_QueryEntry_Term($this->_currentToken->text, $this->_context->getField()); $entry = new Zend_Search_Lucene_Search_QueryEntry_Term($this->_currentToken->text, $this->_context->getField());
$this->_context->addEntry($entry); $this->_context->addEntry($entry);
} }
@ -439,7 +455,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
*/ */
public function addPhraseEntry() public function addPhraseEntry()
{ {
require_once 'Zend/Search/Lucene/Search/QueryEntry/Phrase.php'; include_once 'Zend/Search/Lucene/Search/QueryEntry/Phrase.php';
$entry = new Zend_Search_Lucene_Search_QueryEntry_Phrase($this->_currentToken->text, $this->_context->getField()); $entry = new Zend_Search_Lucene_Search_QueryEntry_Phrase($this->_currentToken->text, $this->_context->getField());
$this->_context->addEntry($entry); $this->_context->addEntry($entry);
} }
@ -477,23 +493,23 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
public function processModifierParameter() public function processModifierParameter()
{ {
if ($this->_lastToken === null) { if ($this->_lastToken === null) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Lexeme modifier parameter must follow lexeme modifier. Char position 0.' ); throw new Zend_Search_Lucene_Search_QueryParserException('Lexeme modifier parameter must follow lexeme modifier. Char position 0.');
} }
switch ($this->_lastToken->type) { switch ($this->_lastToken->type) {
case Zend_Search_Lucene_Search_QueryToken::TT_FUZZY_PROX_MARK: case Zend_Search_Lucene_Search_QueryToken::TT_FUZZY_PROX_MARK:
$this->_context->processFuzzyProximityModifier($this->_currentToken->text); $this->_context->processFuzzyProximityModifier($this->_currentToken->text);
break; break;
case Zend_Search_Lucene_Search_QueryToken::TT_BOOSTING_MARK: case Zend_Search_Lucene_Search_QueryToken::TT_BOOSTING_MARK:
$this->_context->boost($this->_currentToken->text); $this->_context->boost($this->_currentToken->text);
break; break;
default: default:
// It's not a user input exception // It's not a user input exception
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Lexeme modifier parameter must follow lexeme modifier. Char position 0.' ); throw new Zend_Search_Lucene_Exception('Lexeme modifier parameter must follow lexeme modifier. Char position 0.');
} }
} }
@ -503,7 +519,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
*/ */
public function subqueryStart() public function subqueryStart()
{ {
require_once 'Zend/Search/Lucene/Search/QueryParserContext.php'; include_once 'Zend/Search/Lucene/Search/QueryParserContext.php';
$this->_contextStack[] = $this->_context; $this->_contextStack[] = $this->_context;
$this->_context = new Zend_Search_Lucene_Search_QueryParserContext($this->_encoding, $this->_context->getField()); $this->_context = new Zend_Search_Lucene_Search_QueryParserContext($this->_encoding, $this->_context->getField());
@ -515,14 +531,14 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
public function subqueryEnd() public function subqueryEnd()
{ {
if (count($this->_contextStack) == 0) { if (count($this->_contextStack) == 0) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing. Char position ' . $this->_currentToken->position . '.' ); throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing. Char position ' . $this->_currentToken->position . '.');
} }
$query = $this->_context->getQuery(); $query = $this->_context->getQuery();
$this->_context = array_pop($this->_contextStack); $this->_context = array_pop($this->_contextStack);
require_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php'; include_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php';
$this->_context->addEntry(new Zend_Search_Lucene_Search_QueryEntry_Subquery($query)); $this->_context->addEntry(new Zend_Search_Lucene_Search_QueryEntry_Subquery($query));
} }
@ -551,10 +567,10 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
{ {
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_rqFirstTerm, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_rqFirstTerm, $this->_encoding);
if (count($tokens) > 1) { if (count($tokens) > 1) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms'); throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
} else if (count($tokens) == 1) { } else if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$from = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField()); $from = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
} else { } else {
$from = null; $from = null;
@ -562,23 +578,23 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_currentToken->text, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_currentToken->text, $this->_encoding);
if (count($tokens) > 1) { if (count($tokens) > 1) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms'); throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
} else if (count($tokens) == 1) { } else if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$to = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField()); $to = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
} else { } else {
$to = null; $to = null;
} }
if ($from === null && $to === null) { if ($from === null && $to === null) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('At least one range query boundary term must be non-empty term'); throw new Zend_Search_Lucene_Search_QueryParserException('At least one range query boundary term must be non-empty term');
} }
require_once 'Zend/Search/Lucene/Search/Query/Range.php'; include_once 'Zend/Search/Lucene/Search/Query/Range.php';
$rangeQuery = new Zend_Search_Lucene_Search_Query_Range($from, $to, false); $rangeQuery = new Zend_Search_Lucene_Search_Query_Range($from, $to, false);
require_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php'; include_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php';
$entry = new Zend_Search_Lucene_Search_QueryEntry_Subquery($rangeQuery); $entry = new Zend_Search_Lucene_Search_QueryEntry_Subquery($rangeQuery);
$this->_context->addEntry($entry); $this->_context->addEntry($entry);
} }
@ -600,10 +616,10 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
{ {
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_rqFirstTerm, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_rqFirstTerm, $this->_encoding);
if (count($tokens) > 1) { if (count($tokens) > 1) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms'); throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
} else if (count($tokens) == 1) { } else if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$from = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField()); $from = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
} else { } else {
$from = null; $from = null;
@ -611,23 +627,23 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_currentToken->text, $this->_encoding); $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_currentToken->text, $this->_encoding);
if (count($tokens) > 1) { if (count($tokens) > 1) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms'); throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
} else if (count($tokens) == 1) { } else if (count($tokens) == 1) {
require_once 'Zend/Search/Lucene/Index/Term.php'; include_once 'Zend/Search/Lucene/Index/Term.php';
$to = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField()); $to = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
} else { } else {
$to = null; $to = null;
} }
if ($from === null && $to === null) { if ($from === null && $to === null) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('At least one range query boundary term must be non-empty term'); throw new Zend_Search_Lucene_Search_QueryParserException('At least one range query boundary term must be non-empty term');
} }
require_once 'Zend/Search/Lucene/Search/Query/Range.php'; include_once 'Zend/Search/Lucene/Search/Query/Range.php';
$rangeQuery = new Zend_Search_Lucene_Search_Query_Range($from, $to, true); $rangeQuery = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);
require_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php'; include_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php';
$entry = new Zend_Search_Lucene_Search_QueryEntry_Subquery($rangeQuery); $entry = new Zend_Search_Lucene_Search_QueryEntry_Subquery($rangeQuery);
$this->_context->addEntry($entry); $this->_context->addEntry($entry);
} }

View File

@ -20,7 +20,9 @@
* @version $Id: QueryParserContext.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: QueryParserContext.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Search_QueryToken */ /**
* Zend_Search_Lucene_Search_QueryToken
*/
require_once 'Zend/Search/Lucene/Search/QueryToken.php'; require_once 'Zend/Search/Lucene/Search/QueryToken.php';
@ -101,7 +103,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
/** /**
* Context object constructor * Context object constructor
* *
* @param string $encoding * @param string $encoding
* @param string|null $defaultField * @param string|null $defaultField
*/ */
public function __construct($encoding, $defaultField = null) public function __construct($encoding, $defaultField = null)
@ -135,13 +137,13 @@ class Zend_Search_Lucene_Search_QueryParserContext
/** /**
* Set sign for next entry * Set sign for next entry
* *
* @param integer $sign * @param integer $sign
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function setNextEntrySign($sign) public function setNextEntrySign($sign)
{ {
if ($this->_mode === self::GM_BOOLEAN) { if ($this->_mode === self::GM_BOOLEAN) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('It\'s not allowed to mix boolean and signs styles in the same subquery.'); throw new Zend_Search_Lucene_Search_QueryParserException('It\'s not allowed to mix boolean and signs styles in the same subquery.');
} }
@ -152,7 +154,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
} else if ($sign == Zend_Search_Lucene_Search_QueryToken::TT_PROHIBITED) { } else if ($sign == Zend_Search_Lucene_Search_QueryToken::TT_PROHIBITED) {
$this->_nextEntrySign = false; $this->_nextEntrySign = false;
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unrecognized sign type.'); throw new Zend_Search_Lucene_Exception('Unrecognized sign type.');
} }
} }
@ -185,7 +187,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
{ {
// Check, that modifier has came just after word or phrase // Check, that modifier has came just after word or phrase
if ($this->_nextEntryField !== null || $this->_nextEntrySign !== null) { if ($this->_nextEntryField !== null || $this->_nextEntrySign !== null) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('\'~\' modifier must follow word or phrase.'); throw new Zend_Search_Lucene_Search_QueryParserException('\'~\' modifier must follow word or phrase.');
} }
@ -193,7 +195,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
if (!$lastEntry instanceof Zend_Search_Lucene_Search_QueryEntry) { if (!$lastEntry instanceof Zend_Search_Lucene_Search_QueryEntry) {
// there are no entries or last entry is boolean operator // there are no entries or last entry is boolean operator
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('\'~\' modifier must follow word or phrase.'); throw new Zend_Search_Lucene_Search_QueryParserException('\'~\' modifier must follow word or phrase.');
} }
@ -211,7 +213,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
{ {
// Check, that modifier has came just after word or phrase // Check, that modifier has came just after word or phrase
if ($this->_nextEntryField !== null || $this->_nextEntrySign !== null) { if ($this->_nextEntryField !== null || $this->_nextEntrySign !== null) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('\'^\' modifier must follow word, phrase or subquery.'); throw new Zend_Search_Lucene_Search_QueryParserException('\'^\' modifier must follow word, phrase or subquery.');
} }
@ -219,7 +221,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
if (!$lastEntry instanceof Zend_Search_Lucene_Search_QueryEntry) { if (!$lastEntry instanceof Zend_Search_Lucene_Search_QueryEntry) {
// there are no entries or last entry is boolean operator // there are no entries or last entry is boolean operator
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('\'^\' modifier must follow word, phrase or subquery.'); throw new Zend_Search_Lucene_Search_QueryParserException('\'^\' modifier must follow word, phrase or subquery.');
} }
@ -236,7 +238,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
public function addLogicalOperator($operator) public function addLogicalOperator($operator)
{ {
if ($this->_mode === self::GM_SIGNS) { if ($this->_mode === self::GM_SIGNS) {
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('It\'s not allowed to mix boolean and signs styles in the same subquery.'); throw new Zend_Search_Lucene_Search_QueryParserException('It\'s not allowed to mix boolean and signs styles in the same subquery.');
} }
@ -254,10 +256,10 @@ class Zend_Search_Lucene_Search_QueryParserContext
*/ */
public function _signStyleExpressionQuery() public function _signStyleExpressionQuery()
{ {
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$query = new Zend_Search_Lucene_Search_Query_Boolean(); $query = new Zend_Search_Lucene_Search_Query_Boolean();
require_once 'Zend/Search/Lucene/Search/QueryParser.php'; include_once 'Zend/Search/Lucene/Search/QueryParser.php';
if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) { if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) {
$defaultSign = true; // required $defaultSign = true; // required
} else { } else {
@ -293,30 +295,30 @@ class Zend_Search_Lucene_Search_QueryParserContext
* one or more query entries * one or more query entries
*/ */
require_once 'Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php'; include_once 'Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php';
$expressionRecognizer = new Zend_Search_Lucene_Search_BooleanExpressionRecognizer(); $expressionRecognizer = new Zend_Search_Lucene_Search_BooleanExpressionRecognizer();
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
try { try {
foreach ($this->_entries as $entry) { foreach ($this->_entries as $entry) {
if ($entry instanceof Zend_Search_Lucene_Search_QueryEntry) { if ($entry instanceof Zend_Search_Lucene_Search_QueryEntry) {
$expressionRecognizer->processLiteral($entry); $expressionRecognizer->processLiteral($entry);
} else { } else {
switch ($entry) { switch ($entry) {
case Zend_Search_Lucene_Search_QueryToken::TT_AND_LEXEME: case Zend_Search_Lucene_Search_QueryToken::TT_AND_LEXEME:
$expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_AND_OPERATOR); $expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_AND_OPERATOR);
break; break;
case Zend_Search_Lucene_Search_QueryToken::TT_OR_LEXEME: case Zend_Search_Lucene_Search_QueryToken::TT_OR_LEXEME:
$expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_OR_OPERATOR); $expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_OR_OPERATOR);
break; break;
case Zend_Search_Lucene_Search_QueryToken::TT_NOT_LEXEME: case Zend_Search_Lucene_Search_QueryToken::TT_NOT_LEXEME:
$expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_NOT_OPERATOR); $expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_NOT_OPERATOR);
break; break;
default: default:
throw new Zend_Search_Lucene('Boolean expression error. Unknown operator type.'); throw new Zend_Search_Lucene('Boolean expression error. Unknown operator type.');
} }
} }
} }
@ -326,7 +328,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
// throw new Zend_Search_Lucene_Search_QueryParserException('Boolean expression error. Error message: \'' . // throw new Zend_Search_Lucene_Search_QueryParserException('Boolean expression error. Error message: \'' .
// $e->getMessage() . '\'.' ); // $e->getMessage() . '\'.' );
// It's query syntax error message and it should be user friendly. So FSM message is omitted // It's query syntax error message and it should be user friendly. So FSM message is omitted
require_once 'Zend/Search/Lucene/Search/QueryParserException.php'; include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Boolean expression error.', 0, $e); throw new Zend_Search_Lucene_Search_QueryParserException('Boolean expression error.', 0, $e);
} }
@ -353,7 +355,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
if (count($conjuction) == 1) { if (count($conjuction) == 1) {
$subqueries[] = $conjuction[0][0]->getQuery($this->_encoding); $subqueries[] = $conjuction[0][0]->getQuery($this->_encoding);
} else { } else {
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$subquery = new Zend_Search_Lucene_Search_Query_Boolean(); $subquery = new Zend_Search_Lucene_Search_Query_Boolean();
foreach ($conjuction as $conjuctionEntry) { foreach ($conjuction as $conjuctionEntry) {
@ -365,7 +367,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
} }
if (count($subqueries) == 0) { if (count($subqueries) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php'; include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant(); return new Zend_Search_Lucene_Search_Query_Insignificant();
} }
@ -374,7 +376,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
} }
require_once 'Zend/Search/Lucene/Search/Query/Boolean.php'; include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
$query = new Zend_Search_Lucene_Search_Query_Boolean(); $query = new Zend_Search_Lucene_Search_Query_Boolean();
foreach ($subqueries as $subquery) { foreach ($subqueries as $subquery) {

View File

@ -37,5 +37,7 @@ require_once 'Zend/Search/Lucene/Exception.php';
* Special exception type, which may be used to intercept wrong user input * Special exception type, which may be used to intercept wrong user input
*/ */
class Zend_Search_Lucene_Search_QueryParserException extends Zend_Search_Lucene_Exception class Zend_Search_Lucene_Search_QueryParserException extends Zend_Search_Lucene_Exception
{} {
}

View File

@ -128,98 +128,98 @@ class Zend_Search_Lucene_Search_QueryToken
$this->position = $position + 1; // Start from 1 $this->position = $position + 1; // Start from 1
switch ($tokenCategory) { switch ($tokenCategory) {
case self::TC_WORD: case self::TC_WORD:
if ( strtolower($tokenText) == 'and') { if (strtolower($tokenText) == 'and') {
$this->type = self::TT_AND_LEXEME; $this->type = self::TT_AND_LEXEME;
} else if (strtolower($tokenText) == 'or') { } else if (strtolower($tokenText) == 'or') {
$this->type = self::TT_OR_LEXEME; $this->type = self::TT_OR_LEXEME;
} else if (strtolower($tokenText) == 'not') { } else if (strtolower($tokenText) == 'not') {
$this->type = self::TT_NOT_LEXEME; $this->type = self::TT_NOT_LEXEME;
} else if (strtolower($tokenText) == 'to') { } else if (strtolower($tokenText) == 'to') {
$this->type = self::TT_TO_LEXEME; $this->type = self::TT_TO_LEXEME;
} else { } else {
$this->type = self::TT_WORD; $this->type = self::TT_WORD;
} }
break;
case self::TC_PHRASE:
$this->type = self::TT_PHRASE;
break;
case self::TC_NUMBER:
$this->type = self::TT_NUMBER;
break;
case self::TC_SYNTAX_ELEMENT:
switch ($tokenText) {
case ':':
$this->type = self::TT_FIELD_INDICATOR;
break; break;
case self::TC_PHRASE: case '+':
$this->type = self::TT_PHRASE; $this->type = self::TT_REQUIRED;
break; break;
case self::TC_NUMBER: case '-':
$this->type = self::TT_NUMBER; $this->type = self::TT_PROHIBITED;
break; break;
case self::TC_SYNTAX_ELEMENT: case '~':
switch ($tokenText) { $this->type = self::TT_FUZZY_PROX_MARK;
case ':':
$this->type = self::TT_FIELD_INDICATOR;
break;
case '+':
$this->type = self::TT_REQUIRED;
break;
case '-':
$this->type = self::TT_PROHIBITED;
break;
case '~':
$this->type = self::TT_FUZZY_PROX_MARK;
break;
case '^':
$this->type = self::TT_BOOSTING_MARK;
break;
case '[':
$this->type = self::TT_RANGE_INCL_START;
break;
case ']':
$this->type = self::TT_RANGE_INCL_END;
break;
case '{':
$this->type = self::TT_RANGE_EXCL_START;
break;
case '}':
$this->type = self::TT_RANGE_EXCL_END;
break;
case '(':
$this->type = self::TT_SUBQUERY_START;
break;
case ')':
$this->type = self::TT_SUBQUERY_END;
break;
case '!':
$this->type = self::TT_NOT_LEXEME;
break;
case '&&':
$this->type = self::TT_AND_LEXEME;
break;
case '||':
$this->type = self::TT_OR_LEXEME;
break;
default:
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unrecognized query syntax lexeme: \'' . $tokenText . '\'');
}
break; break;
case self::TC_NUMBER: case '^':
$this->type = self::TT_NUMBER; $this->type = self::TT_BOOSTING_MARK;
break;
case '[':
$this->type = self::TT_RANGE_INCL_START;
break;
case ']':
$this->type = self::TT_RANGE_INCL_END;
break;
case '{':
$this->type = self::TT_RANGE_EXCL_START;
break;
case '}':
$this->type = self::TT_RANGE_EXCL_END;
break;
case '(':
$this->type = self::TT_SUBQUERY_START;
break;
case ')':
$this->type = self::TT_SUBQUERY_END;
break;
case '!':
$this->type = self::TT_NOT_LEXEME;
break;
case '&&':
$this->type = self::TT_AND_LEXEME;
break;
case '||':
$this->type = self::TT_OR_LEXEME;
break;
default: default:
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unrecognized lexeme type: \'' . $tokenCategory . '\''); throw new Zend_Search_Lucene_Exception('Unrecognized query syntax lexeme: \'' . $tokenText . '\'');
}
break;
case self::TC_NUMBER:
$this->type = self::TT_NUMBER;
default:
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unrecognized lexeme type: \'' . $tokenCategory . '\'');
} }
} }
} }

View File

@ -322,7 +322,7 @@ abstract class Zend_Search_Lucene_Search_Similarity
public static function getDefault() public static function getDefault()
{ {
if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Search_Similarity) { if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Search_Similarity) {
require_once 'Zend/Search/Lucene/Search/Similarity/Default.php'; include_once 'Zend/Search/Lucene/Search/Similarity/Default.php';
self::$_defaultImpl = new Zend_Search_Lucene_Search_Similarity_Default(); self::$_defaultImpl = new Zend_Search_Lucene_Search_Similarity_Default();
} }
@ -350,8 +350,8 @@ abstract class Zend_Search_Lucene_Search_Similarity
* 'fieldName' of 'doc'. * 'fieldName' of 'doc'.
* Returns a normalization factor for hits on this field of this document * Returns a normalization factor for hits on this field of this document
* *
* @param string $fieldName * @param string $fieldName
* @param integer $numTokens * @param integer $numTokens
* @return float * @return float
*/ */
abstract public function lengthNorm($fieldName, $numTokens); abstract public function lengthNorm($fieldName, $numTokens);
@ -367,7 +367,7 @@ abstract class Zend_Search_Lucene_Search_Similarity
* sumOfSquaredWeights - the sum of the squares of query term weights * sumOfSquaredWeights - the sum of the squares of query term weights
* Returns a normalization factor for query weights * Returns a normalization factor for query weights
* *
* @param float $sumOfSquaredWeights * @param float $sumOfSquaredWeights
* @return float * @return float
*/ */
abstract public function queryNorm($sumOfSquaredWeights); abstract public function queryNorm($sumOfSquaredWeights);
@ -376,7 +376,7 @@ abstract class Zend_Search_Lucene_Search_Similarity
/** /**
* Decodes a normalization factor stored in an index. * Decodes a normalization factor stored in an index.
* *
* @param integer $byte * @param integer $byte
* @return float * @return float
*/ */
public static function decodeNorm($byte) public static function decodeNorm($byte)
@ -396,18 +396,18 @@ abstract class Zend_Search_Lucene_Search_Similarity
* small to represent are rounded up to the smallest positive representable * small to represent are rounded up to the smallest positive representable
* value. * value.
* *
* @param float $f * @param float $f
* @return integer * @return integer
*/ */
static function encodeNorm($f) static function encodeNorm($f)
{ {
return self::_floatToByte($f); return self::_floatToByte($f);
} }
/** /**
* Float to byte conversion * Float to byte conversion
* *
* @param integer $b * @param integer $b
* @return float * @return float
*/ */
private static function _floatToByte($f) private static function _floatToByte($f)
@ -435,8 +435,9 @@ abstract class Zend_Search_Lucene_Search_Similarity
} }
// round to closest value // round to closest value
if ($highIndex != 255 && if ($highIndex != 255
$f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f ) { && $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f
) {
return $highIndex + 1; return $highIndex + 1;
} else { } else {
return $highIndex; return $highIndex;
@ -458,7 +459,7 @@ abstract class Zend_Search_Lucene_Search_Similarity
* freq - the frequency of a term within a document * freq - the frequency of a term within a document
* Returns a score factor based on a term's within-document frequency * Returns a score factor based on a term's within-document frequency
* *
* @param float $freq * @param float $freq
* @return float * @return float
*/ */
abstract public function tf($freq); abstract public function tf($freq);
@ -476,7 +477,7 @@ abstract class Zend_Search_Lucene_Search_Similarity
* distance - the edit distance of this sloppy phrase match * distance - the edit distance of this sloppy phrase match
* Returns the frequency increment for this match * Returns the frequency increment for this match
* *
* @param integer $distance * @param integer $distance
* @return float * @return float
*/ */
abstract public function sloppyFreq($distance); abstract public function sloppyFreq($distance);
@ -492,8 +493,8 @@ abstract class Zend_Search_Lucene_Search_Similarity
* reader - reader the document collection being searched * reader - reader the document collection being searched
* Returns a score factor for the term * Returns a score factor for the term
* *
* @param mixed $input * @param mixed $input
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
* @return a score factor for the term * @return a score factor for the term
*/ */
public function idf($input, Zend_Search_Lucene_Interface $reader) public function idf($input, Zend_Search_Lucene_Interface $reader)
@ -523,8 +524,8 @@ abstract class Zend_Search_Lucene_Search_Similarity
* numDocs - the total number of documents in the collection * numDocs - the total number of documents in the collection
* Returns a score factor based on the term's document frequency * Returns a score factor based on the term's document frequency
* *
* @param integer $docFreq * @param integer $docFreq
* @param integer $numDocs * @param integer $numDocs
* @return float * @return float
*/ */
abstract public function idfFreq($docFreq, $numDocs); abstract public function idfFreq($docFreq, $numDocs);
@ -542,8 +543,8 @@ abstract class Zend_Search_Lucene_Search_Similarity
* maxOverlap - the total number of terms in the query * maxOverlap - the total number of terms in the query
* Returns a score factor based on term overlap with the query * Returns a score factor based on term overlap with the query
* *
* @param integer $overlap * @param integer $overlap
* @param integer $maxOverlap * @param integer $maxOverlap
* @return float * @return float
*/ */
abstract public function coord($overlap, $maxOverlap); abstract public function coord($overlap, $maxOverlap);

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Similarity */ /**
* Zend_Search_Lucene_Search_Similarity
*/
require_once 'Zend/Search/Lucene/Search/Similarity.php'; require_once 'Zend/Search/Lucene/Search/Similarity.php';
@ -38,8 +40,8 @@ class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Se
/** /**
* Implemented as '1/sqrt(numTerms)'. * Implemented as '1/sqrt(numTerms)'.
* *
* @param string $fieldName * @param string $fieldName
* @param integer $numTerms * @param integer $numTerms
* @return float * @return float
*/ */
public function lengthNorm($fieldName, $numTerms) public function lengthNorm($fieldName, $numTerms)
@ -54,7 +56,7 @@ class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Se
/** /**
* Implemented as '1/sqrt(sumOfSquaredWeights)'. * Implemented as '1/sqrt(sumOfSquaredWeights)'.
* *
* @param float $sumOfSquaredWeights * @param float $sumOfSquaredWeights
* @return float * @return float
*/ */
public function queryNorm($sumOfSquaredWeights) public function queryNorm($sumOfSquaredWeights)
@ -65,7 +67,7 @@ class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Se
/** /**
* Implemented as 'sqrt(freq)'. * Implemented as 'sqrt(freq)'.
* *
* @param float $freq * @param float $freq
* @return float * @return float
*/ */
public function tf($freq) public function tf($freq)
@ -76,7 +78,7 @@ class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Se
/** /**
* Implemented as '1/(distance + 1)'. * Implemented as '1/(distance + 1)'.
* *
* @param integer $distance * @param integer $distance
* @return float * @return float
*/ */
public function sloppyFreq($distance) public function sloppyFreq($distance)
@ -87,8 +89,8 @@ class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Se
/** /**
* Implemented as 'log(numDocs/(docFreq+1)) + 1'. * Implemented as 'log(numDocs/(docFreq+1)) + 1'.
* *
* @param integer $docFreq * @param integer $docFreq
* @param integer $numDocs * @param integer $numDocs
* @return float * @return float
*/ */
public function idfFreq($docFreq, $numDocs) public function idfFreq($docFreq, $numDocs)
@ -99,8 +101,8 @@ class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Se
/** /**
* Implemented as 'overlap/maxOverlap'. * Implemented as 'overlap/maxOverlap'.
* *
* @param integer $overlap * @param integer $overlap
* @param integer $maxOverlap * @param integer $maxOverlap
* @return float * @return float
*/ */
public function coord($overlap, $maxOverlap) public function coord($overlap, $maxOverlap)

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Weight */ /**
* Zend_Search_Lucene_Search_Weight
*/
require_once 'Zend/Search/Lucene/Search/Weight.php'; require_once 'Zend/Search/Lucene/Search/Weight.php';
@ -66,8 +68,9 @@ class Zend_Search_Lucene_Search_Weight_Boolean extends Zend_Search_Lucene_Search
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
*/ */
public function __construct(Zend_Search_Lucene_Search_Query $query, public function __construct(Zend_Search_Lucene_Search_Query $query,
Zend_Search_Lucene_Interface $reader) Zend_Search_Lucene_Interface $reader
{ ) {
$this->_query = $query; $this->_query = $query;
$this->_reader = $reader; $this->_reader = $reader;
$this->_weights = array(); $this->_weights = array();

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Weight */ /**
* Zend_Search_Lucene_Search_Weight
*/
require_once 'Zend/Search/Lucene/Search/Weight.php'; require_once 'Zend/Search/Lucene/Search/Weight.php';

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Weight */ /**
* Zend_Search_Lucene_Search_Weight
*/
require_once 'Zend/Search/Lucene/Search/Weight.php'; require_once 'Zend/Search/Lucene/Search/Weight.php';
@ -66,8 +68,9 @@ class Zend_Search_Lucene_Search_Weight_MultiTerm extends Zend_Search_Lucene_Sear
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
*/ */
public function __construct(Zend_Search_Lucene_Search_Query $query, public function __construct(Zend_Search_Lucene_Search_Query $query,
Zend_Search_Lucene_Interface $reader) Zend_Search_Lucene_Interface $reader
{ ) {
$this->_query = $query; $this->_query = $query;
$this->_reader = $reader; $this->_reader = $reader;
$this->_weights = array(); $this->_weights = array();
@ -76,7 +79,7 @@ class Zend_Search_Lucene_Search_Weight_MultiTerm extends Zend_Search_Lucene_Sear
foreach ($query->getTerms() as $id => $term) { foreach ($query->getTerms() as $id => $term) {
if ($signs === null || $signs[$id] === null || $signs[$id]) { if ($signs === null || $signs[$id] === null || $signs[$id]) {
require_once 'Zend/Search/Lucene/Search/Weight/Term.php'; include_once 'Zend/Search/Lucene/Search/Weight/Term.php';
$this->_weights[$id] = new Zend_Search_Lucene_Search_Weight_Term($term, $query, $reader); $this->_weights[$id] = new Zend_Search_Lucene_Search_Weight_Term($term, $query, $reader);
$query->setWeight($id, $this->_weights[$id]); $query->setWeight($id, $this->_weights[$id]);
} }

View File

@ -64,8 +64,9 @@ class Zend_Search_Lucene_Search_Weight_Phrase extends Zend_Search_Lucene_Search_
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
*/ */
public function __construct(Zend_Search_Lucene_Search_Query_Phrase $query, public function __construct(Zend_Search_Lucene_Search_Query_Phrase $query,
Zend_Search_Lucene_Interface $reader) Zend_Search_Lucene_Interface $reader
{ ) {
$this->_query = $query; $this->_query = $query;
$this->_reader = $reader; $this->_reader = $reader;
} }

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Search_Weight */ /**
* Zend_Search_Lucene_Search_Weight
*/
require_once 'Zend/Search/Lucene/Search/Weight.php'; require_once 'Zend/Search/Lucene/Search/Weight.php';
@ -79,9 +81,10 @@ class Zend_Search_Lucene_Search_Weight_Term extends Zend_Search_Lucene_Search_We
* @param Zend_Search_Lucene_Interface $reader * @param Zend_Search_Lucene_Interface $reader
*/ */
public function __construct(Zend_Search_Lucene_Index_Term $term, public function __construct(Zend_Search_Lucene_Index_Term $term,
Zend_Search_Lucene_Search_Query $query, Zend_Search_Lucene_Search_Query $query,
Zend_Search_Lucene_Interface $reader) Zend_Search_Lucene_Interface $reader
{ ) {
$this->_term = $term; $this->_term = $term;
$this->_query = $query; $this->_query = $query;
$this->_reader = $reader; $this->_reader = $reader;

View File

@ -48,7 +48,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Creates a new, empty file in the directory with the given $filename. * Creates a new, empty file in the directory with the given $filename.
* *
* @param string $filename * @param string $filename
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
*/ */
abstract public function createFile($filename); abstract public function createFile($filename);
@ -57,7 +57,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Removes an existing $filename in the directory. * Removes an existing $filename in the directory.
* *
* @param string $filename * @param string $filename
* @return void * @return void
*/ */
abstract public function deleteFile($filename); abstract public function deleteFile($filename);
@ -67,7 +67,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
* *
* Method is used to prevent 'too many open files' error * Method is used to prevent 'too many open files' error
* *
* @param string $filename * @param string $filename
* @return void * @return void
*/ */
abstract public function purgeFile($filename); abstract public function purgeFile($filename);
@ -75,7 +75,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Returns true if a file with the given $filename exists. * Returns true if a file with the given $filename exists.
* *
* @param string $filename * @param string $filename
* @return boolean * @return boolean
*/ */
abstract public function fileExists($filename); abstract public function fileExists($filename);
@ -84,7 +84,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Returns the length of a $filename in the directory. * Returns the length of a $filename in the directory.
* *
* @param string $filename * @param string $filename
* @return integer * @return integer
*/ */
abstract public function fileLength($filename); abstract public function fileLength($filename);
@ -93,7 +93,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Returns the UNIX timestamp $filename was last modified. * Returns the UNIX timestamp $filename was last modified.
* *
* @param string $filename * @param string $filename
* @return integer * @return integer
*/ */
abstract public function fileModified($filename); abstract public function fileModified($filename);
@ -102,8 +102,8 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Renames an existing file in the directory. * Renames an existing file in the directory.
* *
* @param string $from * @param string $from
* @param string $to * @param string $to
* @return void * @return void
*/ */
abstract public function renameFile($from, $to); abstract public function renameFile($from, $to);
@ -112,7 +112,7 @@ abstract class Zend_Search_Lucene_Storage_Directory
/** /**
* Sets the modified time of $filename to now. * Sets the modified time of $filename to now.
* *
* @param string $filename * @param string $filename
* @return void * @return void
*/ */
abstract public function touchFile($filename); abstract public function touchFile($filename);
@ -126,8 +126,8 @@ abstract class Zend_Search_Lucene_Storage_Directory
* Shared handler are good for short atomic requests. * Shared handler are good for short atomic requests.
* Non-shared handlers are useful for stream file reading (especial for compound files). * Non-shared handlers are useful for stream file reading (especial for compound files).
* *
* @param string $filename * @param string $filename
* @param boolean $shareHandler * @param boolean $shareHandler
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
*/ */
abstract public function getFileObject($filename, $shareHandler = true); abstract public function getFileObject($filename, $shareHandler = true);

View File

@ -21,7 +21,9 @@
*/ */
/** Zend_Search_Lucene_Storage_Directory */ /**
* Zend_Search_Lucene_Storage_Directory
*/
require_once 'Zend/Search/Lucene/Storage/Directory.php'; require_once 'Zend/Search/Lucene/Storage/Directory.php';
@ -47,7 +49,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
* Cache for Zend_Search_Lucene_Storage_File_Filesystem objects * Cache for Zend_Search_Lucene_Storage_File_Filesystem objects
* Array: filename => Zend_Search_Lucene_Storage_File object * Array: filename => Zend_Search_Lucene_Storage_File object
* *
* @var array * @var array
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
protected $_fileHandlers; protected $_fileHandlers;
@ -84,9 +86,9 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Utility function to recursive directory creation * Utility function to recursive directory creation
* *
* @param string $dir * @param string $dir
* @param integer $mode * @param integer $mode
* @param boolean $recursive * @param boolean $recursive
* @return boolean * @return boolean
*/ */
@ -109,18 +111,18 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
* Object constructor * Object constructor
* Checks if $path is a directory or tries to create it. * Checks if $path is a directory or tries to create it.
* *
* @param string $path * @param string $path
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function __construct($path) public function __construct($path)
{ {
if (!is_dir($path)) { if (!is_dir($path)) {
if (file_exists($path)) { if (file_exists($path)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Path exists, but it\'s not a directory'); throw new Zend_Search_Lucene_Exception('Path exists, but it\'s not a directory');
} else { } else {
if (!self::mkdirs($path)) { if (!self::mkdirs($path)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception("Can't create directory '$path'."); throw new Zend_Search_Lucene_Exception("Can't create directory '$path'.");
} }
} }
@ -154,11 +156,12 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
{ {
$result = array(); $result = array();
$dirContent = opendir( $this->_dirPath ); $dirContent = opendir($this->_dirPath);
while (($file = readdir($dirContent)) !== false) { while (($file = readdir($dirContent)) !== false) {
if (($file == '..')||($file == '.')) continue; if (($file == '..')||($file == '.')) { continue;
}
if( !is_dir($this->_dirPath . '/' . $file) ) { if(!is_dir($this->_dirPath . '/' . $file) ) {
$result[] = $file; $result[] = $file;
} }
} }
@ -170,7 +173,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Creates a new, empty file in the directory with the given $filename. * Creates a new, empty file in the directory with the given $filename.
* *
* @param string $filename * @param string $filename
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -180,7 +183,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
$this->_fileHandlers[$filename]->close(); $this->_fileHandlers[$filename]->close();
} }
unset($this->_fileHandlers[$filename]); unset($this->_fileHandlers[$filename]);
require_once 'Zend/Search/Lucene/Storage/File/Filesystem.php'; include_once 'Zend/Search/Lucene/Storage/File/Filesystem.php';
$this->_fileHandlers[$filename] = new Zend_Search_Lucene_Storage_File_Filesystem($this->_dirPath . '/' . $filename, 'w+b'); $this->_fileHandlers[$filename] = new Zend_Search_Lucene_Storage_File_Filesystem($this->_dirPath . '/' . $filename, 'w+b');
// Set file permissions, but don't care about any possible failures, since file may be already // Set file permissions, but don't care about any possible failures, since file may be already
@ -194,7 +197,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Removes an existing $filename in the directory. * Removes an existing $filename in the directory.
* *
* @param string $filename * @param string $filename
* @return void * @return void
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -209,7 +212,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
$trackErrors = ini_get('track_errors'); ini_set('track_errors', '1'); $trackErrors = ini_get('track_errors'); ini_set('track_errors', '1');
if (!@unlink($this->_dirPath . '/' . $filename)) { if (!@unlink($this->_dirPath . '/' . $filename)) {
ini_set('track_errors', $trackErrors); ini_set('track_errors', $trackErrors);
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Can\'t delete file: ' . $php_errormsg); throw new Zend_Search_Lucene_Exception('Can\'t delete file: ' . $php_errormsg);
} }
ini_set('track_errors', $trackErrors); ini_set('track_errors', $trackErrors);
@ -220,7 +223,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
* *
* Method is used to prevent 'too many open files' error * Method is used to prevent 'too many open files' error
* *
* @param string $filename * @param string $filename
* @return void * @return void
*/ */
public function purgeFile($filename) public function purgeFile($filename)
@ -235,7 +238,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Returns true if a file with the given $filename exists. * Returns true if a file with the given $filename exists.
* *
* @param string $filename * @param string $filename
* @return boolean * @return boolean
*/ */
public function fileExists($filename) public function fileExists($filename)
@ -248,12 +251,12 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Returns the length of a $filename in the directory. * Returns the length of a $filename in the directory.
* *
* @param string $filename * @param string $filename
* @return integer * @return integer
*/ */
public function fileLength($filename) public function fileLength($filename)
{ {
if (isset( $this->_fileHandlers[$filename] )) { if (isset($this->_fileHandlers[$filename])) {
return $this->_fileHandlers[$filename]->size(); return $this->_fileHandlers[$filename]->size();
} }
return filesize($this->_dirPath .'/'. $filename); return filesize($this->_dirPath .'/'. $filename);
@ -263,7 +266,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Returns the UNIX timestamp $filename was last modified. * Returns the UNIX timestamp $filename was last modified.
* *
* @param string $filename * @param string $filename
* @return integer * @return integer
*/ */
public function fileModified($filename) public function fileModified($filename)
@ -275,8 +278,8 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Renames an existing file in the directory. * Renames an existing file in the directory.
* *
* @param string $from * @param string $from
* @param string $to * @param string $to
* @return void * @return void
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
@ -296,7 +299,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
if (file_exists($this->_dirPath . '/' . $to)) { if (file_exists($this->_dirPath . '/' . $to)) {
if (!unlink($this->_dirPath . '/' . $to)) { if (!unlink($this->_dirPath . '/' . $to)) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Delete operation failed'); throw new Zend_Search_Lucene_Exception('Delete operation failed');
} }
} }
@ -307,7 +310,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
$success = @rename($this->_dirPath . '/' . $from, $this->_dirPath . '/' . $to); $success = @rename($this->_dirPath . '/' . $from, $this->_dirPath . '/' . $to);
if (!$success) { if (!$success) {
ini_set('track_errors', $trackErrors); ini_set('track_errors', $trackErrors);
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception($php_errormsg); throw new Zend_Search_Lucene_Exception($php_errormsg);
} }
@ -320,7 +323,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
/** /**
* Sets the modified time of $filename to now. * Sets the modified time of $filename to now.
* *
* @param string $filename * @param string $filename
* @return void * @return void
*/ */
public function touchFile($filename) public function touchFile($filename)
@ -337,20 +340,20 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
* Shared handler are good for short atomic requests. * Shared handler are good for short atomic requests.
* Non-shared handlers are useful for stream file reading (especial for compound files). * Non-shared handlers are useful for stream file reading (especial for compound files).
* *
* @param string $filename * @param string $filename
* @param boolean $shareHandler * @param boolean $shareHandler
* @return Zend_Search_Lucene_Storage_File * @return Zend_Search_Lucene_Storage_File
*/ */
public function getFileObject($filename, $shareHandler = true) public function getFileObject($filename, $shareHandler = true)
{ {
$fullFilename = $this->_dirPath . '/' . $filename; $fullFilename = $this->_dirPath . '/' . $filename;
require_once 'Zend/Search/Lucene/Storage/File/Filesystem.php'; include_once 'Zend/Search/Lucene/Storage/File/Filesystem.php';
if (!$shareHandler) { if (!$shareHandler) {
return new Zend_Search_Lucene_Storage_File_Filesystem($fullFilename); return new Zend_Search_Lucene_Storage_File_Filesystem($fullFilename);
} }
if (isset( $this->_fileHandlers[$filename] )) { if (isset($this->_fileHandlers[$filename])) {
$this->_fileHandlers[$filename]->seek(0); $this->_fileHandlers[$filename]->seek(0);
return $this->_fileHandlers[$filename]; return $this->_fileHandlers[$filename];
} }

View File

@ -33,7 +33,7 @@ abstract class Zend_Search_Lucene_Storage_File
* Reads $length number of bytes at the current position in the * Reads $length number of bytes at the current position in the
* file and advances the file pointer. * file and advances the file pointer.
* *
* @param integer $length * @param integer $length
* @return string * @return string
*/ */
abstract protected function _fread($length=1); abstract protected function _fread($length=1);
@ -51,8 +51,8 @@ abstract class Zend_Search_Lucene_Storage_File
* in offset.) * in offset.)
* Upon success, returns 0; otherwise, returns -1 * Upon success, returns 0; otherwise, returns -1
* *
* @param integer $offset * @param integer $offset
* @param integer $whence * @param integer $whence
* @return integer * @return integer
*/ */
abstract public function seek($offset, $whence=SEEK_SET); abstract public function seek($offset, $whence=SEEK_SET);
@ -77,7 +77,7 @@ abstract class Zend_Search_Lucene_Storage_File
* Writes $length number of bytes (all, if $length===null) to the end * Writes $length number of bytes (all, if $length===null) to the end
* of the file. * of the file.
* *
* @param string $data * @param string $data
* @param integer $length * @param integer $length
*/ */
abstract protected function _fwrite($data, $length=null); abstract protected function _fwrite($data, $length=null);
@ -87,7 +87,7 @@ abstract class Zend_Search_Lucene_Storage_File
* *
* Lock type may be a LOCK_SH (shared lock) or a LOCK_EX (exclusive lock) * Lock type may be a LOCK_SH (shared lock) or a LOCK_EX (exclusive lock)
* *
* @param integer $lockType * @param integer $lockType
* @return boolean * @return boolean
*/ */
abstract public function lock($lockType, $nonBlockinLock = false); abstract public function lock($lockType, $nonBlockinLock = false);
@ -122,7 +122,7 @@ abstract class Zend_Search_Lucene_Storage_File
* Read num bytes from the current position in the file * Read num bytes from the current position in the file
* and advances the file pointer. * and advances the file pointer.
* *
* @param integer $num * @param integer $num
* @return string * @return string
*/ */
public function readBytes($num) public function readBytes($num)
@ -134,7 +134,7 @@ abstract class Zend_Search_Lucene_Storage_File
* Writes num bytes of data (all, if $num===null) to the end * Writes num bytes of data (all, if $num===null) to the end
* of the string. * of the string.
* *
* @param string $data * @param string $data
* @param integer $num * @param integer $num
*/ */
public function writeBytes($data, $num=null) public function writeBytes($data, $num=null)
@ -168,10 +168,12 @@ abstract class Zend_Search_Lucene_Storage_File
public function writeInt($value) public function writeInt($value)
{ {
settype($value, 'integer'); settype($value, 'integer');
$this->_fwrite( chr($value>>24 & 0xFF) . $this->_fwrite(
chr($value>>24 & 0xFF) .
chr($value>>16 & 0xFF) . chr($value>>16 & 0xFF) .
chr($value>>8 & 0xFF) . chr($value>>8 & 0xFF) .
chr($value & 0xFF), 4 ); chr($value & 0xFF), 4
);
} }
@ -207,7 +209,7 @@ abstract class Zend_Search_Lucene_Storage_File
/** /**
* Writes long integer to the end of file * Writes long integer to the end of file
* *
* @param integer $value * @param integer $value
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function writeLong($value) public function writeLong($value)
@ -218,14 +220,16 @@ abstract class Zend_Search_Lucene_Storage_File
*/ */
if (PHP_INT_SIZE > 4) { if (PHP_INT_SIZE > 4) {
settype($value, 'integer'); settype($value, 'integer');
$this->_fwrite( chr($value>>56 & 0xFF) . $this->_fwrite(
chr($value>>56 & 0xFF) .
chr($value>>48 & 0xFF) . chr($value>>48 & 0xFF) .
chr($value>>40 & 0xFF) . chr($value>>40 & 0xFF) .
chr($value>>32 & 0xFF) . chr($value>>32 & 0xFF) .
chr($value>>24 & 0xFF) . chr($value>>24 & 0xFF) .
chr($value>>16 & 0xFF) . chr($value>>16 & 0xFF) .
chr($value>>8 & 0xFF) . chr($value>>8 & 0xFF) .
chr($value & 0xFF), 8 ); chr($value & 0xFF), 8
);
} else { } else {
$this->writeLong32Bit($value); $this->writeLong32Bit($value);
} }
@ -249,7 +253,7 @@ abstract class Zend_Search_Lucene_Storage_File
if ($wordHigh == (int)0xFFFFFFFF && ($wordLow & (int)0x80000000)) { if ($wordHigh == (int)0xFFFFFFFF && ($wordLow & (int)0x80000000)) {
return $wordLow; return $wordLow;
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.'); throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.');
} }
@ -273,13 +277,13 @@ abstract class Zend_Search_Lucene_Storage_File
/** /**
* Writes long integer to the end of file (32-bit platforms implementation) * Writes long integer to the end of file (32-bit platforms implementation)
* *
* @param integer|float $value * @param integer|float $value
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function writeLong32Bit($value) public function writeLong32Bit($value)
{ {
if ($value < (int)0x80000000) { if ($value < (int)0x80000000) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.'); throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.');
} }
@ -329,7 +333,7 @@ abstract class Zend_Search_Lucene_Storage_File
{ {
settype($value, 'integer'); settype($value, 'integer');
while ($value > 0x7F) { while ($value > 0x7F) {
$this->_fwrite(chr( ($value & 0x7F)|0x80 )); $this->_fwrite(chr(($value & 0x7F)|0x80));
$value >>= 7; $value >>= 7;
} }
$this->_fwrite(chr($value)); $this->_fwrite(chr($value));
@ -379,11 +383,12 @@ abstract class Zend_Search_Lucene_Storage_File
// Check for null character. Java2 encodes null character // Check for null character. Java2 encodes null character
// in two bytes. // in two bytes.
if (ord($str_val[$count]) == 0xC0 && if (ord($str_val[$count]) == 0xC0
ord($str_val[$count+1]) == 0x80 ) { && ord($str_val[$count+1]) == 0x80
) {
$str_val[$count] = 0; $str_val[$count] = 0;
$str_val = substr($str_val,0,$count+1) $str_val = substr($str_val, 0, $count+1)
. substr($str_val,$count+2); . substr($str_val, $count+2);
} }
$count += $addBytes; $count += $addBytes;
} }
@ -396,7 +401,7 @@ abstract class Zend_Search_Lucene_Storage_File
/** /**
* Writes a string to the end of file. * Writes a string to the end of file.
* *
* @param string $str * @param string $str
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function writeString($str) public function writeString($str)
@ -447,7 +452,7 @@ abstract class Zend_Search_Lucene_Storage_File
} }
if ($chars < 0) { if ($chars < 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Invalid UTF-8 string'); throw new Zend_Search_Lucene_Exception('Invalid UTF-8 string');
} }

View File

@ -20,7 +20,9 @@
* @version $Id: Filesystem.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Filesystem.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Storage_File */ /**
* Zend_Search_Lucene_Storage_File
*/
require_once 'Zend/Search/Lucene/Storage/File.php'; require_once 'Zend/Search/Lucene/Storage/File.php';
/** /**
@ -52,7 +54,7 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
if (strpos($mode, 'w') === false && !is_readable($filename)) { if (strpos($mode, 'w') === false && !is_readable($filename)) {
// opening for reading non-readable file // opening for reading non-readable file
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('File \'' . $filename . '\' is not readable.'); throw new Zend_Search_Lucene_Exception('File \'' . $filename . '\' is not readable.');
} }
@ -63,7 +65,7 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
if ($this->_fileHandle === false) { if ($this->_fileHandle === false) {
ini_set('track_errors', $trackErrors); ini_set('track_errors', $trackErrors);
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception($php_errormsg); throw new Zend_Search_Lucene_Exception($php_errormsg);
} }
@ -84,8 +86,8 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
* *
* Upon success, returns 0; otherwise, returns -1 * Upon success, returns 0; otherwise, returns -1
* *
* @param integer $offset * @param integer $offset
* @param integer $whence * @param integer $whence
* @return integer * @return integer
*/ */
public function seek($offset, $whence=SEEK_SET) public function seek($offset, $whence=SEEK_SET)
@ -137,7 +139,7 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
$position = ftell($this->_fileHandle); $position = ftell($this->_fileHandle);
fseek($this->_fileHandle, 0, SEEK_END); fseek($this->_fileHandle, 0, SEEK_END);
$size = ftell($this->_fileHandle); $size = ftell($this->_fileHandle);
fseek($this->_fileHandle,$position); fseek($this->_fileHandle, $position);
return $size; return $size;
} }
@ -145,7 +147,7 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
/** /**
* Read a $length bytes from the file and advance the file pointer. * Read a $length bytes from the file and advance the file pointer.
* *
* @param integer $length * @param integer $length
* @return string * @return string
*/ */
protected function _fread($length=1) protected function _fread($length=1)
@ -171,7 +173,7 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
* Writes $length number of bytes (all, if $length===null) to the end * Writes $length number of bytes (all, if $length===null) to the end
* of the file. * of the file.
* *
* @param string $data * @param string $data
* @param integer $length * @param integer $length
*/ */
protected function _fwrite($data, $length=null) protected function _fwrite($data, $length=null)
@ -188,8 +190,8 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
* *
* Lock type may be a LOCK_SH (shared lock) or a LOCK_EX (exclusive lock) * Lock type may be a LOCK_SH (shared lock) or a LOCK_EX (exclusive lock)
* *
* @param integer $lockType * @param integer $lockType
* @param boolean $nonBlockingLock * @param boolean $nonBlockingLock
* @return boolean * @return boolean
*/ */
public function lock($lockType, $nonBlockingLock = false) public function lock($lockType, $nonBlockingLock = false)

View File

@ -20,7 +20,9 @@
* @version $Id: Memory.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: Memory.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Storage_File */ /**
* Zend_Search_Lucene_Storage_File
*/
require_once 'Zend/Search/Lucene/Storage/File.php'; require_once 'Zend/Search/Lucene/Storage/File.php';
/** /**
@ -61,7 +63,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
* Reads $length number of bytes at the current position in the * Reads $length number of bytes at the current position in the
* file and advances the file pointer. * file and advances the file pointer.
* *
* @param integer $length * @param integer $length
* @return string * @return string
*/ */
protected function _fread($length = 1) protected function _fread($length = 1)
@ -84,28 +86,28 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
* in offset.) * in offset.)
* Upon success, returns 0; otherwise, returns -1 * Upon success, returns 0; otherwise, returns -1
* *
* @param integer $offset * @param integer $offset
* @param integer $whence * @param integer $whence
* @return integer * @return integer
*/ */
public function seek($offset, $whence=SEEK_SET) public function seek($offset, $whence=SEEK_SET)
{ {
switch ($whence) { switch ($whence) {
case SEEK_SET: case SEEK_SET:
$this->_position = $offset; $this->_position = $offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
$this->_position += $offset; $this->_position += $offset;
break; break;
case SEEK_END: case SEEK_END:
$this->_position = strlen($this->_data); $this->_position = strlen($this->_data);
$this->_position += $offset; $this->_position += $offset;
break; break;
default: default:
break; break;
} }
} }
@ -137,7 +139,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
* Writes $length number of bytes (all, if $length===null) to the end * Writes $length number of bytes (all, if $length===null) to the end
* of the file. * of the file.
* *
* @param string $data * @param string $data
* @param integer $length * @param integer $length
*/ */
protected function _fwrite($data, $length=null) protected function _fwrite($data, $length=null)
@ -159,7 +161,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
* *
* Lock type may be a LOCK_SH (shared lock) or a LOCK_EX (exclusive lock) * Lock type may be a LOCK_SH (shared lock) or a LOCK_EX (exclusive lock)
* *
* @param integer $lockType * @param integer $lockType
* @return boolean * @return boolean
*/ */
public function lock($lockType, $nonBlockinLock = false) public function lock($lockType, $nonBlockinLock = false)
@ -210,7 +212,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
* Read num bytes from the current position in the file * Read num bytes from the current position in the file
* and advances the file pointer. * and advances the file pointer.
* *
* @param integer $num * @param integer $num
* @return string * @return string
*/ */
public function readBytes($num) public function readBytes($num)
@ -225,7 +227,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
* Writes num bytes of data (all, if $num===null) to the end * Writes num bytes of data (all, if $num===null) to the end
* of the string. * of the string.
* *
* @param string $data * @param string $data
* @param integer $num * @param integer $num
*/ */
public function writeBytes($data, $num=null) public function writeBytes($data, $num=null)
@ -314,7 +316,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
/** /**
* Writes long integer to the end of file * Writes long integer to the end of file
* *
* @param integer $value * @param integer $value
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function writeLong($value) public function writeLong($value)
@ -361,7 +363,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
if ($wordHigh == (int)0xFFFFFFFF && ($wordLow & (int)0x80000000)) { if ($wordHigh == (int)0xFFFFFFFF && ($wordLow & (int)0x80000000)) {
return $wordLow; return $wordLow;
} else { } else {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.'); throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.');
} }
@ -385,13 +387,13 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
/** /**
* Writes long integer to the end of file (32-bit platforms implementation) * Writes long integer to the end of file (32-bit platforms implementation)
* *
* @param integer|float $value * @param integer|float $value
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function writeLong32Bit($value) public function writeLong32Bit($value)
{ {
if ($value < (int)0x80000000) { if ($value < (int)0x80000000) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.'); throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.');
} }
@ -443,7 +445,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
settype($value, 'integer'); settype($value, 'integer');
while ($value > 0x7F) { while ($value > 0x7F) {
$this->_data .= chr( ($value & 0x7F)|0x80 ); $this->_data .= chr(($value & 0x7F)|0x80);
$value >>= 7; $value >>= 7;
} }
$this->_data .= chr($value); $this->_data .= chr($value);
@ -497,11 +499,12 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
// Check for null character. Java2 encodes null character // Check for null character. Java2 encodes null character
// in two bytes. // in two bytes.
if (ord($str_val[$count]) == 0xC0 && if (ord($str_val[$count]) == 0xC0
ord($str_val[$count+1]) == 0x80 ) { && ord($str_val[$count+1]) == 0x80
) {
$str_val[$count] = 0; $str_val[$count] = 0;
$str_val = substr($str_val,0,$count+1) $str_val = substr($str_val, 0, $count+1)
. substr($str_val,$count+2); . substr($str_val, $count+2);
} }
$count += $addBytes; $count += $addBytes;
} }
@ -514,7 +517,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
/** /**
* Writes a string to the end of file. * Writes a string to the end of file.
* *
* @param string $str * @param string $str
* @throws Zend_Search_Lucene_Exception * @throws Zend_Search_Lucene_Exception
*/ */
public function writeString($str) public function writeString($str)
@ -568,7 +571,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
} }
if ($chars < 0) { if ($chars < 0) {
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Invalid UTF-8 string'); throw new Zend_Search_Lucene_Exception('Invalid UTF-8 string');
} }

View File

@ -20,7 +20,9 @@
* @version $Id: TermStreamsPriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $ * @version $Id: TermStreamsPriorityQueue.php 20096 2010-01-06 02:05:09Z bkarwin $
*/ */
/** Zend_Search_Lucene_Index_TermsStream_Interface */ /**
* Zend_Search_Lucene_Index_TermsStream_Interface
*/
require_once 'Zend/Search/Lucene/Index/TermsStream/Interface.php'; require_once 'Zend/Search/Lucene/Index/TermsStream/Interface.php';
@ -58,7 +60,7 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
/** /**
* Object constructor * Object constructor
* *
* @param array $termStreams array of term streams (Zend_Search_Lucene_Index_TermsStream_Interface objects) * @param array $termStreams array of term streams (Zend_Search_Lucene_Index_TermsStream_Interface objects)
*/ */
public function __construct(array $termStreams) public function __construct(array $termStreams)
{ {
@ -72,8 +74,10 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
*/ */
public function resetTermsStream() public function resetTermsStream()
{ {
/** Zend_Search_Lucene_Index_TermsPriorityQueue */ /**
require_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php'; * Zend_Search_Lucene_Index_TermsPriorityQueue
*/
include_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php';
$this->_termsStreamQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue(); $this->_termsStreamQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
@ -123,9 +127,9 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
public function nextTerm() public function nextTerm()
{ {
while (($termStream = $this->_termsStreamQueue->pop()) !== null) { while (($termStream = $this->_termsStreamQueue->pop()) !== null) {
if ($this->_termsStreamQueue->top() === null || if ($this->_termsStreamQueue->top() === null
$this->_termsStreamQueue->top()->currentTerm()->key() != || $this->_termsStreamQueue->top()->currentTerm()->key() != $termStream->currentTerm()->key()
$termStream->currentTerm()->key()) { ) {
// We got new term // We got new term
$this->_lastTerm = $termStream->currentTerm(); $this->_lastTerm = $termStream->currentTerm();