From e36279d8b19bd14188ab644a423c570d1e97097f Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Wed, 16 Mar 2016 12:35:55 +0100 Subject: [PATCH] changed materio_serach_api, query configuration by query --- .../js/materio_search_api_ajax.js | 6 +-- .../materio_search_api.pages.inc | 38 ++++++++++++++----- .../materio_search_api_ajax.module | 2 +- .../materio_search_api_ajax.pages.inc | 14 ++++--- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/sites/all/modules/gui/materiobasemod/js/materio_search_api_ajax.js b/sites/all/modules/gui/materiobasemod/js/materio_search_api_ajax.js index 7a4aadc2..79da5ddd 100755 --- a/sites/all/modules/gui/materiobasemod/js/materio_search_api_ajax.js +++ b/sites/all/modules/gui/materiobasemod/js/materio_search_api_ajax.js @@ -7,7 +7,7 @@ MaterioSearchApiAjax = function(){ var _isloadingresults = false; var _$content = $('#content'); // TODO: define $content by module settings - + /** * init() */ @@ -188,7 +188,7 @@ MaterioSearchApiAjax = function(){ }; function loadNextResultsPage(href){ - // trace('loadNextResultsPage'); + trace('loadNextResultsPage'); var keys = href.match(/explore\/([^\/|\?]+)/); var page = href.match(/\?page=([0-9]+)/); 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(); }); -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/sites/all/modules/gui/materiobasemod/materio_search_api.pages.inc b/sites/all/modules/gui/materiobasemod/materio_search_api.pages.inc index 8f12499c..96842105 100755 --- a/sites/all/modules/gui/materiobasemod/materio_search_api.pages.inc +++ b/sites/all/modules/gui/materiobasemod/materio_search_api.pages.inc @@ -129,9 +129,19 @@ function materio_search_api_results_search(){ //dsm("materio_search_api_results_search"); // retreive typed words separated by slashes as a sentence - $keys = func_get_args(); + $args = func_get_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 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); } # only breves search (+ related materials) + # not used anymore as free users not exists anymore else if(user_access('use materio search api for breves')){ // dsm('limited search'); $results = msa_solrquery_breves($typed, $language, $user, $offset, $limit); @@ -201,7 +212,7 @@ function materio_search_api_results_search(){ return $ret; } -function msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit){ +function msa_solrquery_materiauxbreves($keys, $language, $user, $offset, $limit){ // dsm($offset, 'offset'); // dsm($limit, 'limit'); @@ -218,21 +229,21 @@ function msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles; - # choose solr query options - $query_options = array('conjunction'=>'OR', 'parse mode'=>'direct'); - - // -- -- taxo search -- -- // + // -- -- 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); + # 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($typed); + ->keys($keys); # apply bundle options to solr query if usefull if(count($bundles_filter)){ @@ -248,11 +259,13 @@ function msa_solrquery_materiauxbreves($typed, $language, $user, $offset, $limit # 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"); - #add range to retriev the real current results + # add range to retriev the real current results $taxo_query->range($offset, $limit); # 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 $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($typed) + ->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 @@ -395,6 +411,8 @@ function msa_solrquery_breves($typed, $language, $user, $offset, $limit){ * materio_search_api_actuality() * */ +# only breves search (+ related materials) +# NOT USED ANYMORE as free users not exists anymore function materio_search_api_actuality(){ global $user; diff --git a/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.module b/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.module index 68ded5fe..d4c184b1 100755 --- a/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.module +++ b/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.module @@ -24,7 +24,7 @@ function materio_search_api_ajax_init() { // ), 'languages' => isset($languages) ? $languages[1] : array(), )), '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'); } /** diff --git a/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.pages.inc b/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.pages.inc index 1b5b7684..1969b657 100755 --- a/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.pages.inc +++ b/sites/all/modules/gui/materiobasemod/materio_search_api_ajax.pages.inc @@ -11,13 +11,17 @@ function materio_search_api_ajax_search($page = 0){ $_GET['page'] = $page; $keys = rawurldecode($_GET['keys']); + // $keys = $_GET['keys']; + // dsm($keys, 'keys'); - foreach(explode(' ', $keys) as $word){ - $words[] = rawurlencode($word); - } - $keys_encoded = implode(' ', $words); + // foreach(explode(' ', $keys) as $word){ + // $words[] = rawurlencode($word); + // } + // $keys_encoded = implode(' ', $words); // dsm($words, 'words'); + $keys_encoded = rawurlencode($keys); + $path = $search_path . '/' . $keys;//. ($page ? '?page='.$page : ''); // 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); } -} \ No newline at end of file +}