added some comments
This commit is contained in:
parent
afce4662bd
commit
c5f5eb4f64
@ -189,47 +189,52 @@ function materio_search_api_results_search(){
|
|||||||
// 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
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
# retrieve viewmode and then use it to define the query range
|
||||||
// dsm($viewmode, 'viewmode');
|
$viewmode = isset($user->data['materiosearchapi_viewmode'])
|
||||||
|
? $user->data['materiosearchapi_viewmode']
|
||||||
|
: variable_get('defaultviewmode', 'full');
|
||||||
|
|
||||||
$limit = variable_get($viewmode.'_limite', '10');
|
$limit = variable_get($viewmode.'_limite', '10');
|
||||||
$offset = pager_find_page() * $limit; //$page*$limit;//
|
$offset = pager_find_page() * $limit; //$page*$limit;//
|
||||||
|
|
||||||
if(isset($index)){
|
if(isset($index)){
|
||||||
|
|
||||||
// $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
# define default bundle option (materiaux, breves)
|
||||||
// dsm($index_machine_name, '$index_machine_name');
|
|
||||||
$default_bundles = array();
|
$default_bundles = array();
|
||||||
if(isset($index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
if(isset($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'];
|
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
||||||
foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
|
foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
|
||||||
}
|
}
|
||||||
|
# choose solr query bundle option
|
||||||
|
$bundles_filter = isset($user->data['materiosearchapi_bundlesfilter'])
|
||||||
|
? $user->data['materiosearchapi_bundlesfilter']
|
||||||
|
: $default_bundles;
|
||||||
|
|
||||||
$bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
|
# choose solr query options
|
||||||
// dsm($bundles_filter, 'bundles_filter');
|
$query_options = $advanced
|
||||||
if($advanced){
|
? array('conjunction'=>'AND', 'parse mode'=>'direct')
|
||||||
$query_options = array('conjunction'=>'AND', 'parse mode'=>'direct');
|
: array('conjunction'=>'OR', 'parse mode'=>'direct');
|
||||||
}
|
|
||||||
else{
|
|
||||||
$query_options = array('conjunction'=>'OR', 'parse mode'=>'direct');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#create the solr query
|
||||||
$query = search_api_query($index_machine_name, $query_options)
|
$query = search_api_query($index_machine_name, $query_options)
|
||||||
->keys($typed)
|
->keys($typed)
|
||||||
->range($offset, $limit);
|
->range($offset, $limit);
|
||||||
|
|
||||||
|
# apply bundle options to solr query if usefull
|
||||||
if(count($bundles_filter)){
|
if(count($bundles_filter)){
|
||||||
$filter = $query->createFilter('OR');
|
$filter = $query->createFilter('OR');
|
||||||
foreach ($bundles_filter as $type) {
|
foreach ($bundles_filter as $type)
|
||||||
$filter->condition('type', $type, '=');
|
$filter->condition('type', $type, '=');
|
||||||
}
|
|
||||||
// dsm($filter, 'filter');
|
|
||||||
$query->filter($filter);
|
$query->filter($filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $query->setOption('search_api_bypass_access', true);
|
// $query->setOption('search_api_bypass_access', true);
|
||||||
|
|
||||||
|
# add user access solr query option
|
||||||
$query->setOption('search_api_access_account', $user);
|
$query->setOption('search_api_access_account', $user);
|
||||||
|
|
||||||
|
# execute solr query and record results
|
||||||
$results = $query->execute();
|
$results = $query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user