Commit c4ffa2d3 authored by lphuberdeau's avatar lphuberdeau

[MOD] Disabling result highlight by default (extremely slow, as revealed in profiling)

parent cddfd0d4
......@@ -1809,6 +1809,7 @@ lib/core/Search/Query/Order.php -text
lib/core/Search/Query/WeightCalculator/Field.php -text
lib/core/Search/Query/WeightCalculator/Interface.php -text
lib/core/Search/ResultSet.php -text
lib/core/Search/ResultSet/SnippetHelper.php -text
lib/core/Search/Type/Factory/Direct.php -text
lib/core/Search/Type/Factory/Interface.php -text
lib/core/Search/Type/Factory/Lucene.php -text
......
......@@ -8,8 +8,9 @@
class Search_Index_Lucene implements Search_Index_Interface
{
private $lucene;
private $highlight = true;
function __construct($directory, $lang = 'en')
function __construct($directory, $lang = 'en', $highlight = true)
{
switch($lang) {
case 'en':
......@@ -25,6 +26,8 @@ class Search_Index_Lucene implements Search_Index_Interface
$this->lucene->setMaxBufferedDocs(100);
$this->lucene->setMaxMergeDocs(200);
$this->lucene->setMergeFactor(50);
$this->highlight = (bool) $highlight;
}
function addDocument(array $data)
......@@ -75,7 +78,11 @@ class Search_Index_Lucene implements Search_Index_Interface
$resultSet = new Search_ResultSet($result, count($hits), $resultStart, $resultCount);
$resultSet->setHighlightHelper(new Search_Index_Lucene_HighlightHelper($query));
if ($this->highlight) {
$resultSet->setHighlightHelper(new Search_Index_Lucene_HighlightHelper($query));
} else {
$resultSet->setHighlightHelper(new Search_ResultSet_SnippetHelper);
}
return $resultSet;
}
......@@ -235,7 +242,8 @@ class Search_Index_Lucene_HighlightHelper implements Zend_Filter_Interface
function filter($content)
{
$content = substr($content, 0, 240);
$snippetHelper = new Search_ResultSet_SnippetHelper;
$content = $snippetHelper->filter($content);
return trim(strip_tags($this->query->highlightMatches($content), '<b>'));
}
}
......
<?php
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
class Search_ResultSet_SnippetHelper implements Zend_Filter_Interface
{
private $length;
function __construct($length = 240)
{
$this->length = (int) 240;
}
function filter($content)
{
return substr($content, 0, $this->length);
}
}
......@@ -24,6 +24,12 @@ function prefs_unified_list()
'size' => 35,
'default' => 'temp/unified-index',
),
'unified_lucene_highlight' => array(
'name' => tra('Highlight results snippets'),
'description' => tra('Highlight the result snippet based on the search query. Enabling this option will impact performance, but improve user experience.'),
'type' => 'flag',
'default' => 'n',
),
'unified_incremental_update' => array(
'name' => tra('Incremental Index Update'),
'description' => tra('Update the index incrementally as the site content is modified. This may lead to lower performance and accuracy than processing the index on a periodic basis.'),
......
......@@ -219,7 +219,7 @@ class UnifiedSearchLib
global $prefs;
if ($prefs['unified_engine'] == 'lucene') {
$index = new Search_Index_Lucene($prefs['unified_lucene_location']);
$index = new Search_Index_Lucene($prefs['unified_lucene_location'], $prefs['language'], $prefs['unified_lucene_highlight'] == 'y');
return $index;
}
......
......@@ -26,6 +26,7 @@
{preference name="unified_engine"}
<div class="adminoptionboxchild unified_engine_childcontainer lucene">
{preference name="unified_lucene_location"}
{preference name="unified_lucene_highlight"}
</div>
{preference name=unified_field_weight}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment