Osclass forums
		Support forums => General help => Topic started by: Gilou26 on December 10, 2018, 06:01:32 pm
		
			
			- 
				Hello,
 I use the Osclasswizzards theme 2.0.6 with Osclass 3.8.
 The searches are done in the description and the title of the article.
 I would like the search to be on the title of the article only.
 Is it possible?
 Thanks in advance
- 
				Hello,
 Can we modify something in this code to allow a search in the title only?
 
   <div class="banner_none" id="form_vh_map">
 <form action="<?php echo osc_base_url(true); ?>" id="main_search" method="get" class="search nocsrf" >
 <div class="container">
 <input type="hidden" name="page" value="search"/>
 <div class="main-search">
 <div class="form-filters">
 <div class="row">
 <?php $showCountry  = (osc_get_preference('show_search_country', 'osclasswizards_theme') == '1') ? true : false; ?>
 <div class="col-md-<?php echo ($showCountry)? '3' : '4'; ?>">
 <div class="cell">
 <input type="text" name="sPattern" id="query" class="input-text" value="" placeholder="<?php echo osc_esc_html(__(osc_get_preference('keyword_placeholder', 'osclasswizards_theme'), OSCLASSWIZARDS_THEME_FOLDER)); ?>" />
 </div>
 </div>
 <div class="col-md-2">
 <?php  if ( osc_count_categories() ) { ?>
 <div class="cell selector">
 <?php cs_category_select_with_count('sCategory', null, __('Ou selectionnez une catégorie de rosier', 'osclasswizards')) ; ?>
 </div>
 <?php  } ?>
 </div>
 <div class="cell reset-padding">
 <button  class="btn btn-success btn_search"><i class="fas fa-search"></i> <span <?php echo ($showCountry)? '' : 'class="showLabel"'; ?>><?php echo osc_esc_html(__("Recherchez", OSCLASSWIZARDS_THEME_FOLDER));?></span> </button>
 </div>
 </div>
 </div>
 </div>
 </div>
 </div>
 </form>
 </div>
 Thanks for your help.
- 
				Hello,
 I contacted Osclass with the contact form on their site, but I did not get an answer.
 Does anyone know another contact I can contact to solve my problem?
 It is very important for me to limit the search in the title only.
 Thank you in advance for your answer.
- 
				You need it as a core mod or as a plugin?
			
- 
				Hello,
 
 First solution fixed, works.
 
 I checked the search model file, don't see any hooks in makeSQL function. If you want a core mod, I think replacing
 "$this->dao->where(sprintf("MATCH(d.s_title, d.s_description) AGAINST('%s' IN BOOLEAN MODE)", $this->sPattern) );"
 with
 "$this->dao->where(sprintf("MATCH(d.s_title) AGAINST('%s' IN BOOLEAN MODE)", $this->sPattern) );"
 in oc-includes/osclass/model/Search.php may work.
 
 But what if we use 'search_conditions' hook and change "sPattern" in theme files with something like "sKeyword" and then add this function:
 
 <?php
 function wm_search_keyword_title($params) {
 foreach($params as $key => $value) {
 switch($key) {
 case 'sKeyword':
 Search::newInstance()->join(DB_TABLE_PREFIX.'t_item_description as d','d.fk_i_item_id = '.DB_TABLE_PREFIX.'t_item.pk_i_id','LEFT');
 Search::newInstance()->addConditions(sprintf("MATCH(d.s_title, d.s_description) AGAINST('%s' IN BOOLEAN MODE)", $value));
 if(OC_ADMIN) {
 $locale_code[osc_current_admin_locale()] = osc_current_admin_locale();
 } else {
 $locale_code[osc_current_user_locale()] = osc_current_user_locale();
 }
 $this->dao->where(sprintf("( d.fk_c_locale_code LIKE '%s' )", implode("' d.fk_c_locale_code LIKE '", $locale_code)));
 break;
 default:
 break;
 }
 }
 }
 osc_add_hook('search_conditions', 'wm_search_keyword_title');
 
 Well honestly, I have no idea. But you can try it, it may work.  :P
 
 Regards.
- 
				Hello,
 Thank you both for your interest in my problem.
 Excuse my ignorance, but what do you mean by "core mod or as a plugin".
 @patrickFromCroatia:
 
 "$this->dao->where(sprintf("MATCH(d.s_title) AGAINST('%s' IN BOOLEAN MODE)", $this->sPattern) );"
 with
 "$this->dao->where(sprintf("MATCH(d.s_title) AGAINST('%s' IN BOOLEAN MODE)", $this->sPattern) );"
 in oc-includes/osclass/model/Search.php may work
 The two lines are identical, so I deleted "d.s_description" in my line of code, but it does not work.
 
 Can you tell me exactly which files I have to intervene to do these tests?
 
 But what if we use 'search_conditions' hook and change "sPattern" in theme files with something like "sKeyword" and then add this function:
 
 Code: [Select]
 
 <?php
 function wm_search_keyword_title($params) {
 foreach($params as $key => $value) {
 switch($key) {
 case 'sKeyword':
 Search::newInstance()->join(DB_TABLE_PREFIX.'t_item_description as d','d.fk_i_item_id = '.DB_TABLE_PREFIX.'t_item.pk_i_id','LEFT');
 Search::newInstance()->addConditions(sprintf("MATCH(d.s_title, d.s_description) AGAINST('%s' IN BOOLEAN MODE)", $value));
 if(OC_ADMIN) {
 $locale_code[osc_current_admin_locale()] = osc_current_admin_locale();
 } else {
 $locale_code[osc_current_user_locale()] = osc_current_user_locale();
 }
 $this->dao->where(sprintf("( d.fk_c_locale_code LIKE '%s' )", implode("' d.fk_c_locale_code LIKE '", $locale_code)));
 break;
 default:
 break;
 }
 }
 }
 osc_add_hook('search_conditions', 'wm_search_keyword_title');
 Thank you both again.
- 
				Hello,
 All my excuses.
 I have two lines (822 and 943) that contain the code:
 "$ this-> dao-> where (sprintf (" MATCH (d.s_title, d.s_description) AGAINST ('% s' IN BOOLEAN MODE) ", $ this-> sPattern));"
 which I replaced by:
 "$ this-> dao-> where (sprintf (" MATCH (d.s_title) AGAINST ('% s' IN BOOLEAN MODE) ", $ this-> sPattern));"
 
 I modified a single line, that's why it did not work.
 
 Now it works perfectly.
 
 Thank you for you precious help.
- 
				Glad it worked! Yes I meant to remove d.s_description but I copied a wrong line.
 
 Regards.
- 
				What was the reason for this? The search was too lazy?
			
- 
				What was the reason for this? The search was too lazy?
 
 
 Are you asking @Gilou26 or me? And what do you mean? :)
 
 Regards.
- 
				 I ask him. Why this feature?
			
- 
				Hello,
 My website is a database about roses.
 When a visitor was looking for a rose, the results were not accurate, because in some descriptions, we can refer to other roses. So the search results were skewed.
 Regards
- 
				Thanks. I thought it was a duration related reason.