Commit 90ad14d7 authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '663-alle-special-searches-optional-uber-url-parameter-ubernehmen' into 'development'

Resolve "Alle Special Searches Optional über URL Parameter übernehmen."

Closes #663

See merge request !1144
parents c2840ed4 41a9a20a
...@@ -1034,40 +1034,52 @@ class MetaGer ...@@ -1034,40 +1034,52 @@ class MetaGer
public function checkSpecialSearches(Request $request) public function checkSpecialSearches(Request $request)
{ {
if ($request->has('site')) { $this->searchCheckSitesearch($request);
$site = $request->input('site'); $this->searchCheckHostBlacklist($request);
} else { $this->searchCheckDomainBlacklist($request);
$site = "";
}
$this->searchCheckSitesearch($site);
$this->searchCheckHostBlacklist();
$this->searchCheckDomainBlacklist();
$this->searchCheckUrlBlacklist(); $this->searchCheckUrlBlacklist();
$this->searchCheckPhrase(); $this->searchCheckPhrase();
$this->searchCheckStopwords(); $this->searchCheckStopwords($request);
$this->searchCheckNoSearch(); $this->searchCheckNoSearch();
} }
private function searchCheckSitesearch($site) private function searchCheckSitesearch($request)
{ {
// matches '[... ]site:test.de[ ...]' // matches '[... ]site:test.de[ ...]'
while (preg_match("/(^|.+\s)site:(\S+)(?:\s(.+)|($))/si", $this->q, $match)) { 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];
} }
if ($site !== "") { # Overwrite Setting if it's submitted via Parameter
$this->site = $site; if ($request->has('site')) {
$this->site = $request->input('site');
} }
} }
private function searchCheckHostBlacklist() private function searchCheckHostBlacklist($request)
{ {
// matches '[... ]-site:test.de[ ...]' // matches '[... ]-site:test.de[ ...]'
while (preg_match("/(^|.+\s)-site:([^\s\*]\S*)(?:\s(.+)|($))/si", $this->q, $match)) { while (preg_match("/(^|.+\s)-site:([^\s\*]\S*)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->hostBlacklist[] = $match[2]; $this->hostBlacklist[] = $match[2];
$this->q = $match[1] . $match[3]; $this->q = $match[1] . $match[3];
} }
# Overwrite Setting if it's submitted via Parameter
if($request->has('blacklist')){
$this->hostBlacklist = [];
$blacklistString = trim($request->input('blacklist'));
if(strpos($blacklistString, ",") !== FALSE){
$blacklistArray = explode(',', $blacklistString);
foreach($blacklistArray as $blacklistElement){
$blacklistElement = trim($blacklistElement);
if(strpos($blacklistElement, "*") !== 0){
$this->hostBlacklist[] = $blacklistElement;
}
}
}else if(strpos($blacklistString, "*") !== 0){
$this->hostBlacklist[] = $blacklistString;
}
}
// print the host blacklist as a user warning // print the host blacklist as a user warning
if (sizeof($this->hostBlacklist) > 0) { if (sizeof($this->hostBlacklist) > 0) {
$hostString = ""; $hostString = "";
...@@ -1079,13 +1091,29 @@ class MetaGer ...@@ -1079,13 +1091,29 @@ class MetaGer
} }
} }
private function searchCheckDomainBlacklist() private function searchCheckDomainBlacklist($request)
{ {
// matches '[... ]-site:*.test.de[ ...]' // matches '[... ]-site:*.test.de[ ...]'
while (preg_match("/(^|.+\s)-site:\*\.(\S+)(?:\s(.+)|($))/si", $this->q, $match)) { while (preg_match("/(^|.+\s)-site:\*\.(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->domainBlacklist[] = $match[2]; $this->domainBlacklist[] = $match[2];
$this->q = $match[1] . $match[3]; $this->q = $match[1] . $match[3];
} }
# Overwrite Setting if it's submitted via Parameter
if($request->has('blacklist')){
$this->domainBlacklist = [];
$blacklistString = trim($request->input('blacklist'));
if(strpos($blacklistString, ",") !== FALSE){
$blacklistArray = explode(',', $blacklistString);
foreach($blacklistArray as $blacklistElement){
$blacklistElement = trim($blacklistElement);
if(strpos($blacklistElement, "*.") === 0){
$this->domainBlacklist[] = substr($blacklistElement, strpos($blacklistElement, "*.")+2);
}
}
}else if(strpos($blacklistString, "*.") === 0){
$this->domainBlacklist[] = substr($blacklistString, strpos($blacklistString, "*.")+2);
}
}
// print the domain blacklist as a user warning // print the domain blacklist as a user warning
if (sizeof($this->domainBlacklist) > 0) { if (sizeof($this->domainBlacklist) > 0) {
$domainString = ""; $domainString = "";
...@@ -1115,13 +1143,27 @@ class MetaGer ...@@ -1115,13 +1143,27 @@ class MetaGer
} }
} }
private function searchCheckStopwords() private function searchCheckStopwords($request)
{ {
// matches '[... ]-test[ ...]' // matches '[... ]-test[ ...]'
while (preg_match("/(^|.+\s)-(\S+)(?:\s(.+)|($))/si", $this->q, $match)) { while (preg_match("/(^|.+\s)-(\S+)(?:\s(.+)|($))/si", $this->q, $match)) {
$this->stopWords[] = $match[2]; $this->stopWords[] = $match[2];
$this->q = $match[1] . $match[3]; $this->q = $match[1] . $match[3];
} }
# Overwrite Setting if submitted via Parameter
if($request->has('stop')){
$this->stopWords = [];
$stop = trim($request->input('stop'));
if(strpos($stop, ',') !== FALSE){
$stopArray = explode(',', $stop);
foreach($stopArray as $stopElement){
$stopElement = trim($stopElement);
$this->stopWords[] = $stopElement;
}
}else{
$this->stopWords[] = $stop;
}
}
// print the stopwords as a user warning // print the stopwords as a user warning
if (sizeof($this->stopWords) > 0) { if (sizeof($this->stopWords) > 0) {
$stopwordsString = ""; $stopwordsString = "";
......
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