fixed and refactored solr search main function
This commit is contained in:
parent
7b11f2794e
commit
39dc81ad14
@ -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
|
$return = array(
|
||||||
$taxo_query->range($offset, $limit);
|
"results" => $taxo_total_results['results']
|
||||||
|
);
|
||||||
# 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -- -- 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)
|
->keys($keys);
|
||||||
->range(($fulltxt_offset > 0 ? $fulltxt_offset : 0), $limit); // change offset to match with the first query (taxonomy)
|
|
||||||
|
|
||||||
# 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
|
# add the fulltext search results to the global results
|
||||||
$taxo_results['result count'] += $fulltxt_results['result count'];
|
$return['results'] += $fulltxt_results['results'];
|
||||||
|
|
||||||
# if we are at the end of the first search results list
|
# count global results
|
||||||
if($fulltxt_offset >= 0){
|
$return['result count'] = count($return['results']);
|
||||||
$fulltxt_items = $fulltxt_index->loadItems(array_keys($fulltxt_results['results']));
|
|
||||||
// dsm($fulltxt_items, 'full txt items');
|
# create items array with the good range
|
||||||
$taxo_results['items'] += $fulltxt_items;
|
$return['items'] = array();
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
foreach ($return['results'] as $nid => $value) {
|
||||||
|
if( $i < $offset )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$return['items'][$nid] = node_load($nid);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
@ -31,37 +31,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<?php //dsm($index, 'index'); ?>
|
|
||||||
<?php //dsm($search_performance, 'search_performance'); ?>
|
|
||||||
<?php //dsm($result_count, 'result_count'); ?>
|
|
||||||
|
|
||||||
<?php //if (!empty($result_count)) : ?>
|
|
||||||
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
|
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
|
||||||
<?php //if ($result_count) : ?>
|
<?php if(!$perfascard): ?>
|
||||||
<?php if(!$perfascard): ?>
|
<p class="search-performance"><?php print render($search_performance); ?></P>
|
||||||
<p class="search-performance"><?php print render($search_performance); ?></P>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
|
||||||
<?php //print render($spellcheck); ?>
|
|
||||||
<div class="search-results">
|
|
||||||
<?php if($perfascard): ?>
|
|
||||||
<article class="search-performance <?php print ' view-mode-' . $variables['view_mode'];?>">
|
|
||||||
<div class="inner">
|
|
||||||
|
|
||||||
<p><?php print render($search_performance); ?></P>
|
<div class="search-results">
|
||||||
</div>
|
<?php if($perfascard): ?>
|
||||||
</article>
|
<article class="search-performance <?php print ' view-mode-' . $variables['view_mode'];?>">
|
||||||
<?php endif; ?>
|
<div class="inner">
|
||||||
<?php //dsm($items, '$items'); ?>
|
<p><?php print render($search_performance); ?></P>
|
||||||
<?php
|
</div>
|
||||||
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
</article>
|
||||||
?>
|
<?php endif; ?>
|
||||||
<?php if ($result_count) : ?>
|
<?php
|
||||||
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
|
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
||||||
<?php endif; ?>
|
?>
|
||||||
</div>
|
<?php if ($result_count) : ?>
|
||||||
<?php print $pager; ?>
|
<?php print render(entity_view('node', $items, $variables['view_mode'])); ?>
|
||||||
<?php //else : ?>
|
<?php endif; ?>
|
||||||
<!-- <p class="search-noresults"><?php print t('Your search yielded no results.');?></p> -->
|
</div>
|
||||||
<?php //endif; ?>
|
|
||||||
|
<?php print $pager; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php //endif; ?>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user