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');
|
||||
$offset = pager_find_page() * $limit; //$page*$limit;//
|
||||
// dsm($offset, "offset");
|
||||
|
||||
|
||||
# Normal search
|
||||
if(user_access('use materio search api')){
|
||||
@ -177,7 +179,7 @@ function materio_search_api_results_search(){
|
||||
// for all case
|
||||
$ret['results']['#results'] = $results;
|
||||
$ret['results']['#items'] = $results['items'];
|
||||
$ret['results']['#index'] = $results['index'];
|
||||
// $ret['results']['#index'] = $results['index'];
|
||||
$ret['results']['#theme'] = 'materio_search_api_results';
|
||||
$ret['results']['#keys'] = $typed;
|
||||
$ret['results']['#view_mode'] = $viewmode;
|
||||
@ -230,10 +232,8 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
||||
: $default_bundles;
|
||||
|
||||
|
||||
|
||||
// -- -- taxo search AND -- -- //
|
||||
|
||||
|
||||
# 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);
|
||||
@ -259,43 +259,28 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
||||
# add user access solr query option
|
||||
$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
|
||||
$taxo_total_results = $taxo_query->execute();
|
||||
// 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 -- -- //
|
||||
|
||||
|
||||
#define search api solr index
|
||||
$fulltxt_index_machine_name = variable_get('fulltextsearchindex_'.$language->language, -1);
|
||||
$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
|
||||
$query_options = array('conjunction'=>'OR', 'parse mode'=>'terms');
|
||||
|
||||
#create the solr query for taxonomy search
|
||||
$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
|
||||
if(count($bundles_filter)){
|
||||
@ -307,9 +292,8 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
||||
}
|
||||
|
||||
# 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');
|
||||
foreach ($taxo_total_results['results'] as $nid => $item)
|
||||
foreach ($results['results'] as $nid => $item)
|
||||
$nid_filter->condition('nid', $nid, '<>');
|
||||
|
||||
$fulltxt_query->filter($nid_filter);
|
||||
@ -321,21 +305,34 @@ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit)
|
||||
$fulltxt_results = $fulltxt_query->execute();
|
||||
// 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'];
|
||||
|
||||
# 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;
|
||||
# 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);
|
||||
|
||||
$i++;
|
||||
if ($i > $offset+$limit)
|
||||
break;
|
||||
}
|
||||
|
||||
# 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){
|
||||
|
||||
$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'];?>">
|
||||
<?php //if ($result_count) : ?>
|
||||
<?php if(!$perfascard): ?>
|
||||
<p class="search-performance"><?php print render($search_performance); ?></P>
|
||||
<?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">
|
||||
<?php if(!$perfascard): ?>
|
||||
<p class="search-performance"><?php print render($search_performance); ?></P>
|
||||
<?php endif; ?>
|
||||
|
||||
<p><?php print render($search_performance); ?></P>
|
||||
</div>
|
||||
</article>
|
||||
<?php endif; ?>
|
||||
<?php //dsm($items, '$items'); ?>
|
||||
<?php
|
||||
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
||||
?>
|
||||
<?php if ($result_count) : ?>
|
||||
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php print $pager; ?>
|
||||
<?php //else : ?>
|
||||
<!-- <p class="search-noresults"><?php print t('Your search yielded no results.');?></p> -->
|
||||
<?php //endif; ?>
|
||||
<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>
|
||||
</article>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
||||
?>
|
||||
<?php if ($result_count) : ?>
|
||||
<?php print render(entity_view('node', $items, $variables['view_mode'])); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php print $pager; ?>
|
||||
</div>
|
||||
<?php //endif; ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user