!!! search api for breve
Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
d01d0a2a7e
commit
0db5022c47
@ -20,6 +20,13 @@ function materio_search_api_settings(){
|
|||||||
'#title' => t('Main search api index for %lang contents.', array('%lang'=>$name)),
|
'#title' => t('Main search api index for %lang contents.', array('%lang'=>$name)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$form['brevessearchindex_'.$lcode] = array(
|
||||||
|
'#type'=>'select',
|
||||||
|
'#options'=>$index_options,
|
||||||
|
'#default_value' => variable_get('brevessearchindex_'.$lcode, -1),
|
||||||
|
'#title' => t('Breves search api index for %lang contents.', array('%lang'=>$name)),
|
||||||
|
);
|
||||||
|
|
||||||
$form['autocompletesearchindex_'.$lcode] = array(
|
$form['autocompletesearchindex_'.$lcode] = array(
|
||||||
'#type'=>'select',
|
'#type'=>'select',
|
||||||
'#options'=>$index_options,
|
'#options'=>$index_options,
|
||||||
@ -28,6 +35,7 @@ function materio_search_api_settings(){
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: select the activated viewmodes for change view mode and selected view mode
|
// TODO: select the activated viewmodes for change view mode and selected view mode
|
||||||
$entity_infos = entity_get_info();
|
$entity_infos = entity_get_info();
|
||||||
// dsm($entity_infos, 'entity_infos');
|
// dsm($entity_infos, 'entity_infos');
|
||||||
|
@ -18,6 +18,10 @@ function materio_search_api_permission() {
|
|||||||
'title' => t('Use materio search api'),
|
'title' => t('Use materio search api'),
|
||||||
'description' => t('Use materio search api.'),
|
'description' => t('Use materio search api.'),
|
||||||
),
|
),
|
||||||
|
'use materio search api for breves' => array(
|
||||||
|
'title' => t('Use materio search api for breves'),
|
||||||
|
'description' => t('Use materio search api for breves.'),
|
||||||
|
),
|
||||||
'use materio search api autocomplete' => array(
|
'use materio search api autocomplete' => array(
|
||||||
'title' => t('Use materio search api autocomplete'),
|
'title' => t('Use materio search api autocomplete'),
|
||||||
'description' => t('Use materio search api autocomplete.'),
|
'description' => t('Use materio search api autocomplete.'),
|
||||||
@ -68,7 +72,8 @@ function materio_search_api_menu() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$items['explore'] = $base+array(
|
$items['explore'] = $base+array(
|
||||||
'access arguments' => array('use materio search api'),
|
// 'access arguments' => array('use materio search api'),
|
||||||
|
'access callback' => 'materio_search_api_access_search',
|
||||||
'page callback' => 'materio_search_api_results_search',
|
'page callback' => 'materio_search_api_results_search',
|
||||||
'title' => t('Explore'),
|
'title' => t('Explore'),
|
||||||
//'page argument' => array(1,2,3),
|
//'page argument' => array(1,2,3),
|
||||||
@ -82,7 +87,7 @@ function materio_search_api_menu() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$items['materiosearchapi/viewmode/change'] = $base+array(
|
$items['materiosearchapi/viewmode/change'] = $base+array(
|
||||||
'access arguments' => array('use materio search api'),
|
'access arguments' => array('use materio search api viewmode selection'),
|
||||||
'page callback' => 'materio_search_api_viewmode_change',
|
'page callback' => 'materio_search_api_viewmode_change',
|
||||||
'page argument' => array(3),
|
'page argument' => array(3),
|
||||||
);
|
);
|
||||||
@ -90,6 +95,11 @@ function materio_search_api_menu() {
|
|||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function materio_search_api_access_search(){
|
||||||
|
return user_access('use materio search api for breves') || user_access('use materio search api');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hook_entity_property_info_alter().
|
* hook_entity_property_info_alter().
|
||||||
*/
|
*/
|
||||||
@ -199,7 +209,7 @@ function materio_search_api_block_view($delta = '') {
|
|||||||
|
|
||||||
switch ($delta) {
|
switch ($delta) {
|
||||||
case 'materio_search_api_search':
|
case 'materio_search_api_search':
|
||||||
if (user_access('use materio search api')) {
|
if (user_access('use materio search api') || user_access('use materio search api for breves')) {
|
||||||
$block['subject'] = t('Search');
|
$block['subject'] = t('Search');
|
||||||
$block['content'] = theme('materio_search_api_search_block', array());
|
$block['content'] = theme('materio_search_api_search_block', array());
|
||||||
}
|
}
|
||||||
@ -533,7 +543,7 @@ function template_preprocess_materio_search_api_results(array &$variables) {
|
|||||||
$results = $variables['results'];
|
$results = $variables['results'];
|
||||||
$keys = $variables['keys'];
|
$keys = $variables['keys'];
|
||||||
|
|
||||||
$variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
|
// $variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
|
||||||
$variables['result_count'] = $results['result count'];
|
$variables['result_count'] = $results['result count'];
|
||||||
$variables['sec'] = round($results['performance']['complete'], 3);
|
$variables['sec'] = round($results['performance']['complete'], 3);
|
||||||
$variables['search_performance'] = format_plural(
|
$variables['search_performance'] = format_plural(
|
||||||
|
@ -157,8 +157,25 @@ function materio_search_api_results_search(){
|
|||||||
// dsm($keys, 'keys');
|
// dsm($keys, 'keys');
|
||||||
|
|
||||||
global $language;
|
global $language;
|
||||||
$index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
|
||||||
$index = search_api_index_load($index_machine_name);
|
|
||||||
|
// if(user_access('use materio search api')){
|
||||||
|
|
||||||
|
// }else if(user_access('use materio search api for breves')){
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
if(user_access('use materio search api')){
|
||||||
|
$index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
||||||
|
$index = search_api_index_load($index_machine_name);
|
||||||
|
}else if(user_access('use materio search api for breves')){
|
||||||
|
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||||
|
// dsm($index_machine_name, '$index_machine_name');
|
||||||
|
$index = search_api_index_load($index_machine_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||||
|
// dsm($index_machine_name, '$index_machine_name');
|
||||||
|
|
||||||
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
||||||
foreach ($indexed_bundles as $bundle) {
|
foreach ($indexed_bundles as $bundle) {
|
||||||
@ -168,6 +185,7 @@ function materio_search_api_results_search(){
|
|||||||
// dsm($bundles_filter, 'bundles_filter');
|
// dsm($bundles_filter, 'bundles_filter');
|
||||||
|
|
||||||
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||||
|
// dsm($viewmode, 'viewmode');
|
||||||
|
|
||||||
if ($keys) {
|
if ($keys) {
|
||||||
// TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful
|
// TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful
|
||||||
@ -220,38 +238,67 @@ function materio_search_api_results_search(){
|
|||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(user_access('use materio search api')){
|
||||||
|
$items = $index->loadItems(array_keys($results['results']));
|
||||||
|
// dsm($items, 'items');
|
||||||
|
}else if(user_access('use materio search api for breves')){
|
||||||
|
$items = array();
|
||||||
|
$breves = $index->loadItems(array_keys($results['results']));
|
||||||
|
foreach ($breves as $nid => $breve) {
|
||||||
|
|
||||||
|
if(!node_access('view', $breve))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$items[] = $breve;
|
||||||
|
$materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
||||||
|
// dsm($materiaux, 'materiaux');
|
||||||
|
if($materiaux){
|
||||||
|
foreach ($materiaux as $value) {
|
||||||
|
$materiau = node_load($value['target_id']);
|
||||||
|
if(node_access('view', $materiau))
|
||||||
|
$items[] = $materiau;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$ret['results']['#theme'] = 'materio_search_api_results';
|
$ret['results']['#theme'] = 'materio_search_api_results';
|
||||||
/*
|
/*
|
||||||
TODO choose index in module settings
|
TODO choose index in module settings
|
||||||
*/
|
*/
|
||||||
$ret['results']['#index'] = search_api_index_load($index_machine_name);
|
$ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
||||||
$ret['results']['#results'] = $results;
|
$ret['results']['#results'] = $results;
|
||||||
|
|
||||||
|
$ret['results']['#items'] = $items;
|
||||||
|
|
||||||
$ret['results']['#view_mode'] = $viewmode;
|
$ret['results']['#view_mode'] = $viewmode;
|
||||||
$ret['results']['#keys'] = $keys;
|
$ret['results']['#keys'] = $keys;
|
||||||
|
|
||||||
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
|
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
|
||||||
|
|
||||||
// Load pager.
|
if(isset($results)){
|
||||||
// if ($results['result count'] > $page->options['per_page']) {
|
// Load pager.
|
||||||
pager_default_initialize($results['result count'], $limit);
|
// if ($results['result count'] > $page->options['per_page']) {
|
||||||
$ret['results']['#pager'] = theme('pager');
|
pager_default_initialize($results['result count'], $limit);
|
||||||
// }
|
$ret['results']['#pager'] = theme('pager');
|
||||||
|
// }
|
||||||
|
|
||||||
if (!empty($results['ignored'])) {
|
if (!empty($results['ignored'])) {
|
||||||
drupal_set_message(
|
drupal_set_message(
|
||||||
t('The following search keys are too short or too common and were therefore ignored: "@list".',
|
t('The following search keys are too short or too common and were therefore ignored: "@list".',
|
||||||
array( '@list' => implode(t('", "'), $results['ignored']) ) ),
|
array( '@list' => implode(t('", "'), $results['ignored']) ) ),
|
||||||
'warning'
|
'warning'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!empty($results['warnings'])) {
|
if (!empty($results['warnings'])) {
|
||||||
foreach ($results['warnings'] as $warning) {
|
foreach ($results['warnings'] as $warning) {
|
||||||
drupal_set_message($warning, 'warning');
|
drupal_set_message($warning, 'warning');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user