upadted to 1.8
This commit is contained in:
@@ -10,9 +10,9 @@ files[] = search_api_test.module
|
||||
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-09
|
||||
version = "7.x-1.4"
|
||||
; Information added by drupal.org packaging script on 2013-09-01
|
||||
version = "7.x-1.8"
|
||||
core = "7.x"
|
||||
project = "search_api"
|
||||
datestamp = "1357726719"
|
||||
datestamp = "1378025826"
|
||||
|
||||
|
@@ -22,7 +22,7 @@ function search_api_test_schema() {
|
||||
'description' => 'The title of the item.',
|
||||
'type' => 'varchar',
|
||||
'length' => 50,
|
||||
'not null' => TRUE,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'body' => array(
|
||||
'description' => 'A text belonging to the item.',
|
||||
@@ -33,7 +33,13 @@ function search_api_test_schema() {
|
||||
'description' => 'A string identifying the type of item.',
|
||||
'type' => 'varchar',
|
||||
'length' => 50,
|
||||
'not null' => TRUE,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'keywords' => array(
|
||||
'description' => 'A comma separated list of keywords.',
|
||||
'type' => 'varchar',
|
||||
'length' => 200,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
|
@@ -43,6 +43,9 @@ function search_api_test_insert_item(array $form, array &$form_state) {
|
||||
'type' => array(
|
||||
'#type' => 'textfield',
|
||||
),
|
||||
'keywords' => array(
|
||||
'#type' => 'textfield',
|
||||
),
|
||||
'submit' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
@@ -55,7 +58,7 @@ function search_api_test_insert_item(array $form, array &$form_state) {
|
||||
*/
|
||||
function search_api_test_insert_item_submit(array $form, array &$form_state) {
|
||||
form_state_values_clean($form_state);
|
||||
db_insert('search_api_test')->fields($form_state['values'])->execute();
|
||||
db_insert('search_api_test')->fields(array_filter($form_state['values']))->execute();
|
||||
module_invoke_all('entity_insert', search_api_test_load($form_state['values']['id']), 'search_api_test');
|
||||
}
|
||||
|
||||
@@ -78,25 +81,8 @@ function search_api_test_view($entity) {
|
||||
* Menu callback for executing a search.
|
||||
*/
|
||||
function search_api_test_query(SearchApiIndex $index, $keys = 'foo bar', $offset = 0, $limit = 10, $fields = NULL, $sort = NULL, $filters = NULL) {
|
||||
// Slight "hack" for testing complex queries.
|
||||
if ($keys == '|COMPLEX|') {
|
||||
$keys = array(
|
||||
'#conjunction' => 'AND',
|
||||
'test',
|
||||
array(
|
||||
'#conjunction' => 'OR',
|
||||
'baz',
|
||||
'foobar',
|
||||
),
|
||||
array(
|
||||
'#conjunction' => 'AND',
|
||||
'#negation' => TRUE,
|
||||
'bar',
|
||||
),
|
||||
);
|
||||
}
|
||||
$query = $index->query()
|
||||
->keys($keys)
|
||||
->keys($keys ? $keys : NULL)
|
||||
->range($offset, $limit);
|
||||
if ($fields) {
|
||||
$query->fields(explode(',', $fields));
|
||||
@@ -177,6 +163,12 @@ function search_api_test_entity_property_info() {
|
||||
'description' => "The item's parent.",
|
||||
'getter callback' => 'search_api_test_parent',
|
||||
),
|
||||
'keywords' => array(
|
||||
'label' => 'Keywords',
|
||||
'type' => 'list<string>',
|
||||
'description' => 'An optional collection of keywords describing the item.',
|
||||
'getter callback' => 'search_api_test_list_callback',
|
||||
),
|
||||
);
|
||||
|
||||
return $info;
|
||||
@@ -198,6 +190,20 @@ function search_api_test_parent($entity) {
|
||||
return search_api_test_load($entity->id - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* List callback.
|
||||
*/
|
||||
function search_api_test_list_callback($data) {
|
||||
//return is_array($entity->keywords) ? $entity->keywords : explode(',', $entity->keywords);
|
||||
if (is_array($data)) {
|
||||
$res = is_array($data['keywords']) ? $data['keywords'] : explode(',', $data['keywords']);
|
||||
}
|
||||
else {
|
||||
$res = is_array($data->keywords) ? $data->keywords : explode(',', $data->keywords);
|
||||
}
|
||||
return array_filter($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_api_service_info().
|
||||
*/
|
||||
|
Reference in New Issue
Block a user