diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2016-02-03 21:12:17 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2016-02-03 21:12:17 +0100 |
| commit | 88c741c09b664260f826ff947bfaab071ac70d05 (patch) | |
| tree | b2f7417aee5979d4bd994b929f71d518a3604aa0 /src/phinde | |
| parent | fab8cabe19ac99e3c8a95abcea3c0569b67045bb (diff) | |
| download | phinde-88c741c09b664260f826ff947bfaab071ac70d05.tar.gz phinde-88c741c09b664260f826ff947bfaab071ac70d05.zip | |
add site search, highlighting
Diffstat (limited to 'src/phinde')
| -rw-r--r-- | src/phinde/Elasticsearch.php | 31 | ||||
| -rw-r--r-- | src/phinde/Helper.php | 9 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/phinde/Elasticsearch.php b/src/phinde/Elasticsearch.php index 4bc4637..735b64f 100644 --- a/src/phinde/Elasticsearch.php +++ b/src/phinde/Elasticsearch.php @@ -68,7 +68,7 @@ class Elasticsearch $r->send(); } - public function search($query, $filters, $page, $perPage) + public function search($query, $filters, $site, $page, $perPage) { $r = new Elasticsearch_Request( $this->baseUrl . 'document/_search', @@ -98,6 +98,24 @@ class Elasticsearch ) ) ), + 'highlight' => array( + 'pre_tags' => array('<em class="hl">'), + 'order' => 'score', + 'fields' => array( + 'title' => array( + 'require_field_match' => false, + 'number_of_fragments' => 0, + ), + 'url' => array( + 'require_field_match' => false, + 'number_of_fragments' => 0, + ), + 'text' => array( + 'require_field_match' => false, + 'number_of_fragments' => 1, + ), + ) + ), 'aggregations' => array( 'tags' => array( 'terms' => array( @@ -133,11 +151,20 @@ class Elasticsearch ) ); } + if ($site != '') { + $doc['query']['bool']['must'][] = array( + 'prefix' => array( + 'schemalessUrl' => array( + 'value' => $site + ) + ) + ); + } //unset($doc['_source']); //ini_set('xdebug.var_display_max_depth', 10); - //return json_decode(json_encode($doc)); + //echo json_encode($doc);die(); $r->setBody(json_encode($doc)); $res = $r->send(); return json_decode($res->getBody()); diff --git a/src/phinde/Helper.php b/src/phinde/Helper.php index 4863961..0b98521 100644 --- a/src/phinde/Helper.php +++ b/src/phinde/Helper.php @@ -11,5 +11,14 @@ class Helper } return true; } + + public static function noSchema($url) + { + return str_replace( + array('http://', 'https://'), + '', + $url + ); + } } ?> |
