function testGetAllPages()
 {
     if (!DocumentationSearch::enabled()) {
         return;
     }
     DocumentationService::set_automatic_registration(false);
     DocumentationService::register('docs-search', BASE_PATH . '/sapphiredocs/tests/docs-search/');
     $search = DocumentationSearch::get_all_documentation_pages();
     $this->assertEquals(7, $search->Count(), '5 pages. 5 pages in entire folder');
 }
 public function description()
 {
     $viewer = new DocumentationViewer();
     if (!$viewer->canView()) {
         return Security::permissionFailure($this);
     }
     if (!Config::inst()->get('DocumentationSearch', 'enabled')) {
         return $this->httpError('404');
     }
     $data = DocumentationSearch::get_meta_data();
     $link = Director::absoluteBaseUrl() . ($data['SearchPageLink'] = Controller::join_links($viewer->Link(), 'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1'));
     $data['SearchPageAtom'] = $data['SearchPageLink'] . '&format=atom';
     return $this->customise(new ArrayData($data))->renderWith(array('OpenSearchDescription'));
 }
 /**
  * Past straight to results, display and encode the query.
  */
 public function getSearchResults()
 {
     $query = $this->getSearchQuery();
     $search = new DocumentationSearch();
     $search->setQuery($query);
     $search->setVersions($this->getSearchedVersions());
     $search->setModules($this->getSearchedEntities());
     $search->setOutputController($this->owner);
     return $search->renderResults();
 }
 /**
  * Performs the search against the documentation in the system
  * @param {string} $keywords Keywords to search for
  * @param {int} $startIndex Start index for pagination
  * @return {ArrayData} Array Data of information about the results
  * 
  * @see ICMSUserDocsSearchEngine::getSearchResults()
  */
 public function getSearchResults($keywords, $startIndex = 0, SS_HTTPRequest $request = null)
 {
     //Workaround to set the search index location
     Config::inst()->update('DocumentationSearch', 'index_location', self::config()->index_location);
     //Search the index
     $search = new DocumentationSearch();
     $search->setQuery($keywords);
     $search->setVersions(array());
     $search->setModules(array());
     $search->performSearch();
     return $search->getSearchResults($request);
 }
 function rebuildIndexes($quiet = false)
 {
     require_once BASE_PATH . '/sapphiredocs/thirdparty/markdown/markdown.php';
     require_once 'Zend/Search/Lucene.php';
     ini_set("memory_limit", -1);
     ini_set('max_execution_time', 0);
     // only rebuild the index if we have to. Check for either flush or the time write.lock.file
     // was last altered
     $lock = DocumentationSearch::get_index_location() . '/write.lock.file';
     $lockFileFresh = file_exists($lock) && filemtime($lock) > time() - 60 * 60 * 24;
     if ($lockFileFresh && !isset($_REQUEST['flush'])) {
         if (!$quiet) {
             echo "Index recently rebuilt. If you want to force reindex use ?flush=1";
         }
         return true;
     }
     try {
         $index = Zend_Search_Lucene::open(DocumentationSearch::get_index_location());
         $index->removeReference();
     } catch (Zend_Search_Lucene_Exception $e) {
         // user_error($e);
     }
     try {
         $index = Zend_Search_Lucene::create(DocumentationSearch::get_index_location());
     } catch (Zend_Search_Lucene_Exception $c) {
         user_error($c);
     }
     // includes registration
     $pages = DocumentationSearch::get_all_documentation_pages();
     if ($pages) {
         $count = 0;
         // iconv complains about all the markdown formatting
         // turn off notices while we parse
         $error = error_reporting();
         error_reporting('E_ALL ^ E_NOTICE');
         foreach ($pages as $page) {
             $count++;
             if (!is_dir($page->getPath())) {
                 $doc = new Zend_Search_Lucene_Document();
                 $content = $page->getMarkdown();
                 if ($content) {
                     $content = Markdown($content);
                 }
                 $doc->addField(Zend_Search_Lucene_Field::Text('content', $content));
                 $doc->addField($titleField = Zend_Search_Lucene_Field::Text('Title', $page->getTitle()));
                 $doc->addField($breadcrumbField = Zend_Search_Lucene_Field::Text('BreadcrumbTitle', $page->getBreadcrumbTitle()));
                 $doc->addField(Zend_Search_Lucene_Field::Keyword('Version', $page->getVersion()));
                 $doc->addField(Zend_Search_Lucene_Field::Keyword('Language', $page->getLang()));
                 $doc->addField(Zend_Search_Lucene_Field::Keyword('Link', $page->Link()));
                 // custom boosts
                 $titleField->boost = 1.5;
                 $breadcrumbField->boost = 1.5;
                 foreach (DocumentationSearch::$boost_by_path as $pathExpr => $boost) {
                     if (preg_match($pathExpr, $page->getRelativePath())) {
                         $doc->boost = $boost;
                     }
                 }
                 $index->addDocument($doc);
             }
             if (!$quiet) {
                 echo "adding " . $page->getPath() . "\n";
             }
         }
         error_reporting($error);
     }
     $index->commit();
     if (!$quiet) {
         echo "complete.";
     }
 }
Exemplo n.º 6
0
if (isset($_ENV['CLEARDB_DATABASE_URL'])) {
    global $databaseConfig;
    $parts = parse_url($_ENV['CLEARDB_DATABASE_URL']);
    $databaseConfig['type'] = 'MySQLDatabase';
    $databaseConfig['server'] = $parts['host'];
    $databaseConfig['username'] = $parts['user'];
    $databaseConfig['password'] = $parts['pass'];
    $databaseConfig['database'] = trim($parts['path'], '/');
} else {
    require_once 'conf/ConfigureFromEnv.php';
}
MySQLDatabase::set_connection_charset('utf8');
SSViewer::set_theme('docs');
Config::inst()->update('DocumentationManifest', 'automatic_registration', false);
Config::inst()->update('DocumentationViewer', 'link_base', '');
Config::inst()->update('DocumentationViewer', 'check_permission', false);
DocumentationViewer::set_edit_link('framework', 'https://github.com/silverstripe/silverstripe-framework/edit/%version%/docs/%lang%/%path%', array('rewritetrunktomaster' => true));
if (Director::isLive()) {
    ControllerExtension::$google_analytics_code = 'UA-84547-8';
}
DocumentationSearch::set_meta_data(array('ShortName' => 'SilverStripe Documentation', 'Description' => 'Documentation for SilverStripe CMS / Framework', 'Tags' => 'silverstripe sapphire php framework cms content management system'));
// Changelogs have heaps of phrases, but are rarely relevant for content searches
Config::inst()->update('DocumentationSearch', 'boost_by_path', array('/^changelog/' => 0.05));
// Set shared index (avoid issues with different temp paths between CLI and web users)
if (file_exists(BASE_PATH . '/.lucene-index')) {
    Config::inst()->update('DocumentationSearch', 'index_location', BASE_PATH . '/.lucene-index');
}
// Fix invalid character in iconv
// see http://stackoverflow.com/questions/4723135/invalid-characters-for-lucene-text-search
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
error_reporting(E_ALL);
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('userhelp');
if (@$_GET['db'] == "sqlite3") {
    global $databaseConfig;
    $databaseConfig['type'] = 'SQLite3Database';
}
DocumentationService::set_automatic_registration(false);
DocumentationService::enable_meta_comments();
DocumentationViewer::set_link_base('');
DocumentationViewer::$check_permission = false;
try {
    DocumentationService::register("framework", BASE_PATH . "/src/framework_master/docs/", 'trunk');
    DocumentationService::register("framework", BASE_PATH . "/src/framework_3.1/docs/", '3.1', false, true);
    DocumentationService::register("framework", BASE_PATH . "/src/framework_3.0/docs/", '3.0');
} catch (InvalidArgumentException $e) {
}
// Silence if path is not found (for CI environment)
DocumentationViewer::set_edit_link('framework', 'https://github.com/silverstripe/silverstripe-userhelp-content/edit/%version%/docs/%lang%/%path%', array('rewritetrunktomaster' => true));
Object::add_extension('Controller', 'ControllerExtension');
if (Director::isLive()) {
    ControllerExtension::$google_analytics_code = 'UA-84547-10';
}
// Validator::set_javascript_validation_handler('none');
DocumentationSearch::enable();
DocumentationSearch::set_meta_data(array('ShortName' => 'SilverStripe Userhelp', 'Description' => 'Userhelp for SilverStripe CMS / Framework', 'Tags' => 'silverstripe sapphire php framework cms content management system'));
// Set shared index (avoid issues with different temp paths between CLI and web users)
if (file_exists(BASE_PATH . '/.lucene-index')) {
    DocumentationSearch::set_index(BASE_PATH . '/.lucene-index');
}
 public function rebuildIndexes($quiet = false)
 {
     require_once 'Zend/Search/Lucene.php';
     ini_set("memory_limit", -1);
     ini_set('max_execution_time', 0);
     Filesystem::makeFolder(DocumentationSearch::get_index_location());
     // only rebuild the index if we have to. Check for either flush or the time write.lock.file
     // was last altered
     $lock = DocumentationSearch::get_index_location() . '/write.lock.file';
     $lockFileFresh = file_exists($lock) && filemtime($lock) > time() - 60 * 60 * 24;
     echo "Building index in " . DocumentationSearch::get_index_location() . PHP_EOL;
     if ($lockFileFresh && !isset($_REQUEST['flush'])) {
         if (!$quiet) {
             echo "Index recently rebuilt. If you want to force reindex use ?flush=1";
         }
         return true;
     }
     try {
         $index = Zend_Search_Lucene::open(DocumentationSearch::get_index_location());
         $index->removeReference();
     } catch (Zend_Search_Lucene_Exception $e) {
         user_error($e);
     }
     try {
         $index = Zend_Search_Lucene::create(DocumentationSearch::get_index_location());
     } catch (Zend_Search_Lucene_Exception $c) {
         user_error($c);
     }
     // includes registration
     $manifest = new DocumentationManifest(true);
     $pages = $manifest->getPages();
     if ($pages) {
         $count = 0;
         // iconv complains about all the markdown formatting
         // turn off notices while we parse
         if (!Director::is_cli()) {
             echo "<ul>";
         }
         foreach ($pages as $url => $record) {
             $count++;
             $page = $manifest->getPage($url);
             $doc = new Zend_Search_Lucene_Document();
             $error = error_reporting();
             error_reporting(E_ALL ^ E_NOTICE);
             $content = $page->getHTML();
             error_reporting($error);
             $doc->addField(Zend_Search_Lucene_Field::Text('content', $content));
             $doc->addField($titleField = Zend_Search_Lucene_Field::Text('Title', $page->getTitle()));
             $doc->addField($breadcrumbField = Zend_Search_Lucene_Field::Text('BreadcrumbTitle', $page->getBreadcrumbTitle()));
             $doc->addField(Zend_Search_Lucene_Field::Keyword('Version', $page->getEntity()->getVersion()));
             $doc->addField(Zend_Search_Lucene_Field::Keyword('Language', $page->getEntity()->getLanguage()));
             $doc->addField(Zend_Search_Lucene_Field::Keyword('Entity', $page->getEntity()));
             $doc->addField(Zend_Search_Lucene_Field::Keyword('Link', $page->Link()));
             // custom boosts
             $titleField->boost = 3;
             $breadcrumbField->boost = 1.5;
             $boost = Config::inst()->get('DocumentationSearch', 'boost_by_path');
             foreach ($boost as $pathExpr => $boost) {
                 if (preg_match($pathExpr, $page->getRelativePath())) {
                     $doc->boost = $boost;
                 }
             }
             error_reporting(E_ALL ^ E_NOTICE);
             $index->addDocument($doc);
             if (!$quiet) {
                 if (Director::is_cli()) {
                     echo " * adding " . $page->getPath() . "\n";
                 } else {
                     echo "<li>adding " . $page->getPath() . "</li>\n";
                 }
             }
         }
     }
     $index->commit();
     if (!$quiet) {
         echo "complete.";
     }
 }
 /**
  * Past straight to results, display and encode the query
  */
 function results($data, $form = false)
 {
     $query = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : false;
     if (!$query) {
         return $this->httpError('404');
     }
     $search = new DocumentationSearch();
     $search->setQuery($query);
     $search->setOutputController($this);
     return $search->renderResults();
 }