|
@@ -161,6 +161,8 @@ function materio_search_api_results_search(){
|
|
|
|
|
|
$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;//
|
|
|
|
+ // dsm($offset, "offset");
|
|
|
|
+
|
|
|
|
|
|
# Normal search
|
|
# Normal search
|
|
if(user_access('use materio search api')){
|
|
if(user_access('use materio search api')){
|
|
@@ -177,7 +179,7 @@ function materio_search_api_results_search(){
|
|
// for all case
|
|
// for all case
|
|
$ret['results']['#results'] = $results;
|
|
$ret['results']['#results'] = $results;
|
|
$ret['results']['#items'] = $results['items'];
|
|
$ret['results']['#items'] = $results['items'];
|
|
- $ret['results']['#index'] = $results['index'];
|
|
|
|
|
|
+ // $ret['results']['#index'] = $results['index'];
|
|
$ret['results']['#theme'] = 'materio_search_api_results';
|
|
$ret['results']['#theme'] = 'materio_search_api_results';
|
|
$ret['results']['#keys'] = $typed;
|
|
$ret['results']['#keys'] = $typed;
|
|
$ret['results']['#view_mode'] = $viewmode;
|
|
$ret['results']['#view_mode'] = $viewmode;
|
|
@@ -230,10 +232,8 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
|
: $default_bundles;
|
|
: $default_bundles;
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
// -- -- taxo search AND -- -- //
|
|
// -- -- taxo search AND -- -- //
|
|
|
|
|
|
-
|
|
|
|
# define search api solr index
|
|
# define search api solr index
|
|
$taxo_index_machine_name = variable_get('taxonomysearchindex_'.$language->language, -1);
|
|
$taxo_index_machine_name = variable_get('taxonomysearchindex_'.$language->language, -1);
|
|
$taxo_index = search_api_index_load($taxo_index_machine_name);
|
|
$taxo_index = search_api_index_load($taxo_index_machine_name);
|
|
@@ -259,43 +259,28 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
|
# add user access solr query option
|
|
# add user access solr query option
|
|
$taxo_query->setOption('search_api_access_account', $user);
|
|
$taxo_query->setOption('search_api_access_account', $user);
|
|
|
|
|
|
- $taxo_query->setOption('q.op', 'OR');
|
|
|
|
|
|
+ // $taxo_query->setOption('q.op', 'OR');
|
|
|
|
|
|
#execute first time to get the all items, to be able to filter the full text research
|
|
#execute first time to get the all items, to be able to filter the full text research
|
|
$taxo_total_results = $taxo_query->execute();
|
|
$taxo_total_results = $taxo_query->execute();
|
|
// dsm($taxo_total_results, "taxo total results");
|
|
// dsm($taxo_total_results, "taxo total results");
|
|
|
|
|
|
- # add range to retriev the real current results
|
|
|
|
- $taxo_query->range($offset, $limit);
|
|
|
|
-
|
|
|
|
- # execute solr query and record results
|
|
|
|
- $taxo_results = $taxo_query->execute();
|
|
|
|
- // dsm($taxo_results, "taxo results");
|
|
|
|
-
|
|
|
|
- $taxo_items = $taxo_index->loadItems(array_keys($taxo_results['results']));
|
|
|
|
- // dsm($taxo_items, 'taxo items');
|
|
|
|
- $taxo_results['items'] = $taxo_items;
|
|
|
|
- $taxo_results['index'] = $taxo_index;//search_api_index_load($index_machine_name);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ $return = array(
|
|
|
|
+ "results" => $taxo_total_results['results']
|
|
|
|
+ );
|
|
|
|
|
|
// -- -- full text search -- -- //
|
|
// -- -- full text search -- -- //
|
|
|
|
|
|
-
|
|
|
|
#define search api solr index
|
|
#define search api solr index
|
|
$fulltxt_index_machine_name = variable_get('fulltextsearchindex_'.$language->language, -1);
|
|
$fulltxt_index_machine_name = variable_get('fulltextsearchindex_'.$language->language, -1);
|
|
$fulltxt_index = search_api_index_load($fulltxt_index_machine_name);
|
|
$fulltxt_index = search_api_index_load($fulltxt_index_machine_name);
|
|
|
|
|
|
- #then calculate the good offset and limit for the complementary search
|
|
|
|
- $fulltxt_offset = $offset - $taxo_results['result count'];
|
|
|
|
-
|
|
|
|
# choose solr query options
|
|
# choose solr query options
|
|
$query_options = array('conjunction'=>'OR', 'parse mode'=>'terms');
|
|
$query_options = array('conjunction'=>'OR', 'parse mode'=>'terms');
|
|
|
|
|
|
#create the solr query for taxonomy search
|
|
#create the solr query for taxonomy search
|
|
$fulltxt_query = search_api_query($fulltxt_index_machine_name, $query_options)
|
|
$fulltxt_query = search_api_query($fulltxt_index_machine_name, $query_options)
|
|
- ->keys($keys)
|
|
|
|
- ->range(($fulltxt_offset > 0 ? $fulltxt_offset : 0), $limit); // change offset to match with the first query (taxonomy)
|
|
|
|
|
|
+ ->keys($keys);
|
|
|
|
|
|
# apply bundle options to solr query if usefull
|
|
# apply bundle options to solr query if usefull
|
|
if(count($bundles_filter)){
|
|
if(count($bundles_filter)){
|
|
@@ -307,9 +292,8 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
|
}
|
|
}
|
|
|
|
|
|
# filter to remove precedent search query
|
|
# filter to remove precedent search query
|
|
- # !!!!!! THIS WILL NOT WORK, IT DOESN'T KNOW THE ITEMS FROM PAGES BEFORE THE CURRENT ONE ...
|
|
|
|
$nid_filter = $fulltxt_query->createFilter('AND');
|
|
$nid_filter = $fulltxt_query->createFilter('AND');
|
|
- foreach ($taxo_total_results['results'] as $nid => $item)
|
|
|
|
|
|
+ foreach ($results['results'] as $nid => $item)
|
|
$nid_filter->condition('nid', $nid, '<>');
|
|
$nid_filter->condition('nid', $nid, '<>');
|
|
|
|
|
|
$fulltxt_query->filter($nid_filter);
|
|
$fulltxt_query->filter($nid_filter);
|
|
@@ -321,21 +305,34 @@ 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");
|
|
|
|
|
|
- # add the full text result count to the taxo result to have the total of items
|
|
|
|
- $taxo_results['result count'] += $fulltxt_results['result count'];
|
|
|
|
|
|
+ # add the fulltext search results to the global results
|
|
|
|
+ $return['results'] += $fulltxt_results['results'];
|
|
|
|
+
|
|
|
|
+ # count global results
|
|
|
|
+ $return['result count'] = count($return['results']);
|
|
|
|
+
|
|
|
|
+ # create items array with the good range
|
|
|
|
+ $return['items'] = array();
|
|
|
|
+
|
|
|
|
+ $i = 0;
|
|
|
|
+ foreach ($return['results'] as $nid => $value) {
|
|
|
|
+ if( $i < $offset )
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ $return['items'][$nid] = node_load($nid);
|
|
|
|
|
|
- # if we are at the end of the first search results list
|
|
|
|
- if($fulltxt_offset >= 0){
|
|
|
|
- $fulltxt_items = $fulltxt_index->loadItems(array_keys($fulltxt_results['results']));
|
|
|
|
- // dsm($fulltxt_items, 'full txt items');
|
|
|
|
- $taxo_results['items'] += $fulltxt_items;
|
|
|
|
|
|
+ $i++;
|
|
|
|
+ if ($i > $offset+$limit)
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
# 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
|
|
|
|
|
|
- return $taxo_results;
|
|
|
|
|
|
+ // dsm($return, 'return');
|
|
|
|
+ return $return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+# 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){
|
|
|
|
|
|
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
|
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|