_wildcardMinPrefix = Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength();
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
$this->_defaultPrefixLength = Zend_Search_Lucene_Search_Query_Fuzzy::getDefaultPrefixLength();
Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength(0);
}
public function tearDown()
{
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($this->_wildcardMinPrefix);
Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($this->_defaultPrefixLength);
}
public function testHtmlFragmentHighlightMatches()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('title:"The Right Way" AND text:go');
$highlightedHtmlFragment = $query->htmlFragmentHighlightMatches('Text highlighting using Zend_Search_Lucene is the right way to go!');
$this->assertEquals($highlightedHtmlFragment,
'Text highlighting using Zend_Search_Lucene is the right way to go!');
}
// public function testHtmlFragmentHighlightMatchesCyrillic()
// {
// $query = Zend_Search_Lucene_Search_QueryParser::parse('title:"некоторый текст" AND text:поехали');
//
// $highlightedHtmlFragment = $query->htmlFragmentHighlightMatches('Подсвечиваем некоторый текст с использованием Zend_Search_Lucene. Поехали!');
//
// $this->assertEquals($highlightedHtmlFragment,
// 'Text highlighting using Zend_Search_Lucene is the right way to go!');
// }
//
// public function testHtmlFragmentHighlightMatchesCyrillicWindows()
// {
// $query = Zend_Search_Lucene_Search_QueryParser::parse('title:"Некоторый текст" AND text:поехали');
//
// $highlightedHtmlFragment =
// $query->htmlFragmentHighlightMatches(iconv('UTF-8',
// 'Windows-1251',
// 'Подсвечиваем некоторый текст с использованием Zend_Search_Lucene. Поехали!'),
// 'Windows-1251');
//
// $this->assertEquals($highlightedHtmlFragment,
// 'Text highlighting using Zend_Search_Lucene is the right way to go!');
// }
public function testHighlightPhrasePlusTerm()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('title:"The Right Way" AND text:go');
$html = ''
. '
Page title'
. ''
. 'Text highlighting using Zend_Search_Lucene is the right way to go!'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'the') !== false);
$this->assertTrue(strpos($highlightedHTML, 'right') !== false);
$this->assertTrue(strpos($highlightedHTML, 'way') !== false);
$this->assertTrue(strpos($highlightedHTML, 'go') !== false);
}
public function testHighlightMultitermWithProhibitedTerms()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('+text +highlighting -using -right +go');
$html = ''
. 'Page title'
. ''
. 'Text highlighting using Zend_Search_Lucene is the right way to go!'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'Text') !== false);
$this->assertTrue(strpos($highlightedHTML, 'highlighting') !== false);
$this->assertTrue(strpos($highlightedHTML, 'using Zend_Search_Lucene is the right way to') !== false);
$this->assertTrue(strpos($highlightedHTML, 'go') !== false);
}
public function testHighlightWildcard1()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('te?t');
$html = ''
. 'Page title'
. ''
. 'Test of text highlighting using wildcard query with question mark. Testing...'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'Test') !== false);
$this->assertTrue(strpos($highlightedHTML, 'text') !== false);
// Check that 'Testing' word is not highlighted
$this->assertTrue(strpos($highlightedHTML, 'mark. Testing...') !== false);
}
public function testHighlightWildcard2()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('te?t*');
$html = ''
. 'Page title'
. ''
. 'Test of text highlighting using wildcard query with question mark. Testing...'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'Test') !== false);
$this->assertTrue(strpos($highlightedHTML, 'text') !== false);
// Check that 'Testing' word is also highlighted
$this->assertTrue(strpos($highlightedHTML, 'Testing') !== false);
}
public function testHighlightFuzzy1()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('test~');
$html = ''
. 'Page title'
. ''
. 'Test of text fuzzy search terms highlighting. '
. 'Words: test, text, latest, left, list, next, ...'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'Test') !== false);
$this->assertTrue(strpos($highlightedHTML, 'test') !== false);
$this->assertTrue(strpos($highlightedHTML, 'text') !== false);
// Check that other words are not highlighted
$this->assertTrue(strpos($highlightedHTML, 'latest, left, list, next, ...') !== false);
}
public function testHighlightFuzzy2()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('test~0.4');
$html = ''
. 'Page title'
. ''
. 'Test of text fuzzy search terms highlighting. '
. 'Words: test, text, latest, left, list, next, ...'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'Test') !== false);
$this->assertTrue(strpos($highlightedHTML, 'test') !== false);
// Check that other words are also highlighted
$this->assertTrue(strpos($highlightedHTML, 'text') !== false);
$this->assertTrue(strpos($highlightedHTML, 'latest') !== false);
$this->assertTrue(strpos($highlightedHTML, 'left') !== false);
$this->assertTrue(strpos($highlightedHTML, 'list') !== false);
$this->assertTrue(strpos($highlightedHTML, 'next') !== false);
}
public function testHighlightRangeInclusive()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('[business TO by]');
$html = ''
. 'Page title'
. ''
. 'Test of text using range query. '
. 'It has to match "business", "by", "buss" and "but" words, but has to skip "bus"'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'business') !== false);
$this->assertTrue(strpos($highlightedHTML, 'by') !== false);
$this->assertTrue(strpos($highlightedHTML, 'buss') !== false);
$this->assertTrue(strpos($highlightedHTML, 'but') !== false);
// Check that "bus" word is skipped
$this->assertTrue(strpos($highlightedHTML, 'has to skip "bus"') !== false);
}
public function testHighlightRangeNonInclusive()
{
$query = Zend_Search_Lucene_Search_QueryParser::parse('{business TO by}');
$html = ''
. 'Page title'
. ''
. 'Test of text using range query. '
. 'It has to match "buss" and "but" words, but has to skip "business", "by" and "bus"'
. ''
. '';
$highlightedHTML = $query->highlightMatches($html);
$this->assertTrue(strpos($highlightedHTML, 'buss') !== false);
$this->assertTrue(strpos($highlightedHTML, 'but') !== false);
// Check that "bus" word is skipped
$this->assertTrue(strpos($highlightedHTML, 'has to skip "business", "by" and "bus"') !== false);
}
}