mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 15:05:50 +00:00
ENHANCEMENT Custom document weighting by path support
git-svn-id: http://svn.silverstripe.com/projects/ss2doc/branches/v2@117892 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f33c56d6ea
commit
9d9483056c
@ -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
|
||||
*/
|
||||
|
@ -74,11 +74,19 @@ 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(Zend_Search_Lucene_Field::Text('BreadcrumbTitle', $page->getBreadcrumbTitle()));
|
||||
$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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user