Improved search: combine AND, exact terms and exclude search.

This commit is contained in:
ArthurHoaro 2016-02-01 20:33:58 +01:00
parent 07c2f73543
commit bedd176a54
4 changed files with 83 additions and 29 deletions

View file

@ -278,6 +278,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
'stallman' => 1,
'free' => 1,
'-exclude' => 1,
'stuff' => 2,
),
self::$publicLinkDB->allTags()
);

View file

@ -27,7 +27,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
public function testFilter()
{
$this->assertEquals(
6,
7,
count(self::$linkFilter->filter('', ''))
);
@ -222,7 +222,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
2,
3,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"free software"'))
);
}
@ -250,11 +250,43 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
public function testFilterFullTextMixed()
{
$this->assertEquals(
2,
3,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'free software'))
);
}
/**
* Full-text search - test exclusion with '-'.
*/
public function testExcludeSearch()
{
$this->assertEquals(
1,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'free -software'))
);
$this->assertEquals(
7,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-software'))
);
}
/**
* Full-text search - test AND, exact terms and exclusion combined.
*/
public function testMultiSearch()
{
$this->assertEquals(
2,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"Free Software " stallman "read this"'))
);
$this->assertEquals(
1,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"free software " stallman "read this" -beard'))
);
}
/**
* Tag search with exclusion.
*/
@ -266,7 +298,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
5,
6,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
);
}

View file

@ -16,12 +16,21 @@ class ReferenceLinkDB
$this->addLink(
'Free as in Freedom 2.0',
'https://static.fsf.org/nosvn/faif-2.0.pdf',
'Richard Stallman and the Free Software Revolution',
'Richard Stallman and the Free Software Revolution. Read this.',
0,
'20150310_114633',
'free gnu software stallman -exclude'
);
$this->addLink(
'Note:',
'local',
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.',
0,
'20150310_114651',
''
);
$this->addLink(
'MediaGoblin',
'http://mediagoblin.org/',