Skip to content

Commit 7b4cd38

Browse files
committed
Merge pull request #30 from dmyers/driver-clients
Added ability to create indices for drivers
2 parents c61f58f + 3c87b82 commit 7b4cd38

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

src/Mmanos/Search/Index.php

+9
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ public function select($columns = array('*'))
129129
return $this->query()->select(is_array($columns) ? $columns : func_get_args());
130130
}
131131

132+
/**
133+
* Create the index.
134+
*
135+
* @param array $fields
136+
*
137+
* @return bool
138+
*/
139+
abstract public function createIndex(array $fields = array());
140+
132141
/**
133142
* Get a new query instance from the driver.
134143
*

src/Mmanos/Search/Index/Algolia.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ protected function getClient()
4343
}
4444

4545
/**
46-
* Get the ZendSearch lucene index instance associated with this instance.
46+
* Create the index.
47+
*
48+
* @param array $fields
49+
*
50+
* @return bool
51+
*/
52+
public function createIndex(array $fields = array())
53+
{
54+
return false;
55+
}
56+
57+
/**
58+
* Get the Algolia index instance associated with this instance.
4759
*
4860
* @return \AlgoliaSearch\Index
4961
*/

src/Mmanos/Search/Index/Elasticsearch.php

+25
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ protected function getClient()
4141
return static::$client;
4242
}
4343

44+
/**
45+
* Create the index.
46+
*
47+
* @param array $fields
48+
*
49+
* @return bool
50+
*/
51+
public function createIndex(array $fields = array())
52+
{
53+
$properties = array('_geoloc' => array('type' => 'geo_point'));
54+
55+
foreach ($fields as $field) {
56+
$properties[$field] = array('type' => 'string');
57+
}
58+
59+
$body['mappings'][static::$default_type]['properties'] = $properties;
60+
61+
$this->getClient()->indices()->create(array(
62+
'index' => $this->name,
63+
'body' => $body,
64+
));
65+
66+
return true;
67+
}
68+
4469
/**
4570
* Get a new query instance from the driver.
4671
*

src/Mmanos/Search/Index/Zend.php

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ public function __construct($name, $driver)
3232
* @var array
3333
*/
3434
protected $stored_query_totals = array();
35+
36+
/**
37+
* Create the index.
38+
*
39+
* @param array $fields
40+
*
41+
* @return bool
42+
*/
43+
public function createIndex(array $fields = array())
44+
{
45+
return false;
46+
}
3547

3648
/**
3749
* Get the ZendSearch lucene index instance associated with this instance.

0 commit comments

Comments
 (0)