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

@ -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']);
@ -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,7 +370,8 @@ class DocumentationManifest
$this->pages = array(); $this->pages = array();
foreach ($grouped as $entity) { foreach ($grouped as $entity) {
uasort($entity, function ($a, $b) { uasort(
$entity, function ($a, $b) {
// ensure parent directories are first // ensure parent directories are first
$a['filepath'] = str_replace('index.md', '', $a['filepath']); $a['filepath'] = str_replace('index.md', '', $a['filepath']);
$b['filepath'] = str_replace('index.md', '', $b['filepath']); $b['filepath'] = str_replace('index.md', '', $b['filepath']);
@ -369,7 +385,8 @@ class DocumentationManifest
} }
return ($a['filepath'] < $b['filepath']) ? -1 : 1; return ($a['filepath'] < $b['filepath']) ? -1 : 1;
}); }
);
$this->pages = array_merge($this->pages, $entity); $this->pages = array_merge($this->pages, $entity);
} }
@ -395,11 +412,13 @@ class DocumentationManifest
*/ */
protected function stripLinkBase($link) protected function stripLinkBase($link)
{ {
return ltrim(str_replace( return ltrim(
str_replace(
Config::inst()->get('DocumentationViewer', 'link_base'), Config::inst()->get('DocumentationViewer', 'link_base'),
'', '',
$link $link
), '/'); ), '/'
);
} }
/** /**
@ -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(
new ArrayData(
array(
'Link' => $base->Link(), 'Link' => $base->Link(),
'Title' => $base->Title '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(
new ArrayData(
array(
'Link' => $progress, 'Link' => $progress,
'Title' => DocumentationHelper::clean_page_name($part) '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(
new ArrayData(
array(
'Link' => Controller::join_links($base, $url, '/'), 'Link' => Controller::join_links($base, $url, '/'),
'Title' => $page['title'], 'Title' => $page['title'],
'LinkingMode' => $mode, 'LinkingMode' => $mode,
'Summary' => $page['summary'], 'Summary' => $page['summary'],
'Children' => $children '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(
array(
'Title' => $check->getVersionTitle(),
'Version' => $check->getVersion(),
'Archived' => $check->getIsArchived(),
'Link' => $check->Link(), 'Link' => $check->Link(),
'LinkingMode' => ($same) ? 'current' : 'link', 'LinkingMode' => ($same) ? 'current' : 'link',
'IsStable' => $check->getIsStable() '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(
DocumentationHelper::normalizePath(
dirname($page->getPath()) 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(
str_replace(
BASE_PATH, '', Controller::join_links(
$page->getEntity()->getPath(), $page->getEntity()->getPath(),
$url $url
))); )
)
);
} else { } else {
$relativeUrl = rtrim($baselink, '/') . '/' . ltrim($url, '/'); $relativeUrl = rtrim($baselink, '/') . '/' . ltrim($url, '/');
} }
@ -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

@ -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);
} }
@ -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(
new ArrayData(
array(
'Message' => $message 'Message' => $message
)))->renderWith(array("{$class}_error", $class)); )
)
)->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(
new ArrayData(
array(
'Title' => $entity->getTitle(), 'Title' => $entity->getTitle(),
'Link' => $link, 'Link' => $link,
'LinkingMode' => $mode, 'LinkingMode' => $mode,
'DefaultEntity' => $entity->getIsDefaultEntity(), 'DefaultEntity' => $entity->getIsDefaultEntity(),
'Children' => $children '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(
new ArrayData(
array(
'Children' => $children 'Children' => $children
)))->renderWith('Includes/DocumentationPages'); )
)
)->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(
new ArrayData(
array(
'Link' => Controller::join_links($baseLink, $url), 'Link' => Controller::join_links($baseLink, $url),
'Title' => $page['title'], 'Title' => $page['title'],
'FirstLetter' => $first 'FirstLetter' => $first
))); )
)
);
} }
} }
@ -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,6 +753,7 @@ 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()
*/ */

View File

@ -1,14 +1,15 @@
<?php <?php
/**
* @package docsviewer
*/
class DocumentationViewerVersionWarning extends Extension
{
/** /**
* Check to see if the currently accessed version is out of date or perhaps a * Check to see if the currently accessed version is out of date or perhaps a
* future version rather than the stable edition. * future version rather than the stable edition.
* *
* @return false|ArrayData * @return false|ArrayData
*/ */
class DocumentationViewerVersionWarning extends Extension
{
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(
new ArrayData(
array(
'FutureRelease' => true, 'FutureRelease' => true,
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion()) 'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion())
))); )
)
);
} else { } else {
return $this->owner->customise(new ArrayData(array( return $this->owner->customise(
new ArrayData(
array(
'OutdatedRelease' => true, 'OutdatedRelease' => true,
'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion()) 'StableVersion' => DBField::create_field('HTMLText', $stable->getVersion())
))); )
)
);
} }
return false; return false;

View File

@ -11,7 +11,6 @@
* 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)
{ {
@ -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)
{ {
@ -263,8 +321,7 @@ 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);
} }
/** /**

View File

@ -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(
$titleParts, function ($val) {
if ($val) { if ($val) {
return $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(
'/',
array_map(
function ($a) {
return DocumentationHelper::clean_page_url($a); return DocumentationHelper::clean_page_url($a);
}, $url)); },
$url
)
);
$url = trim($url, '/') . '/'; $url = trim($url, '/') . '/';
@ -246,10 +261,12 @@ class DocumentationPage extends ViewableData
*/ */
public function Link($short = false) public function Link($short = false)
{ {
return ltrim(Controller::join_links( return ltrim(
Controller::join_links(
$this->entity->Link($short), $this->entity->Link($short),
$this->getRelativeLink() $this->getRelativeLink()
), '/'); ), '/'
);
} }
/** /**
@ -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";

View File

@ -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(
Zend_Search_Lucene_Field::Keyword(
'Version', $page->getEntity()->getVersion() 'Version', $page->getEntity()->getVersion()
)); )
);
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
Zend_Search_Lucene_Field::Keyword(
'Language', $page->getEntity()->getLanguage() 'Language', $page->getEntity()->getLanguage()
)); )
);
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
Zend_Search_Lucene_Field::Keyword(
'Entity', $page->getEntity() 'Entity', $page->getEntity()
)); )
);
$doc->addField(Zend_Search_Lucene_Field::Keyword( $doc->addField(
Zend_Search_Lucene_Field::Keyword(
'Link', $page->Link() 'Link', $page->Link()
)); )
);
// custom boosts // custom boosts
$titleField->boost = 3; $titleField->boost = 3;

View File

@ -1,26 +1,35 @@
;(function($) { ;(function($) {
$(document).ready(function() { $(document).ready(
function() {
// Open sidebar on mobile // Open sidebar on mobile
$('.menu-open').click(function(){ $('.menu-open').click(
function(){
$('#sidebar').removeClass('hide').addClass('open'); $('#sidebar').removeClass('hide').addClass('open');
return false; return false;
}); }
);
// Close sidebar on mobile // Close sidebar on mobile
$('.menu-close').click(function(){ $('.menu-close').click(
function(){
$('#sidebar').removeClass('open').addClass('hide'); $('#sidebar').removeClass('open').addClass('hide');
setTimeout(function() { setTimeout(
function() {
$('#sidebar').removeClass('hide'); $('#sidebar').removeClass('hide');
}, 500); }, 500
);
return false; return false;
}); }
);
// Close sidebar by hitting of ESC // Close sidebar by hitting of ESC
$(document).keyup(function(e) { $(document).keyup(
function(e) {
if (e.keyCode == 27) { if (e.keyCode == 27) {
$('#sidebar').removeClass('open'); $('#sidebar').removeClass('open');
} }
}); }
);
var switched = false; var switched = false;
@ -28,26 +37,32 @@
if (($(window).width() < 540) && !switched ) { if (($(window).width() < 540) && !switched ) {
switched = true; switched = true;
$("table").each(function(i, element) { $("table").each(
function(i, element) {
splitTable($(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(
function(i, element) {
unsplitTable($(element)); unsplitTable($(element));
}); }
);
} }
}; };
$(window).load(updateTables); $(window).load(updateTables);
$(window).on("redraw",function() { $(window).on(
"redraw",function() {
switched = false; switched = false;
updateTables(); updateTables();
}); // An event to listen for }
); // An event to listen for
$(window).on("resize", updateTables); $(window).on("resize", updateTables);
@ -77,24 +92,32 @@
tr_copy = copy.find('tr'), tr_copy = copy.find('tr'),
heights = []; heights = [];
tr.each(function (index) { tr.each(
function (index) {
var self = $(this), var self = $(this),
tx = self.find('th, td'); tx = self.find('th, td');
tx.each(function () { tx.each(
function () {
var height = $(this).outerHeight(true); var height = $(this).outerHeight(true);
heights[index] = heights[index] || 0; 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(
function (index) {
$(this).height(heights[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
@ -107,16 +130,20 @@
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(
function(i) {
var current = $(this); var current = $(this);
var tagName = current.prop("tagName"); var tagName = current.prop("tagName");
if(typeof tagName == "String") tagName = tagName.toLowerCase(); if(typeof tagName == "String") { tagName = tagName.toLowerCase();
}
itemCount++; itemCount++;
toc += '<li class="' + tagName + '"><a id="link' + i + '" href="'+ pageURL +'#' + $(this).attr('id') + '" title="' + current.html() + '">' + current.html() + '</a></li>'; 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>';
@ -137,47 +164,59 @@
} }
/** --------------------------------------------- /**
* ---------------------------------------------
* 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(
function() {
var link = '<a class="heading-anchor-link" title="Link to this section" href="'+ url + '#' + $(this).attr('id') + '">&para;</a>'; var link = '<a class="heading-anchor-link" title="Link to this section" href="'+ url + '#' + $(this).attr('id') + '">&para;</a>';
$(this).append(' ' + link); $(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(
function() {
$(this).addClass('hover'); $(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(
function() {
$(this).removeClass('hover'); $(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(
function() {
$("#Form_LanguageForm").submit(); $("#Form_LanguageForm").submit();
}); }
);
/** --------------------------------------------- /**
* ---------------------------------------------
* SYNTAX HIGHLIGHTER * SYNTAX HIGHLIGHTER
* *
* As the Markdown parser now uses the GFM structure (```yml) this does * As the Markdown parser now uses the GFM structure (```yml) this does
* not work with SyntaxHighlighter. The below translates the GFM output * not work with SyntaxHighlighter. The below translates the GFM output
* to one SyntaxHighter can use * to one SyntaxHighter can use
*/ */
$("pre").each(function(i, elem) { $("pre").each(
function(i, elem) {
var code = $(elem).find('code[class^=language]'); var code = $(elem).find('code[class^=language]');
if(code.length > 0) { if(code.length > 0) {
@ -185,8 +224,10 @@
$(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(
'File path',
DocumentationHelper::clean_page_name(
'00_file-path.md' '00_file-path.md'
)); )
);
} }
public function testCleanUrl() public function testCleanUrl()
{ {
$this->assertEquals("some_path", DocumentationHelper::clean_page_url( $this->assertEquals(
'some_path',
DocumentationHelper::clean_page_url(
'Some Path' 'Some Path'
)); )
);
$this->assertEquals("somefilepath", DocumentationHelper::clean_page_url( $this->assertEquals(
'somefilepath',
DocumentationHelper::clean_page_url(
'00_SomeFilePath.md' '00_SomeFilePath.md'
)); )
);
} }
public function testTrimSortNumber() public function testTrimSortNumber()
{ {
$this->assertEquals('file', DocumentationHelper::trim_sort_number( $this->assertEquals(
'file',
DocumentationHelper::trim_sort_number(
'0_file' '0_file'
)); )
);
$this->assertEquals('2.1', DocumentationHelper::trim_sort_number( $this->assertEquals(
'2.1',
DocumentationHelper::trim_sort_number(
'2.1' '2.1'
)); )
);
$this->assertEquals('dev/tasks/2.1', DocumentationHelper::trim_sort_number( $this->assertEquals(
'dev/tasks/2.1',
DocumentationHelper::trim_sort_number(
'dev/tasks/2.1' 'dev/tasks/2.1'
)); )
);
} }
public function testTrimExtension() public function testTrimExtension()
{ {
$this->assertEquals('file', DocumentationHelper::trim_extension_off( $this->assertEquals(
'file',
DocumentationHelper::trim_extension_off(
'file.md' 'file.md'
)); )
);
$this->assertEquals('dev/path/file', DocumentationHelper::trim_extension_off( $this->assertEquals(
'dev/path/file',
DocumentationHelper::trim_extension_off(
'dev/path/file.md' 'dev/path/file.md'
)); )
);
} }
public function testGetExtension() public function testGetExtension()
{ {
$this->assertEquals('md', DocumentationHelper::get_extension( $this->assertEquals(
'md',
DocumentationHelper::get_extension(
'file.md' 'file.md'
)); )
);
$this->assertEquals('md', DocumentationHelper::get_extension( $this->assertEquals(
'md',
DocumentationHelper::get_extension(
'dev/tasks/file.md' 'dev/tasks/file.md'
)); )
);
$this->assertEquals('txt', DocumentationHelper::get_extension( $this->assertEquals(
'txt',
DocumentationHelper::get_extension(
'dev/tasks/file.txt' 'dev/tasks/file.txt'
)); )
);
$this->assertNull(DocumentationHelper::get_extension( $this->assertNull(
DocumentationHelper::get_extension(
'doc_test/2.3' 'doc_test/2.3'
)); )
);
$this->assertNull(DocumentationHelper::get_extension( $this->assertNull(
DocumentationHelper::get_extension(
'dev/docs/en/doc_test/2.3/subfolder' '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(
'2.3/test/',
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs/en/subfolder/subsubfolder/subsubpage.md', DOCSVIEWER_PATH . '/tests/docs/en/subfolder/subsubfolder/subsubpage.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link); )->Link
);
// after sorting, 2 is shown. // after sorting, 2 is shown.
$this->assertContains('/intermediate/', $this->manifest->getNextPage( $this->assertContains(
'/intermediate/',
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs/en/sort/01-basic.md', DOCSVIEWER_PATH . '/tests/docs/en/sort/01-basic.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link); )->Link
);
// next gets the following URL // next gets the following URL
$this->assertContains('/test/', $this->manifest->getNextPage( $this->assertContains(
'/test/',
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/index.md', DOCSVIEWER_PATH . '/tests/docs-v2.4/en/index.md',
DOCSVIEWER_PATH . '/tests/docs-v2.4/en/' DOCSVIEWER_PATH . '/tests/docs-v2.4/en/'
)->Link); )->Link
);
// last folder in a entity does not leak // last folder in a entity does not leak
$this->assertNull($this->manifest->getNextPage( $this->assertNull(
$this->manifest->getNextPage(
DOCSVIEWER_PATH . '/tests/docs/en/test.md', DOCSVIEWER_PATH . '/tests/docs/en/test.md',
DOCSVIEWER_PATH . '/tests/docs/en/' 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(
'subfolder/subsubfolder/subsubpage',
$this->manifest->getPreviousPage(
DOCSVIEWER_PATH . '/tests/docs/en/test.md', DOCSVIEWER_PATH . '/tests/docs/en/test.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)->Link); )->Link
);
// does not leak between entities // does not leak between entities
$this->assertNull($this->manifest->getPreviousPage( $this->assertNull(
$this->manifest->getPreviousPage(
DOCSVIEWER_PATH . '/tests/docs/en/index.md', DOCSVIEWER_PATH . '/tests/docs/en/index.md',
DOCSVIEWER_PATH . '/tests/docs/en/' DOCSVIEWER_PATH . '/tests/docs/en/'
)); )
);
// does not leak between entities // does not leak between entities
$this->assertNull($this->manifest->getPreviousPage( $this->assertNull(
$this->manifest->getPreviousPage(
DOCSVIEWER_PATH . ' /tests/docs/en/index.md', DOCSVIEWER_PATH . ' /tests/docs/en/index.md',
DOCSVIEWER_PATH . '/tests/docs/en/' 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(
$expected,
$this->manifest->getChildrenFor(
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/', DOCSVIEWER_PATH . '/tests/docs-v3.0/en/',
DOCSVIEWER_PATH . '/tests/docs-v3.0/en/ChangeLog.md' 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(
'[parent image link](%s)', Controller::join_links(
Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/_images/image.png' Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/_images/image.png'
)), )
),
$result $result
); );

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

@ -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

@ -20,69 +20,113 @@
*/ */
/** 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';
@ -205,8 +249,10 @@ class Zend_Search_Lucene implements 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));
} }
@ -219,16 +265,22 @@ class Zend_Search_Lucene implements 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;
/** /**
@ -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
@ -350,10 +402,11 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/ */
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(
$this->_directory,
$segName, $segName,
$segSize); $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(
$this->_directory,
$segName, $segName,
$segSize, $segSize,
$delGen, $delGen,
$docStoreOptions, $docStoreOptions,
$hasSingleNormFile, $hasSingleNormFile,
$isCompound); $isCompound
);
} }
} }
@ -508,12 +565,12 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
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->_directory,
$this->_segmentInfos, $this->_segmentInfos,
$this->_formatVersion); $this->_formatVersion
);
} }
return $this->_writer; return $this->_writer;
@ -708,7 +767,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
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.');
} }
@ -918,13 +977,13 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
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,8 +999,10 @@ 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);
@ -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(
$scores, SORT_DESC, SORT_NUMERIC,
$ids, SORT_ASC, SORT_NUMERIC, $ids, SORT_ASC, SORT_NUMERIC,
$hits); $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];
@ -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(
$fieldInfo->name,
$fdtFile->readString(), $fdtFile->readString(),
'UTF-8', 'UTF-8',
true, true,
$fieldInfo->isIndexed, $fieldInfo->isIndexed,
$bits & 1 ); $bits & 1
);
} else { // Binary data } else { // Binary data
$field = new Zend_Search_Lucene_Field($fieldInfo->name, $field = new Zend_Search_Lucene_Field(
$fieldInfo->name,
$fdtFile->readBinary(), $fdtFile->readBinary(),
'', '',
true, true,
$fieldInfo->isIndexed, $fieldInfo->isIndexed,
$bits & 1, $bits & 1,
true ); true
);
} }
$doc->addField($field); $doc->addField($field);
@ -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();
} }
@ -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';
} }
@ -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';

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(
substr(
$this->_input,
$this->_bytePosition, $this->_bytePosition,
$binStartPos - $this->_bytePosition), $binStartPos - $this->_bytePosition
'UTF-8'); ),
'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(
substr(
$this->_input,
$this->_bytePosition, $this->_bytePosition,
$binStartPos - $this->_bytePosition), $binStartPos - $this->_bytePosition
'UTF-8'); ),
'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';

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';
@ -48,7 +50,8 @@ class Zend_Search_Lucene_Analysis_TokenFilter_LowerCase extends Zend_Search_Luce
$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.');
} }
} }
@ -60,7 +62,8 @@ class Zend_Search_Lucene_Analysis_TokenFilter_LowerCaseUtf8 extends Zend_Search_
$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;
@ -48,7 +51,8 @@ class Zend_Search_Lucene_Analysis_TokenFilter_ShortWords extends Zend_Search_Luc
* *
* @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;
} }
@ -58,7 +62,8 @@ class Zend_Search_Lucene_Analysis_TokenFilter_ShortWords extends Zend_Search_Luc
* @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,7 +52,8 @@ 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);
} }
@ -59,7 +63,8 @@ class Zend_Search_Lucene_Analysis_TokenFilter_StopWords extends Zend_Search_Luce
* @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 {
@ -76,14 +81,15 @@ class Zend_Search_Lucene_Analysis_TokenFilter_StopWords extends Zend_Search_Luce
* @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)) {
@ -93,7 +99,7 @@ class Zend_Search_Lucene_Analysis_TokenFilter_StopWords extends Zend_Search_Luce
} }
} }
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';
@ -100,7 +102,7 @@ class Zend_Search_Lucene_Document
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];

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
* *
@ -47,9 +50,10 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
* @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(
dirname($rel['Target'])
. '/' . '/'
. basename($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');
@ -140,9 +148,10 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
* @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

@ -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
@ -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(
Zend_Search_Lucene_Field::Text(
$metaNode->getAttribute('name'),
$metaNode->getAttribute('content'), $metaNode->getAttribute('content'),
'UTF-8')); 'UTF-8'
)
);
} }
$docBody = ''; $docBody = '';
@ -160,16 +172,16 @@ 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;
} }
@ -285,8 +297,10 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
*/ */
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);
@ -406,15 +424,17 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
* *
* @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';
@ -112,12 +114,14 @@ abstract class Zend_Search_Lucene_Document_OpenXml extends Zend_Search_Lucene_Do
* @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';
/** /**
@ -73,7 +75,7 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
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,7 +92,7 @@ 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);
@ -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'));
} }
} }

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';
/** /**
@ -80,7 +82,7 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
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,7 +99,7 @@ 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);
@ -189,9 +191,10 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
// Check for numeric values // Check for numeric values
if (is_numeric($value) && $dataType != 's') { if (is_numeric($value) && $dataType != 's') {
if ($value == (int)$value) $value = (int)$value; if ($value == (int)$value) { $value = (int)$value;
elseif ($value == (float)$value) $value = (float)$value; } elseif ($value == (float)$value) { $value = (float)$value;
elseif ($value == (double)$value) $value = (double)$value; } elseif ($value == (double)$value) { $value = (double)$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'));
} }
} }
@ -235,7 +237,8 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
* @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)) {

View File

@ -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

@ -19,7 +19,9 @@
* @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';
/** /**
@ -177,7 +179,7 @@ abstract class Zend_Search_Lucene_FSM
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.');
} }
@ -248,15 +250,15 @@ abstract class Zend_Search_Lucene_FSM
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.');
} }
@ -288,7 +290,7 @@ abstract class Zend_Search_Lucene_FSM
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. ').');
} }
@ -310,7 +312,7 @@ abstract class Zend_Search_Lucene_FSM
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. ').');
} }
@ -333,11 +335,11 @@ abstract class Zend_Search_Lucene_FSM
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. ').');
} }
@ -363,11 +365,11 @@ abstract class Zend_Search_Lucene_FSM
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. ').');
} }
@ -391,11 +393,11 @@ abstract class Zend_Search_Lucene_FSM
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

@ -23,7 +23,6 @@
/** /**
* 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)

View File

@ -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
@ -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,12 +74,13 @@ 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');
} }
@ -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,8 +150,9 @@ 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);
@ -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';
@ -82,8 +84,10 @@ class Zend_Search_Lucene_Index_SegmentMerger
*/ */
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(
$fieldInfo->name,
$fdtFile->readString(), $fdtFile->readString(),
'UTF-8', 'UTF-8',
true, true,
$fieldInfo->isIndexed, $fieldInfo->isIndexed,
$bits & 1 ); $bits & 1
);
} else { // Binary data } else { // Binary data
$storedFields[] = $storedFields[] =
new Zend_Search_Lucene_Field($fieldInfo->name, new Zend_Search_Lucene_Field(
$fieldInfo->name,
$fdtFile->readBinary(), $fdtFile->readBinary(),
'', '',
true, true,
$fieldInfo->isIndexed, $fieldInfo->isIndexed,
$bits & 1, $bits & 1,
true); 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';
/** /**
@ -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->name,
$field->isIndexed, $field->isIndexed,
$fieldNumber, $fieldNumber,
$field->storeTermVector); $field->storeTermVector
);
return $fieldNumber; return $fieldNumber;
} else { } else {
@ -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->name,
$fieldInfo->isIndexed, $fieldInfo->isIndexed,
$fieldNumber, $fieldNumber,
$fieldInfo->storeTermVector); $fieldInfo->storeTermVector
);
return $fieldNumber; return $fieldNumber;
} else { } else {
@ -288,7 +298,8 @@ 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 */ |
@ -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
@ -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);
@ -513,8 +530,9 @@ abstract class Zend_Search_Lucene_Index_SegmentWriter
*/ */
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';
/** /**
@ -71,8 +73,10 @@ class Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter extends Zend_Search_
*/ */
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,8 +182,10 @@ 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])) {
@ -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->_directory,
$this->_name, $this->_name,
$this->_docCount, $this->_docCount,
-1, -1,
null, null,
true, 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';
/** /**
@ -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->_directory,
$this->_name, $this->_name,
$this->_docCount, $this->_docCount,
-1, -1,
null, null,
true, true,
true); true
);
} }
} }

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';
/** /**

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';
@ -169,10 +171,11 @@ class Zend_Search_Lucene_Index_Writer
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);
} }
} }
@ -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(
$this->_directory,
$segName, $segName,
$segSize, $segSize,
$delGen, $delGen,
$docStoreOptions, $docStoreOptions,
$hasSingleNormFile, $hasSingleNormFile,
$isCompound); $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(
$filesTypes, SORT_ASC, SORT_NUMERIC,
$filesNumbers, SORT_ASC, SORT_NUMERIC, $filesNumbers, SORT_ASC, SORT_NUMERIC,
$filesToDelete, SORT_ASC, SORT_STRING); $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);
} }

View File

@ -20,19 +20,29 @@
*/ */
/** 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';

View File

@ -19,10 +19,14 @@
* @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';
/** /**
@ -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;
@ -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;
@ -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;

View File

@ -20,7 +20,9 @@
*/ */
/** Zend_Search_Lucene_Interface */ /**
* Zend_Search_Lucene_Interface
*/
require_once 'Zend/Search/Lucene/Interface.php'; require_once 'Zend/Search/Lucene/Interface.php';
/** /**
@ -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.');
} }
} }
@ -83,7 +85,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
*/ */
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");
} }
@ -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");
} }
@ -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.');
} }
} }
@ -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);
} }
@ -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.');
} }
@ -557,7 +561,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
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');
} }
@ -593,7 +597,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
*/ */
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');
} }
@ -609,7 +613,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
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');
} }
@ -647,7 +651,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
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');
} }
@ -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.');
} }
} }
@ -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.');
} }
@ -799,7 +803,7 @@ class Zend_Search_Lucene_Interface_MultiSearcher implements Zend_Search_Lucene_I
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.');
} }
@ -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

@ -133,8 +133,8 @@ 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++;
} }

View File

@ -19,7 +19,9 @@
* @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';

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,7 +106,8 @@ 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,
@ -108,12 +115,14 @@ class Zend_Search_Lucene_Search_BooleanExpressionRecognizer extends Zend_Search_
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

View File

@ -186,12 +186,14 @@ abstract class Zend_Search_Lucene_Search_Query
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);
@ -212,15 +214,17 @@ abstract class Zend_Search_Lucene_Search_Query
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';
@ -114,7 +116,8 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
* @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();
@ -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;
@ -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();
} }
@ -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
@ -471,7 +478,7 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
*/ */
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(
$resVectorsSizes, SORT_ASC, SORT_NUMERIC,
$resVectorsIds, SORT_ASC, SORT_NUMERIC, $resVectorsIds, SORT_ASC, SORT_NUMERIC,
$resVectors); $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(
$requiredVectorsSizes, SORT_ASC, SORT_NUMERIC,
$requiredVectorsIds, SORT_ASC, SORT_NUMERIC, $requiredVectorsIds, SORT_ASC, SORT_NUMERIC,
$requiredVectors); $requiredVectors
);
$required = null; $required = null;
foreach ($requiredVectors as $nextResVector) { foreach ($requiredVectors as $nextResVector) {
@ -612,8 +623,10 @@ class Zend_Search_Lucene_Search_Query_Boolean extends Zend_Search_Lucene_Search_
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;
@ -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();
} }

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';
@ -65,7 +67,7 @@ class Zend_Search_Lucene_Search_Query_Empty extends Zend_Search_Lucene_Search_Qu
*/ */
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();
} }

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;
/** /**
@ -122,15 +126,15 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
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');
} }
@ -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));
@ -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.');
} }
} }
@ -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->_scores, SORT_DESC, SORT_NUMERIC,
$this->_termKeys, SORT_ASC, SORT_STRING, $this->_termKeys, SORT_ASC, SORT_STRING,
$this->_matches); $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]);
@ -337,7 +343,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
*/ */
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.');
} }
@ -366,7 +372,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
*/ */
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)');
} }
@ -381,7 +387,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
*/ */
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,7 +401,7 @@ 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)');
} }
@ -409,7 +415,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
*/ */
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)');
} }
@ -422,7 +428,7 @@ class Zend_Search_Lucene_Search_Query_Fuzzy extends Zend_Search_Lucene_Search_Qu
{ {
$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();

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';
@ -66,7 +68,7 @@ class Zend_Search_Lucene_Search_Query_Insignificant extends Zend_Search_Lucene_S
*/ */
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();
} }

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';
@ -106,7 +108,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
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.');
} }
@ -139,7 +141,8 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
* @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();
@ -163,7 +166,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
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;
@ -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();
} }
@ -308,7 +315,7 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
*/ */
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(
$docFreqs, SORT_ASC, SORT_NUMERIC,
$ids, SORT_ASC, SORT_NUMERIC, $ids, SORT_ASC, SORT_NUMERIC,
$this->_terms); $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(
$requiredVectorsSizes, SORT_ASC, SORT_NUMERIC,
$requiredVectorsIds, SORT_ASC, SORT_NUMERIC, $requiredVectorsIds, SORT_ASC, SORT_NUMERIC,
$requiredVectors); $requiredVectors
);
$required = null; $required = null;
foreach ($requiredVectors as $nextResVector) { foreach ($requiredVectors as $nextResVector) {
@ -466,8 +477,10 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
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;
@ -514,8 +527,8 @@ 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++;

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';
@ -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');
} }
} }
@ -162,11 +164,14 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
* @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;
@ -189,12 +194,12 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
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);
@ -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();
} }
@ -281,7 +286,7 @@ class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Q
*/ */
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;
} }
@ -302,9 +307,9 @@ 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;
} }
} }
@ -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;
} }
@ -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(
$resVectorsSizes, SORT_ASC, SORT_NUMERIC,
$resVectorsIds, SORT_ASC, SORT_NUMERIC, $resVectorsIds, SORT_ASC, SORT_NUMERIC,
$resVectors); $resVectors
);
foreach ($resVectors as $nextResVector) { foreach ($resVectors as $nextResVector) {
if($this->_resVector === null) { if($this->_resVector === null) {

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';
@ -58,7 +60,7 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
*/ */
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.');
} }
@ -70,7 +72,7 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
*/ */
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.');
} }
@ -83,7 +85,7 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
*/ */
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,7 +98,7 @@ 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.');
} }
@ -109,7 +111,7 @@ abstract class Zend_Search_Lucene_Search_Query_Preprocessing extends Zend_Search
*/ */
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';
@ -96,29 +98,32 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
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->_word,
$this->_encoding, $this->_encoding,
$fieldName, $fieldName,
$this->_minimumSimilarity); $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,7 +216,7 @@ 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');
} }
@ -220,14 +227,20 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy extends Zend_Search_Lu
*/ */
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';
/** /**
@ -131,11 +133,11 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
// 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->_phrase,
$this->_phraseEncoding, $this->_phraseEncoding,
$fieldName); $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);
@ -212,15 +216,21 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Phrase extends Zend_Search_L
*/ */
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';
@ -83,24 +85,26 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
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->_word,
$this->_encoding, $this->_encoding,
$fieldName); $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
@ -243,13 +249,19 @@ class Zend_Search_Lucene_Search_Query_Preprocessing_Term extends Zend_Search_Luc
*/ */
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';
@ -88,11 +90,11 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
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');
} }
@ -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) {
@ -244,7 +247,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
*/ */
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.');
} }
@ -273,7 +276,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
*/ */
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)');
} }
@ -288,7 +291,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
*/ */
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,7 +305,7 @@ 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)');
} }
@ -316,7 +319,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
*/ */
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)');
} }
@ -330,7 +333,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
$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';
@ -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);
@ -104,7 +106,7 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
{ {
// 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();
} }
@ -120,7 +122,7 @@ class Zend_Search_Lucene_Search_Query_Term extends Zend_Search_Lucene_Search_Que
*/ */
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;
} }

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';
@ -141,11 +143,13 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
$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) {
@ -220,7 +224,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
*/ */
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');
} }
@ -261,7 +265,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
*/ */
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)');
} }
@ -276,7 +280,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
*/ */
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,7 +294,7 @@ 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)');
} }
@ -304,7 +308,7 @@ class Zend_Search_Lucene_Search_Query_Wildcard extends Zend_Search_Lucene_Search
*/ */
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)');
} }
@ -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

@ -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';
/** /**
@ -97,13 +99,17 @@ class Zend_Search_Lucene_Search_QueryEntry_Phrase extends Zend_Search_Lucene_Sea
*/ */
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, */
include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Phrase.php';
$query = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase(
$this->_phrase,
$encoding, $encoding,
($this->_field !== null)? ($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';
/** /**
@ -57,7 +59,7 @@ class Zend_Search_Lucene_Search_QueryEntry_Subquery extends Zend_Search_Lucene_S
*/ */
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');
} }

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;
} }
} }
@ -102,9 +106,12 @@ class Zend_Search_Lucene_Search_QueryEntry_Term extends Zend_Search_Lucene_Searc
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, */
include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Fuzzy.php';
$query = new Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy(
$this->_term,
$encoding, $encoding,
($this->_field !== null)? ($this->_field !== null)?
iconv($encoding, 'UTF-8', $this->_field) : iconv($encoding, 'UTF-8', $this->_field) :
@ -116,9 +123,12 @@ class Zend_Search_Lucene_Search_QueryEntry_Term extends Zend_Search_Lucene_Searc
} }
/** 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, */
include_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Term.php';
$query = new Zend_Search_Lucene_Search_Query_Preprocessing_Term(
$this->_term,
$encoding, $encoding,
($this->_field !== null)? ($this->_field !== null)?
iconv($encoding, 'UTF-8', $this->_field) : iconv($encoding, 'UTF-8', $this->_field) :

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);
} }

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,
@ -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);
@ -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,9 +429,10 @@ 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());
} }
@ -402,13 +443,14 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$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());
} }
@ -426,7 +468,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$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
);
} }
@ -438,7 +481,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$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 = '';
} }
@ -451,7 +495,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$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 = '';
} }
@ -464,7 +509,8 @@ class Zend_Search_Lucene_Search_QueryLexer extends Zend_Search_Lucene_FSM
$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,7 +193,8 @@ 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),
@ -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();
} }
@ -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()
@ -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();
} }
@ -385,7 +401,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
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);
} }
} }
@ -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,7 +493,7 @@ 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.');
} }
@ -492,7 +508,7 @@ class Zend_Search_Lucene_Search_QueryParser extends Zend_Search_Lucene_FSM
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';
@ -141,7 +143,7 @@ class Zend_Search_Lucene_Search_QueryParserContext
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,10 +295,10 @@ 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) {
@ -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

@ -209,7 +209,7 @@ class Zend_Search_Lucene_Search_QueryToken
break; break;
default: default:
require_once 'Zend/Search/Lucene/Exception.php'; include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unrecognized query syntax lexeme: \'' . $tokenText . '\''); throw new Zend_Search_Lucene_Exception('Unrecognized query syntax lexeme: \'' . $tokenText . '\'');
} }
break; break;
@ -218,7 +218,7 @@ class Zend_Search_Lucene_Search_QueryToken
$this->type = self::TT_NUMBER; $this->type = self::TT_NUMBER;
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 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();
} }
@ -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;

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';

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';
@ -80,8 +82,9 @@ class Zend_Search_Lucene_Search_Weight_Term extends Zend_Search_Lucene_Search_We
*/ */
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

@ -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';
@ -116,11 +118,11 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
{ {
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'.");
} }
} }
@ -156,7 +158,8 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
$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;
@ -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
@ -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);
@ -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);
} }
@ -345,7 +348,7 @@ class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene
{ {
$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);
} }

View File

@ -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
);
} }
@ -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.');
} }
@ -279,7 +283,7 @@ abstract class Zend_Search_Lucene_Storage_File
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.');
} }
@ -379,8 +383,9 @@ 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);
@ -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);
} }

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';
/** /**
@ -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.');
} }
@ -391,7 +393,7 @@ class Zend_Search_Lucene_Storage_File_Memory extends Zend_Search_Lucene_Storage_
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.');
} }
@ -497,8 +499,9 @@ 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);
@ -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';
@ -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();