removed advanced search code

This commit is contained in:
Bachir Soussi Chiadmi 2014-10-21 19:08:52 +02:00
parent ab1e9ae0ff
commit e5b63e455f
3 changed files with 7 additions and 306 deletions

View File

@ -34,12 +34,6 @@ function materio_search_api_settings(){
'#title' => t('Autocomplete search api index for %lang contents.', array('%lang'=>$name)),
);
$form['advancedsearchindex_'.$lcode] = array(
'#type'=>'select',
'#options'=>$index_options,
'#default_value' => variable_get('advancedsearchindex_'.$lcode, -1),
'#title' => t('Advanced search api index for %lang contents.', array('%lang'=>$name)),
);
}
@ -75,19 +69,5 @@ function materio_search_api_settings(){
);
}
$vocabularies = taxonomy_get_vocabularies();
// dsm($vocabularies, 'vocabularies');
foreach ($vocabularies as $vid => $voc){
$vocs_options[$vid] = $voc->name;
}
$form['advancedsearchvocs'] = array(
'#type'=>'select',
'#options'=>$vocs_options,
'#default_value' => variable_get('advancedsearchvocs', array()),
'#title' => t('Advanced Search Vocabularies'),
'#multiple' => true,
);
return system_settings_form($form);
}

View File

@ -38,10 +38,6 @@ function materio_search_api_permission() {
'title' => t('use Materio search api filters'),
'description' => t('Use materio search api filters.'),
),
'use materio search api advanced search' => array(
'title' => t('use materio search api advanced search'),
'description' => t('Use materio search api advanced search.'),
),
);
}
@ -440,11 +436,6 @@ function materio_search_api_block_info() {
'cache' => DRUPAL_NO_CACHE
);
$blocks['materio_sa_adv_search'] = array(
'info' => t('Materio search api advanced search'),
'cache' => DRUPAL_NO_CACHE
);
# NOT USED
$blocks['materio_search_api_viewmode'] = array(
'info' => t('Materio search api view mode selection'),
@ -496,13 +487,6 @@ function materio_search_api_block_view($delta = '') {
// }
// break;
# NOT USED
case 'materio_sa_adv_search':
if(user_access('use materio search api advanced search')){
$block['subject'] = t('Advanced Search');
$block['content'] = theme('materio_search_api_advanced_search_block', array());
}
break;
}
return $block;
}
@ -677,240 +661,6 @@ function materio_search_api_search_form_submit($form, &$form_state){
}
/**
* materiobase_advancedsearch_form()
*/
function materio_search_api_advanced_search_form($form, &$form_state){
// dsm($form_state, 'form_state');
// dsm($form, 'form');
// global $user;
$as_tree = materio_serach_api_get_advancedsearch_tree();
// dsm($as_tree, 'as_tree');
$keys = arg();
$path = array_shift($keys);
// dsm($keys, 'keys');
if($path == 'explore' && $keys[0] == "advanced"){
$advanced = true;
array_shift($keys);
$default_keys = $keys;
}
$form = array(
'title' => array(
'#prefix' => "<h3>",
'#markup' => t("Advanced Search"),
'#suffix' => "</h3>",
)
);
$form['slider'] = array(
'#type' => 'fieldset',
// '#title' => $voc->name,
'#tree' => true,
);
foreach ($as_tree as $vid => $tree) {
// $voc = taxonomy_vocabulary_load($vid);
// dsm($voc, 'voc');
$form['slider']['voc-'.$vid] = array(
'#type' => 'fieldset',
// '#title' => $voc->name,
'#tree' => true,
);
foreach ($tree as $term) {
// dsm($term, 'term');
$form['slider']['voc-'.$vid]['tree-'.$term['tid']] = array(
'#type' => 'fieldset',
// '#title' => $term->name,
'#attributes' => array("class"=>array("treelevel1")),
'#tree' => true,
);
$placeholder = t("Select an option");
$form['slider']['voc-'.$vid]['tree-'.$term['tid']]['children'] = array(
'#type' => 'select',
'#title' => $term['name'],
'#attributes' => array(
"class"=>array("treelevel1"),
"title"=>$placeholder,
"data-placeholder" => $placeholder,
), //, "form-control"
'#theme_wrappers' => array('materio_search_api_form_element'),
'#empty_option' => $placeholder,
'#empty_value' => 1,
);
$options = array();
foreach ($term['children'] as $tid => $child) {
$options[$tid] = $child['name'];
$classes2 = array("treelevel2", $child['tid']);
$options2 = array();
$dflt_values2 = array();
foreach ($child['children'] as $tid2 => $child2) {
$options2[$tid2] = $child2['name'];
// default Values
if(in_array($tid2, $default_keys))
$dflt_values2[] = $tid2;
}
if(count($options2)){
if(count($dflt_values2))
$classes2[] = 'visible';
$form['slider']['voc-'.$vid]['tree-'.$term['tid']]['tid-'.$child['tid']] = array(
'#type' => 'select',
'#title' => $child['name'],
'#multiple' => true,
'#attributes' => array(
"class" => $classes2, // , "form-control"
"title" => "-Please select-",
"tid" => $child['tid'],
),
'#theme_wrappers' => array('materio_search_api_form_element'),
// '#empty_option' => '-Please select-',
// '#empty_value' => 1,
'#options' => $options2,
'#default_value' => $dflt_values2,
);
}
}
if(count($options)){
$form['slider']['voc-'.$vid]['tree-'.$term['tid']]['children']['#options'] = $options;
}else{
unset($form['slider']['voc-'.$vid]['tree-'.$term['tid']]);
}
}
}
$form['slider']['show'] = array(
'#type' => 'image_button',
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
'#value' => t('Find'),
// '#attributes' => array("class"=>array("btn","btn-lg")),
'#prefix' => '<div class="submits">',
'#suffix' => '</div>',
);
return $form;
}
function materio_serach_api_get_advancedsearch_tree(){
$as_tree = array();
$vocabularies = variable_get('advancedsearchvocs', array());
foreach ($vocabularies as $vid) {
// dsm($vid, "vid");
// $voc = taxonomy_vocabulary_load($vid);
// dsm($voc, 'voc');
$tree = taxonomy_get_tree($vid, 0, 1, TRUE);
// dsm($tree, 'tree');
if(!count($tree)) continue;
foreach ($tree as $term) {
// dsm($term, "term : ".$term->name);
if(!isset($term->field_used_on_advanced_search['und'][0]['value'])
|| $term->field_used_on_advanced_search['und'][0]['value'] == 0)
continue;
$children = taxonomy_get_children($term->tid, $vid);
// dsm($children, "children");
if(!count($children)) continue;
foreach ($children as $tid => $child) {
$child = taxonomy_term_load($child->tid);
// dsm($child, 'child : '.$child->name);
if($child->field_used_on_advanced_search['und'][0]['value'] == 0)
continue;
// $children2 = taxonomy_get_children($child->tid, $vid);
$children2 = taxonomy_get_children_all($child->tid, $vid);
// dsm($children2, "children2");
if(!count($children2)) continue;
foreach ($children2 as $tid2 => $child2) {
$child2 = taxonomy_term_load($tid2);
// dsm($child2, 'child2 : '.$child2->name);
if(!isset($child2->field_used_on_advanced_search['und'][0]['value'])
|| $child2->field_used_on_advanced_search['und'][0]['value'] == 0)
continue;
$as_tree[$vid][$term->tid]['children'][$child->tid]['children'][$child2->tid] = array('tid'=>$child2->tid,'name'=>$child2->name);
}
if(isset($as_tree[$vid][$term->tid]['children'][$child->tid]['children']))
$as_tree[$vid][$term->tid]['children'][$child->tid] += array("tid"=>$child->tid,"name"=>$child->name);
}
if(isset($as_tree[$vid][$term->tid]['children']))
$as_tree[$vid][$term->tid] += array("tid"=>$term->tid,"name"=>$term->name);
}
}
return $as_tree;
}
function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
$c = taxonomy_get_children($tid, $vid, $key);
$result = array();
foreach ($c as $t => $d){
$result[$t] = $d;
$below = taxonomy_get_children_all($t, $vid, $key);
if (!empty($below)) {
foreach ($below as $nt => $nd){
$result[$nt] = $nd;
}
}
}
return $result;
}
function materio_search_api_advanced_search_form_validate($form, &$form_state){
// dsm($form, '$form');
// dsm($form_state, '$form_state');
// dsm(strlen($form_state['values']['searchfield']));
// if (strlen(trim($form_state['values']['searchfield'])) <= 1) {
// form_set_error('searchfield', 'Please enter at least 2 characters keyword.');
// }
}
function materio_search_api_advanced_search_form_submit($form, &$form_state){
// dsm($form, 'form');
// dsm($form_state, 'form_state');
$fs_values = $form_state['values']['slider'];
unset($fs_values['show']);
// dsm($fs_values, 'values');
foreach($fs_values as $voc => $trees){
foreach($trees as $tree => $values){
foreach ($values as $values => $selected) {
if(is_array($selected) && count($selected)){
foreach ($selected as $tid) {
$tids[] = $tid;
}
}
}
}
}
$form_state['redirect'] = 'explore/advanced/'.implode('/', $tids);
}
/**
* viewmode
*/

View File

@ -130,19 +130,8 @@ function materio_search_api_results_search(){
// 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{
$advanced = false;
$typed = implode('/', $keys);
}
$typed = implode('/', $keys);
// remove query page params
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
@ -155,13 +144,7 @@ function materio_search_api_results_search(){
global $language;
global $user;
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')){
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";
@ -183,7 +166,7 @@ function materio_search_api_results_search(){
$index = search_api_index_load($index_machine_name);
}
if(!user_access('use materio search api advanced search') && !user_access('use materio search api')){
if(!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);
@ -215,9 +198,7 @@ function materio_search_api_results_search(){
: $default_bundles;
# choose solr query options
$query_options = $advanced
? array('conjunction'=>'AND', 'parse mode'=>'direct')
: array('conjunction'=>'OR', 'parse mode'=>'direct');
$query_options = array('conjunction'=>'OR', 'parse mode'=>'direct');
#create the solr query
$query = search_api_query($index_machine_name, $query_options)
@ -262,9 +243,8 @@ function materio_search_api_results_search(){
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( user_access('use materio search api') ){
if(is_array($results['results'])){
$items = $index->loadItems(array_keys($results['results']));
}else{
@ -316,16 +296,7 @@ function materio_search_api_results_search(){
// page title
if($advanced){
foreach($keys as $tid){
$t = taxonomy_term_load($tid);
$ptk[] = $t->name;
}
$page_title = implode(' +', $ptk);
}
else{
$page_title = $typed;
}
$page_title = $typed;
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($page_title), PASS_THROUGH);
// render results