Last active
December 17, 2015 01:09
-
-
Save staabm/5526027 to your computer and use it in GitHub Desktop.
watson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// baseclass | |
public abstract class AbstractWatsonSearcher { | |
/** | |
* @return string[] an array of supported keywords | |
* / | |
abstract function keywords(); | |
/** | |
* Search for the given SearchTerm | |
* | |
* @return SearchResult | |
* / | |
abstract function search(SearchTerm $search); | |
} | |
public class SearchTerm { | |
private $keyword; | |
private $input; | |
// .. constructor mit $keyword & $input | |
// getter für keyword+searchTerm | |
} | |
public class SearchResult { | |
// was immer du alles brauchst für die ergebnisliste | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Phase1 | |
/** @var $searcher AbstractWatsonSearcher[] */ | |
$searchers = rex_register_extension_point('WATSON_SEARCHER'); | |
// Phase2 | |
// User Eingabe parsen in $keyword & $input | |
$searchTerm = new SearchTerm($keyword, $input); | |
// Eingabe an vorher registrierte Search übergeben und Ergebnisse einsammeln | |
/** @var $searchResults SearchResult[] */ | |
$searchResults = array(); | |
foreach($searchers as $searcher) { | |
if (in_array($searcher->getKeywords(), $searchTerm->getKeyword()) { | |
$searchResults[] = $searcher->search($searchTerm); | |
} | |
} | |
// irgendwo später Ergebnis rendern | |
foreach ($searchResults as $searchResult) { | |
// render json/html whatever | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Searcher2 extends AbstractWatsonSearcher { | |
public function keywords() { | |
return array('ep', 'xyz'); | |
} | |
public function search(SearchTerm $searchTerm) { | |
$result = new SearchResult(); | |
// suche in einem Array von EPs | |
// ergebnisse in $result einfügen | |
return $result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Searcher1 extends AbstractWatsonSearcher { | |
public function keywords() { | |
return array('maggus', 'thomas'); | |
} | |
public function search(SearchTerm $searchTerm) { | |
$result = new SearchResult(); | |
// suche via SQL in der DB | |
// ergebnisse in $result einfügen | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment