Commit f235d281 authored by Karl's avatar Karl

Die neuen Spezialsuchen sind jetzt eingebaut und getestet

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