ENHANCEMENT Breadcrumbs for search results

git-svn-id: http://svn.silverstripe.com/projects/ss2doc/branches/v2@117890 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2011-04-10 20:09:14 +00:00
parent 30d805be8e
commit 4a849df06b
5 changed files with 32 additions and 4 deletions

View File

@ -101,6 +101,16 @@ class DocumentationPage extends ViewableData {
return (is_dir($path)) ? rtrim($path, '/') . '/' : $path;
}
/**
* @param String
* @return String
*/
function getBreadcrumbTitle($divider = ' » ') {
$pathParts = explode('/', $this->getRelativePath());
$titleParts = array_map(array('DocumentationService', 'clean_page_name'), $pathParts);
return implode($divider, $titleParts + array($this->getTitle()));
}
/**
* Returns the link for the web browser
*

View File

@ -157,9 +157,10 @@ class DocumentationSearch {
* Perform a search query on the index
*/
public function performSearch() {
require_once 'Zend/Search/Lucene.php';
try {
$index = Zend_Search_Lucene::open(self::get_index_location());
Zend_Search_Lucene::setResultSetLimit(200);
$this->results = $index->find($this->getQuery());
@ -213,6 +214,7 @@ class DocumentationSearch {
// do a simple markdown parse of the file
$obj = new ArrayData(array(
'Title' => DBField::create('Varchar', $doc->getFieldValue('Title')),
'BreadcrumbTitle' => DBField::create('HTMLText', $doc->getFieldValue('BreadcrumbTitle')),
'Link' => DBField::create('Varchar',$doc->getFieldValue('Link')),
'Language' => DBField::create('Varchar',$doc->getFieldValue('Language')),
'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')),

View File

@ -21,6 +21,7 @@ class RebuildLuceneDocsIndex extends BuildTask {
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);
@ -43,7 +44,7 @@ class RebuildLuceneDocsIndex extends BuildTask {
$index->removeReference();
}
catch (Zend_Search_Lucene_Exception $e) {
user_error($e);
// user_error($e);
}
try {
@ -74,13 +75,14 @@ class RebuildLuceneDocsIndex extends BuildTask {
$doc->addField(Zend_Search_Lucene_Field::Text('content', $content));
$doc->addField(Zend_Search_Lucene_Field::Text('Title', $page->getTitle()));
$doc->addField(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()));
$index->addDocument($doc);
}
if(!$quiet) echo "adding ". $page->getTitle() ."\n\n";
if(!$quiet) echo "adding ". $page->getPath() ."\n";
}
error_reporting($error);

View File

@ -5,7 +5,7 @@
<% if Results %>
<p>Showing page $ThisPage of $TotalPages</p>
<% control Results %>
<h2><a href="$Link">$Title</a></h2>
<h3><a href="$Link">$BreadcrumbTitle</a></h3>
<p>$Content.LimitCharacters(200)</p>
<% end_control %>

View File

@ -40,6 +40,20 @@ class DocumentationPageTest extends SapphireTest {
$this->assertStringEndsWith('versionlinks/en/1/test', $page->Link());
}
function testGetBreadcrumbTitle() {
$page = new DocumentationPage();
$page->setRelativePath('test.md');
$page->setEntity(new DocumentationEntity('mymodule', null, BASE_PATH . '/sapphiredocs/tests/docs/'));
$this->assertEquals('Test', $page->getBreadcrumbTitle());
$page = new DocumentationPage();
$page->setRelativePath('subfolder/subpage.md');
$page->setEntity(new DocumentationEntity('mymodule', null, BASE_PATH . '/sapphiredocs/tests/docs/'));
$this->assertEquals('Subfolder &raquo; Subpage', $page->getBreadcrumbTitle());
}
function testGetRelativePath() {
$page = new DocumentationPage();