Browse Source

changed materio_serach_api, query configuration by query

Bachir Soussi Chiadmi 8 years ago
parent
commit
e36279d8b1

+ 3 - 3
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);
+})(jQuery);

+ 28 - 10
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;
 

+ 1 - 1
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');
 }
 
 /**

+ 9 - 5
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);
   }
-}
+}