changed materio_serach_api, query configuration by query

This commit is contained in:
Bachir Soussi Chiadmi 2016-03-16 12:35:55 +01:00
parent 0b6e0c10cb
commit e36279d8b1
4 changed files with 41 additions and 19 deletions

View File

@ -7,7 +7,7 @@ MaterioSearchApiAjax = function(){
var _isloadingresults = false; var _isloadingresults = false;
var _$content = $('#content'); var _$content = $('#content');
// TODO: define $content by module settings // TODO: define $content by module settings
/** /**
* init() * init()
*/ */
@ -188,7 +188,7 @@ MaterioSearchApiAjax = function(){
}; };
function loadNextResultsPage(href){ function loadNextResultsPage(href){
// trace('loadNextResultsPage'); trace('loadNextResultsPage');
var keys = href.match(/explore\/([^\/|\?]+)/); var keys = href.match(/explore\/([^\/|\?]+)/);
var page = href.match(/\?page=([0-9]+)/); var page = href.match(/\?page=([0-9]+)/);
var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/'+page[1]; var url = Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/'+page[1];
@ -338,4 +338,4 @@ $(document).ready(function() {
var materiosearchapiajax = new MaterioSearchApiAjax(); var materiosearchapiajax = new MaterioSearchApiAjax();
}); });
})(jQuery); })(jQuery);

View File

@ -129,9 +129,19 @@ function materio_search_api_results_search(){
//dsm("materio_search_api_results_search"); //dsm("materio_search_api_results_search");
// retreive typed words separated by slashes as a sentence // retreive typed words separated by slashes as a sentence
$keys = func_get_args(); $args = func_get_args();
// dsm($args, 'args'); // dsm($args, 'args');
$typed = implode('/', $keys);
$keys = $args;
// $keys = explode(' ',implode(' ',$args));
// dsm($keys, 'keys');
$typed = implode(' ', $keys);
// dsm($typed, 'typed');
# with parse mode terms we use a single string of words seperated by spaces wich will be OR or AND regarding the conjunction query option
# had to add q.op = OR on solr requesthandler on solrconfig.xml
// remove query page params // remove query page params
preg_match_all('/\?page=([0-9]+)/', $typed, $pages); preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
@ -158,6 +168,7 @@ function materio_search_api_results_search(){
$results = msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit); $results = msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit);
} }
# only breves search (+ related materials) # only breves search (+ related materials)
# not used anymore as free users not exists anymore
else if(user_access('use materio search api for breves')){ else if(user_access('use materio search api for breves')){
// dsm('limited search'); // dsm('limited search');
$results = msa_solrquery_breves($typed, $language, $user, $offset, $limit); $results = msa_solrquery_breves($typed, $language, $user, $offset, $limit);
@ -201,7 +212,7 @@ function materio_search_api_results_search(){
return $ret; return $ret;
} }
function msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit){ function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit){
// dsm($offset, 'offset'); // dsm($offset, 'offset');
// dsm($limit, 'limit'); // dsm($limit, 'limit');
@ -218,21 +229,21 @@ function msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit
? $user->data['materiosearchapi_bundlesfilter'] ? $user->data['materiosearchapi_bundlesfilter']
: $default_bundles; : $default_bundles;
# choose solr query options
$query_options = array('conjunction'=>'OR', 'parse mode'=>'direct');
// -- -- taxo search AND -- -- //
// -- -- taxo search -- -- //
# 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);
# choose solr query options
$query_options = array('conjunction'=>'AND', 'parse mode'=>'terms');
#create the solr query for taxonomy search #create the solr query for taxonomy search
$taxo_query = search_api_query($taxo_index_machine_name, $query_options) $taxo_query = search_api_query($taxo_index_machine_name, $query_options)
->keys($typed); ->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)){
@ -248,11 +259,13 @@ function msa_solrquery_materiauxbreves($typed, $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');
#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 # add range to retriev the real current results
$taxo_query->range($offset, $limit); $taxo_query->range($offset, $limit);
# execute solr query and record results # execute solr query and record results
@ -276,9 +289,12 @@ function msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit
#then calculate the good offset and limit for the complementary search #then calculate the good offset and limit for the complementary search
$fulltxt_offset = $offset - $taxo_results['result count']; $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 #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($typed) ->keys($keys)
->range(($fulltxt_offset > 0 ? $fulltxt_offset : 0), $limit); // change offset to match with the first query (taxonomy) ->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
@ -395,6 +411,8 @@ function msa_solrquery_breves($typed, $language, $user, $offset, $limit){
* materio_search_api_actuality() * materio_search_api_actuality()
* *
*/ */
# only breves search (+ related materials)
# NOT USED ANYMORE as free users not exists anymore
function materio_search_api_actuality(){ function materio_search_api_actuality(){
global $user; global $user;

View File

@ -24,7 +24,7 @@ function materio_search_api_ajax_init() {
// ), // ),
'languages' => isset($languages) ? $languages[1] : array(), 'languages' => isset($languages) ? $languages[1] : array(),
)), 'setting'); )), 'setting');
drupal_add_js(drupal_get_path('module', 'materio_search_api_ajax').'/js/materio_search_api_ajax.min.js'); drupal_add_js(drupal_get_path('module', 'materio_search_api_ajax').'/js/materio_search_api_ajax.js');
} }
/** /**

View File

@ -11,13 +11,17 @@ function materio_search_api_ajax_search($page = 0){
$_GET['page'] = $page; $_GET['page'] = $page;
$keys = rawurldecode($_GET['keys']); $keys = rawurldecode($_GET['keys']);
// $keys = $_GET['keys'];
// dsm($keys, 'keys');
foreach(explode(' ', $keys) as $word){ // foreach(explode(' ', $keys) as $word){
$words[] = rawurlencode($word); // $words[] = rawurlencode($word);
} // }
$keys_encoded = implode(' ', $words); // $keys_encoded = implode(' ', $words);
// dsm($words, 'words'); // dsm($words, 'words');
$keys_encoded = rawurlencode($keys);
$path = $search_path . '/' . $keys;//. ($page ? '?page='.$page : ''); $path = $search_path . '/' . $keys;//. ($page ? '?page='.$page : '');
// check if request is ajax, if not rediret to search_api_page page with right keys // check if request is ajax, if not rediret to search_api_page page with right keys
@ -244,4 +248,4 @@ function materio_search_api_ajax_node($nid){
); );
drupal_json_output($rep); drupal_json_output($rep);
} }
} }