mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
Cherry picked changes from doc.silverstripe.org. FEATURE: added boost options to promoting or removing listings from the search. ENHANCEMENT: use a breadcrumb trail for search title to provide additional context
This commit is contained in:
parent
fab93f80df
commit
aa0297d52a
@ -101,6 +101,16 @@ class DocumentationPage extends ViewableData {
|
||||
return (is_dir($path)) ? rtrim($path, '/') . '/' : $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String - has to be plain text for open search compatibility.
|
||||
* @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
|
||||
*
|
||||
|
@ -32,6 +32,13 @@ class DocumentationSearch {
|
||||
*/
|
||||
private static $meta_data = array();
|
||||
|
||||
/**
|
||||
* @var Array Regular expression mapped to a "boost factor" for the searched document.
|
||||
* Defaults to 1.0, lower to decrease relevancy. Requires reindex.
|
||||
* Uses {@link DocumentationPage->getRelativePath()} for comparison.
|
||||
*/
|
||||
static $boost_by_path = array();
|
||||
|
||||
/**
|
||||
* @var DataObjectSet - Results
|
||||
*/
|
||||
@ -129,7 +136,12 @@ class DocumentationSearch {
|
||||
self::$enabled = true;
|
||||
|
||||
// include the zend search functionality
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)) . '/thirdparty/');
|
||||
set_include_path(
|
||||
dirname(dirname(__FILE__)) . '/thirdparty/'. PATH_SEPARATOR .
|
||||
get_include_path()
|
||||
);
|
||||
|
||||
require_once 'Zend/Search/Lucene.php';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,6 +225,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')),
|
||||
@ -350,7 +363,6 @@ class DocumentationSearch {
|
||||
$request = $this->outputController->getRequest();
|
||||
|
||||
$data = $this->getSearchResults($request);
|
||||
|
||||
$templates = array('DocumentationViewer_results', 'DocumentationViewer');
|
||||
|
||||
if($request->requestVar('format') && $request->requestVar('format') == "atom") {
|
||||
|
@ -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 {
|
||||
@ -73,14 +74,23 @@ class RebuildLuceneDocsIndex extends BuildTask {
|
||||
if($content) $content = Markdown($content);
|
||||
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('content', $content));
|
||||
$doc->addField(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(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->getTitle() ."\n\n";
|
||||
if(!$quiet) echo "adding ". $page->getPath() ."\n";
|
||||
}
|
||||
|
||||
error_reporting($error);
|
||||
|
@ -13,7 +13,7 @@
|
||||
<opensearch:Query role="request" searchTerms="$Query" startIndex="$StartResult" count="$PageLength"></opensearch:Query>
|
||||
<% control Results %>
|
||||
<entry>
|
||||
<title>$Title</title>
|
||||
<title><% if BreadcrumbTitle %>$BreadcrumbTitle<% else %>$Title<% end_if %></title>
|
||||
<link href="$Link">$Link</link>
|
||||
<id>urn:uuid:$ID</id>
|
||||
<content type="text">$Content.LimitCharacters(200)</content>
|
||||
|
Loading…
Reference in New Issue
Block a user