Commit f235d281 authored by Karl's avatar Karl

Die neuen Spezialsuchen sind jetzt eingebaut und getestet

parent 20a4e5d7
......@@ -854,10 +854,7 @@ class MetaGer
}
# Sucheingabe
$this->eingabe = trim($request->input('eingabe', ''));
if (strlen($this->eingabe) === 0) {
$this->warnings[] = trans('metaGer.formdata.noSearch');
}
$this->q = $this->eingabe;
$this->q = strtolower($this->eingabe);
# IP
$this->ip = $request->ip();
# Language
......@@ -964,7 +961,8 @@ class MetaGer
public function searchCheckSitesearch($site)
{
while (preg_match("/(^|.+\s)site:(\S+)(?:\s(.+)|$)/si", $this->q, $match)) {
// matches '[... ]site:test.de[ ...]'
while (preg_match("/(^|.+\s)site:(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->site = $match[2];
$this->q = $match[1] . $match[3];
}
......@@ -975,9 +973,10 @@ class MetaGer
public function searchCheckHostBlacklist()
{
while (preg_match("/(.*)(^|\s)-host:(\S+)(.*)/si", $this->q, $match)) {
$this->hostBlacklist[] = $match[3];
$this->q = $match[1] . $match[4];
// matches '[... ]-site:test.de[ ...]'
while (preg_match("/(^|.+\s)-site:([^\s\*]\S*)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->hostBlacklist[] = $match[2];
$this->q = $match[1] . $match[3];
}
if (sizeof($this->hostBlacklist) > 0) {
$hostString = "";
......@@ -991,9 +990,10 @@ class MetaGer
public function searchCheckDomainBlacklist()
{
while (preg_match("/(.*)(^|\s)-domain:(\S+)(.*)/si", $this->q, $match)) {
$this->domainBlacklist[] = $match[3];
$this->q = $match[1] . $match[4];
// matches '[... ]-site:*.test.de[ ...]'
while (preg_match("/(^|.+\s)-site:\*\.(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->domainBlacklist[] = $match[2];
$this->q = $match[1] . $match[3];
}
if (sizeof($this->domainBlacklist) > 0) {
$domainString = "";
......@@ -1007,9 +1007,10 @@ class MetaGer
public function searchCheckStopwords()
{
while (preg_match("/(.*)(^|\s)-(\S+)(.*)/si", $this->q, $match)) {
$this->stopWords[] = $match[3];
$this->q = $match[1] . $match[4];
// matches '[... ]-test[ ...]'
while (preg_match("/(^|.+\s)-(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->stopWords[] = $match[2];
$this->q = $match[1] . $match[3];
}
if (sizeof($this->stopWords) > 0) {
$stopwordsString = "";
......@@ -1025,7 +1026,8 @@ class MetaGer
{
$p = "";
$tmp = $this->q;
while (preg_match("/(.*)\"(.+)\"(.*)/si", $tmp, $match)) {
// matches '[... ]"test satz"[ ...]'
while (preg_match("/(^|.+\s)\"(.+)\"(?:\s(.+)|($))/si", $tmp, $match)) {
$tmp = $match[1] . $match[3];
$this->phrases[] = strtolower($match[2]);
}
......@@ -1218,7 +1220,7 @@ class MetaGer
{
$host = urlencode($host);
$requestData = $this->request->except(['page', 'out', 'next']);
$requestData['eingabe'] .= " -host:$host";
$requestData['eingabe'] .= " -site:$host";
$link = action('MetaGerSearch@search', $requestData);
return $link;
}
......@@ -1227,7 +1229,7 @@ class MetaGer
{
$domain = urlencode($domain);
$requestData = $this->request->except(['page', 'out', 'next']);
$requestData['eingabe'] .= " -domain:$domain";
$requestData['eingabe'] .= " -site:*.$domain";
$link = action('MetaGerSearch@search', $requestData);
return $link;
}
......
......@@ -43,14 +43,14 @@ class MetaGerPhpTest extends TestCase
// Testet das erkennen von Spezialsuchen in verschiedenen Sucheingaben
public function specialSearchTest()
{
$metager = $this->createSpecialSearchMetager('suchwort -blackword -host:blackhost -domain:blackdomain site:wantsite "i want phrase"');
$metager = $this->createSpecialSearchMetager('suchwort -blackword -site:blackhost -site:*.blackdomain site:wantsite "i want phrase"');
$this->assertEquals("wantsite", $metager->getSite());
$this->assertContains("blackhost", $metager->getUserHostBlacklist());
$this->assertContains("blackdomain", $metager->getUserDomainBlacklist());
$this->assertContains("blackword", $metager->getStopWords());
$this->assertContains("i want phrase", $metager->getPhrases());
$metager = $this->createSpecialSearchMetager('site:peter:test -blackword-test -host:blackhost-test.de.nz/test ich suche nach -host:blackhost:blackhost2.cote/t?p=5 "peter ist obst-garten und -bauern"');
$metager = $this->createSpecialSearchMetager('site:peter:test -blackword-test -site:blackhost-test.de.nz/test ich suche nach -site:blackhost:blackhost2.cote/t?p=5 "peter ist obst-garten und -bauern"');
$this->assertEquals("peter:test", $metager->getSite());
$this->assertContains("blackhost:blackhost2.cote/t?p=5", $metager->getUserHostBlacklist());
$this->assertContains("blackhost-test.de.nz/test", $metager->getUserHostBlacklist());
......@@ -58,15 +58,19 @@ class MetaGerPhpTest extends TestCase
$this->assertNotContains("bauern", $metager->getStopWords());
$this->assertContains("peter ist obst-garten und -bauern", $metager->getPhrases());
$metager = $this->createSpecialSearchMetager('-host:-domain:test');
$this->assertContains("-domain:test", $metager->getUserHostBlacklist());
$metager = $this->createSpecialSearchMetager('-site:-site:*.test');
$this->assertContains("-site:*.test", $metager->getUserHostBlacklist());
$metager = $this->createSpecialSearchMetager('"-host:-domain:test"');
$this->assertContains("-host:-domain:test", $metager->getPhrases());
$metager = $this->createSpecialSearchMetager('"-site:-site:*.test"');
$this->assertContains("-site:-site:*.test", $metager->getPhrases());
$metager = $this->createSpecialSearchMetager('site:wikipedia.de site:test.de tomate');
$this->assertEquals("tomate", $metager->getQ());
$metager = $this->createSpecialSearchMetager('site:wikipedia.de apfel site:test.de tomate');
$this->assertEquals("apfel tomate", $metager->getQ());
$this->assertEquals("test.de", $metager->getSite());
$metager = $this->createSpecialSearchMetager('site:wikipedia.de');
$this->assertEquals("", $metager->getQ());
$this->assertEquals("wikipedia.de", $metager->getSite());
}
public function createSpecialSearchMetager($eingabe)
......@@ -142,9 +146,9 @@ class MetaGerPhpTest extends TestCase
$this->containCallbackTester($metager, "generateSiteSearchLink", ["wolf.de"],
'site%3Awolf.de');
$this->containCallbackTester($metager, "generateRemovedHostLink", ["wolf.de"],
'-host%3Awolf.de');
'-site%3Awolf.de');
$this->containCallbackTester($metager, "generateRemovedDomainLink", ["wolf.de"],
'-domain%3Awolf.de');
'-site%3A%2A.wolf.de');
}
// Prüft ob der Host Count funktioniert
......@@ -330,7 +334,7 @@ class MetaGerPhpTest extends TestCase
#new Request(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
$query = [];
$query["eingabe"] = 'suchwort -blackword -host:blackhost -domain:blackdomain site:wantsite "i want phrase"';
$query["eingabe"] = 'suchwort -blackword -site:blackhost -site:*.blackdomain site:wantsite "i want phrase"';
$query["focus"] = "angepasst";
$query["encoding"] = "utf8";
$query["lang"] = "all";
......
......@@ -78,7 +78,7 @@ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
$this->assertTrue($result->isValid($metager));
$metager = new MetaGer();
$request = new Request(['eingabe' => 'test -host:host.domain.de -domain:domain.de']);
$request = new Request(['eingabe' => 'test -site:host.domain.de -site:*.domain.de']);
$metager->parseFormData($request);
$metager->checkSpecialSearches($request);
......
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