Merge branch 'bettersearch' into prod
added advanced to prod branch for inline production
This commit is contained in:
@@ -127,9 +127,21 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
|
||||
function materio_search_api_results_search(){
|
||||
//dsm("materio_search_api_results_search");
|
||||
|
||||
// retreive typed words separated by slahes as a sentence
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
// retreive typed words separated by slashes as a sentence
|
||||
$keys = func_get_args();
|
||||
// dsm($args, 'args');
|
||||
if($keys[0] == "advanced"){
|
||||
$advanced = true;
|
||||
array_shift($keys);
|
||||
// dsm($keys, 'shifted keys');
|
||||
// foreach ($args as $arg) {
|
||||
// $typed[] = $arg;//(integer)$arg;
|
||||
// }
|
||||
$typed = implode(' +', $keys);
|
||||
}else{
|
||||
$typed = implode('/', $keys);
|
||||
}
|
||||
|
||||
|
||||
// remove query page params
|
||||
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
||||
@@ -142,8 +154,15 @@ function materio_search_api_results_search(){
|
||||
global $language;
|
||||
global $user;
|
||||
|
||||
if(user_access('use materio search api')){
|
||||
// switch index depending on key words type full text or taxonomy term (autocomplete selection)
|
||||
if($advanced && user_access('use materio search api advanced search')){
|
||||
// dsm('advanced search');
|
||||
$index_machine_name = variable_get('advancedsearchindex_'.$language->language, -1);
|
||||
// dsm($index_machine_name, '$index_machine_name');
|
||||
$index = search_api_index_load($index_machine_name);
|
||||
}
|
||||
else if(user_access('use materio search api')){
|
||||
// dsm('normal search');
|
||||
# switch index depending on key words type full text or taxonomy term (autocomplete selection)
|
||||
$searchmode = isset($user->data['materiosearchapi_searchmode']) ? $user->data['materiosearchapi_searchmode'] : "fulltext";
|
||||
switch($searchmode){
|
||||
case "fulltext":
|
||||
@@ -155,60 +174,74 @@ function materio_search_api_results_search(){
|
||||
// break;
|
||||
}
|
||||
$index = search_api_index_load($index_machine_name);
|
||||
}else if(user_access('use materio search api for breves')){
|
||||
}
|
||||
else if(user_access('use materio search api for breves')){
|
||||
// dsm('limited search');
|
||||
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||
// dsm($index_machine_name, '$index_machine_name');
|
||||
$index = search_api_index_load($index_machine_name);
|
||||
}
|
||||
|
||||
// potential results index for anonymous and free user
|
||||
$could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
||||
$could_index = search_api_index_load($index_machine_name);
|
||||
if(!user_access('use materio search api advanced search') && !user_access('use materio search api')){
|
||||
# potential results index for anonymous and free user
|
||||
$could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
||||
$could_index = search_api_index_load($index_machine_name);
|
||||
}
|
||||
|
||||
if ($typed) {
|
||||
// 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 {
|
||||
|
||||
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||
// dsm($viewmode, 'viewmode');
|
||||
# retrieve viewmode and then use it to define the query range
|
||||
$viewmode = isset($user->data['materiosearchapi_viewmode'])
|
||||
? $user->data['materiosearchapi_viewmode']
|
||||
: variable_get('defaultviewmode', 'full');
|
||||
|
||||
$limit = variable_get($viewmode.'_limite', '10');
|
||||
$offset = pager_find_page() * $limit; //$page*$limit;//
|
||||
|
||||
if(isset($index)){
|
||||
|
||||
// $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||
// dsm($index_machine_name, '$index_machine_name');
|
||||
# define default bundle option (materiaux, breves)
|
||||
$default_bundles = array();
|
||||
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'];
|
||||
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;
|
||||
// dsm($bundles_filter, 'bundles_filter');
|
||||
# choose solr query options
|
||||
$query_options = $advanced
|
||||
? array('conjunction'=>'AND', 'parse mode'=>'direct')
|
||||
: array('conjunction'=>'OR', 'parse mode'=>'direct');
|
||||
|
||||
$query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
||||
// ->keys(implode(' ', $keys))
|
||||
#create the solr query
|
||||
$query = search_api_query($index_machine_name, $query_options)
|
||||
->keys($typed)
|
||||
->range($offset, $limit);
|
||||
|
||||
# apply bundle options to solr query if usefull
|
||||
if(count($bundles_filter)){
|
||||
$filter = $query->createFilter('OR');
|
||||
foreach ($bundles_filter as $type) {
|
||||
foreach ($bundles_filter as $type)
|
||||
$filter->condition('type', $type, '=');
|
||||
}
|
||||
// dsm($filter, 'filter');
|
||||
|
||||
$query->filter($filter);
|
||||
}
|
||||
|
||||
// $query->setOption('search_api_bypass_access', true);
|
||||
|
||||
# add user access solr query option
|
||||
$query->setOption('search_api_access_account', $user);
|
||||
|
||||
# execute solr query and record results
|
||||
$results = $query->execute();
|
||||
}
|
||||
|
||||
# in case of utilisateur search, run a real search to indicate how much items you could find
|
||||
# in case of free user search, run a real search to indicate how much items you could find
|
||||
if(isset($could_index)){
|
||||
$could_query = search_api_query($could_index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
||||
// ->keys(implode(' ', $keys))
|
||||
@@ -226,11 +259,17 @@ function materio_search_api_results_search(){
|
||||
}
|
||||
// dsm($results, 'results');
|
||||
|
||||
if(user_access('use materio search api for breves') || user_access('use materio search api')){
|
||||
if(user_access('use materio search api')){
|
||||
$items = $index->loadItems(array_keys($results['results']));
|
||||
if(user_access('use materio search api for breves')
|
||||
|| user_access('use materio search api')
|
||||
|| user_access('use materio search api advanced search'))
|
||||
{
|
||||
if(user_access('use materio search api') || user_access('use materio search api advanced search')){
|
||||
if(is_array($results['results'])){
|
||||
$items = $index->loadItems(array_keys($results['results']));
|
||||
}else{
|
||||
$items = array();
|
||||
}
|
||||
// dsm($items, 'items');
|
||||
// $count = $results['result count'];
|
||||
}
|
||||
else{
|
||||
$items = array();
|
||||
@@ -275,8 +314,20 @@ function materio_search_api_results_search(){
|
||||
$ret['results']['#view_mode'] = $viewmode;
|
||||
|
||||
|
||||
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
|
||||
// page title
|
||||
if($advanced){
|
||||
foreach($keys as $tid){
|
||||
$t = taxonomy_term_load($tid);
|
||||
$ptk[] = $t->name;
|
||||
}
|
||||
$page_title = implode(' +', $ptk);
|
||||
}
|
||||
else{
|
||||
$page_title = $typed;
|
||||
}
|
||||
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($page_title), PASS_THROUGH);
|
||||
|
||||
// render results
|
||||
if(isset($results)){
|
||||
// Load pager.
|
||||
// if ($results['result count'] > $page->options['per_page']) {
|
||||
|
||||
Reference in New Issue
Block a user