|
@@ -130,7 +130,12 @@ function materio_search_api_results_search(){
|
|
|
|
|
|
// retreive typed words separated by slashes as a sentence
|
|
// retreive typed words separated by slashes as a sentence
|
|
$args = func_get_args();
|
|
$args = func_get_args();
|
|
- // dsm($args, 'args');
|
|
|
|
|
|
+ // dsm($args, 'materio_search_api_results_search :: args');
|
|
|
|
+
|
|
|
|
+ $filters_search = false;
|
|
|
|
+ if(isset($args[0]) && $args[0] == "filters"){
|
|
|
|
+ $filters_search = array_shift($args);
|
|
|
|
+ }
|
|
|
|
|
|
$keys = $args;
|
|
$keys = $args;
|
|
// $keys = explode(' ',implode(' ',$args));
|
|
// $keys = explode(' ',implode(' ',$args));
|
|
@@ -169,7 +174,12 @@ function materio_search_api_results_search(){
|
|
# Normal search
|
|
# Normal search
|
|
if(user_access('use materio search api')){
|
|
if(user_access('use materio search api')){
|
|
// dsm('normal search');
|
|
// dsm('normal search');
|
|
- $results = msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit);
|
|
|
|
|
|
+ // TODO: this two following functions calls should be merged, it's not clean as it is
|
|
|
|
+ if(!$filters_search){
|
|
|
|
+ $results = msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit);
|
|
|
|
+ }else{
|
|
|
|
+ $results = msa_solrquery_filterssearch($typed, $language, $user, $offset, $limit);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
# only breves search (+ related materials)
|
|
# only breves search (+ related materials)
|
|
# not used anymore as free users not exists anymore
|
|
# not used anymore as free users not exists anymore
|
|
@@ -224,6 +234,7 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
|
|
|
|
|
# define default bundle option (materiaux, breves)
|
|
# define default bundle option (materiaux, breves)
|
|
$default_bundles = array();
|
|
$default_bundles = array();
|
|
|
|
+ // TODO: this can't work as $taxo_index is not defined yet
|
|
if(isset($taxo_index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
|
if(isset($taxo_index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
|
$indexed_bundles = $taxo_index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
|
$indexed_bundles = $taxo_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; }
|
|
@@ -307,6 +318,10 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
|
$fulltxt_results = $fulltxt_query->execute();
|
|
$fulltxt_results = $fulltxt_query->execute();
|
|
// dsm($fulltxt_results, "fulltxt_results");
|
|
// dsm($fulltxt_results, "fulltxt_results");
|
|
|
|
|
|
|
|
+
|
|
|
|
+ // -- -- merge taxo and full text search -- -- //
|
|
|
|
+
|
|
|
|
+
|
|
# add the fulltext search results to the global results
|
|
# add the fulltext search results to the global results
|
|
$return['results'] += $fulltxt_results['results'];
|
|
$return['results'] += $fulltxt_results['results'];
|
|
|
|
|
|
@@ -331,6 +346,70 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
|
return $return;
|
|
return $return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function msa_solrquery_filterssearch($keys, $language, $user, $offset, $limit){
|
|
|
|
+ // dsm($offset, 'offset');
|
|
|
|
+ // dsm($limit, 'limit');
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ # define search api solr index
|
|
|
|
+ $taxo_index_machine_name = variable_get('taxonomysearchindex_'.$language->language, -1);
|
|
|
|
+ $taxo_index = search_api_index_load($taxo_index_machine_name);
|
|
|
|
+
|
|
|
|
+ # choose solr query options
|
|
|
|
+ $query_options = array('conjunction'=>'AND', 'parse mode'=>'terms');
|
|
|
|
+
|
|
|
|
+ #create the solr query for taxonomy search
|
|
|
|
+ $taxo_query = search_api_query($taxo_index_machine_name, $query_options)
|
|
|
|
+ ->keys($keys);
|
|
|
|
+ // ->range($offset, $limit);
|
|
|
|
+
|
|
|
|
+ # apply bundle options to solr query if usefull
|
|
|
|
+ if(count($bundles_filter)){
|
|
|
|
+ $filter = $taxo_query->createFilter('OR');
|
|
|
|
+ foreach ($bundles_filter as $type)
|
|
|
|
+ $filter->condition('type', $type, '=');
|
|
|
|
+
|
|
|
|
+ $taxo_query->filter($filter);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // $query->setOption('search_api_bypass_access', true);
|
|
|
|
+
|
|
|
|
+ # add user access solr query option
|
|
|
|
+ $taxo_query->setOption('search_api_access_account', $user);
|
|
|
|
+
|
|
|
|
+ // $taxo_query->setOption('q.op', 'OR');
|
|
|
|
+
|
|
|
|
+ #execute first time to get the all items, to be able to filter the full text research
|
|
|
|
+ $taxo_total_results = $taxo_query->execute();
|
|
|
|
+ // dsm($taxo_total_results, "taxo total results");
|
|
|
|
+
|
|
|
|
+ $return = array(
|
|
|
|
+ "results" => $taxo_total_results['results']
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ # count global results
|
|
|
|
+ $return['result count'] = count($return['results']);
|
|
|
|
+
|
|
|
|
+ # create items array with the good range
|
|
|
|
+ $return['items'] = array();
|
|
|
|
+
|
|
|
|
+ $o = -1;
|
|
|
|
+ foreach ($return['results'] as $nid => $value) {
|
|
|
|
+ $o++;
|
|
|
|
+ if( $o < $offset ) continue;
|
|
|
|
+ if ($o >= $offset+$limit) break;
|
|
|
|
+
|
|
|
|
+ $return['items'][$nid] = node_load($nid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful
|
|
|
|
+
|
|
|
|
+ // dsm($return, 'return');
|
|
|
|
+ return $return;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
# not used anymore as free users not exists anymore
|
|
# not used anymore as free users not exists anymore
|
|
function msa_solrquery_breves($typed, $language, $user, $offset, $limit){
|
|
function msa_solrquery_breves($typed, $language, $user, $offset, $limit){
|
|
|
|
|