Advertisement:

Author Topic: Search only in the title of the article  (Read 87 times)

Gilou26

  • Newbie
  • *
  • Posts: 47
Search only in the title of the article
« 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
« Last Edit: January 11, 2019, 07:54:17 pm by Gilou26 »

Gilou26

  • Newbie
  • *
  • Posts: 47
Re: Search only in the title of the article
« Reply #1 on: January 11, 2019, 07:52:31 pm »
Hello,
Can we modify something in this code to allow a search in the title only?

Code: [Select]
  <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.

Gilou26

  • Newbie
  • *
  • Posts: 47
Re: Search only in the title of the article
« Reply #2 on: January 18, 2019, 07:34:28 pm »
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.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1567
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search only in the title of the article
« Reply #3 on: January 18, 2019, 08:19:21 pm »
You need it as a core mod or as a plugin?

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 541
  • Native Wordpress Widget for Osclass - coming soon
Re: Search only in the title of the article
« Reply #4 on: Today at 12:10:23 am »
Hello,

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) 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:

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');

Well honestly, I have no idea. But you can try it, it may work.  :P

Regards.
« Last Edit: Today at 12:13:05 am by patrickFromCroatia »