Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Start to convert to multiple version indexes.

  • Loading branch information...
commit 5e0001883eedf80fef72f73243a411078acd8bc5 1 parent 263f91c
@markstory authored
Showing with 15 additions and 6 deletions.
  1. +12 −3 Controller/SearchController.php
  2. +3 −3 Model/Search.php
View
15 Controller/SearchController.php
@@ -13,6 +13,10 @@ public function search() {
break;
}
}
+ $version = '2-2';
+ if (!empty($this->request->query['version'])) {
+ $version = $this->request->query['version'];
+ }
if (empty($this->request->query['lang'])) {
throw new BadRequestException();
}
@@ -38,9 +42,14 @@ public function search() {
),
'fields' => array('url', 'title'),
'highlight' => array(
+ 'pre_tags' => array(''),
+ 'post_tags' => array(''),
'fields' => array(
- 'contents' => array('fragment_size' => 100, 'number_of_fragments' => 3)
- )
+ 'contents' => array(
+ 'fragment_size' => 100,
+ 'number_of_fragments' => 3
+ ),
+ ),
),
'size' => 25,
);
@@ -49,7 +58,7 @@ public function search() {
if ($page > 0) {
$query['from'] = $query['size'] * ($page - 1);
}
- $results = $this->Search->find($lang, $query);
+ $results = $this->Search->find($lang, $version, $query);
$this->set('results', $results);
$this->set('_serialize', 'results');
}
View
6 Model/Search.php
@@ -5,14 +5,14 @@ class Search {
/**
* Search the index
*/
- public function find($lang, $query = array()) {
+ public function find($lang, $version, $query = array()) {
$query += array(
'query' => array(),
'sort' => array('_score'),
);
$config = Configure::read('ElasticSearch');
$url = $config['url'];
- $url .= $lang . '/_search';
+ $url .= $version . '-' . $lang . '/_search';
$Http = new HttpSocket();
$results = $Http->get($url, array(), array('body' => json_encode($query)));
@@ -21,7 +21,7 @@ public function find($lang, $query = array()) {
return array(
'title' => isset($el['fields']['title']) ? $el['fields']['title'] : '',
'url' => $el['fields']['url'],
- 'contents' => str_replace(array('<em>', '</em>'), '', $el['highlight']['contents']),
+ 'contents' => $el['highlight']['contents'],
);
}, $contents['hits']['hits']);
return array(
Please sign in to comment.
Something went wrong with that request. Please try again.