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:
Ingo Schommer 2011-04-10 20:51:39 +00:00
parent f33c56d6ea
commit 9d9483056c
2 changed files with 17 additions and 2 deletions

View File

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

View File

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