Advertisement:

Author Topic: [Solved] Search only in the title of the article  (Read 420 times)

Gilou26

  • Jr. Member
  • **
  • Posts: 77
[Solved] 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 19, 2019, 12:47:55 pm by Gilou26 »

Gilou26

  • Jr. Member
  • **
  • Posts: 77
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

  • Jr. Member
  • **
  • Posts: 77
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: 1619
  • "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: 763
Re: Search only in the title of the article
« Reply #4 on: January 19, 2019, 12:10:23 am »
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:

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: January 19, 2019, 01:38:55 pm by patrickFromCroatia »

Gilou26

  • Jr. Member
  • **
  • Posts: 77
Re: Search only in the title of the article
« Reply #5 on: January 19, 2019, 11:14:52 am »
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:

Code: [Select]
"$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?

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

Gilou26

  • Jr. Member
  • **
  • Posts: 77
Re: Search only in the title of the article
« Reply #6 on: January 19, 2019, 12:46:25 pm »
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.

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 763
Re: [Solved] Search only in the title of the article
« Reply #7 on: January 19, 2019, 01:37:58 pm »
Glad it worked! Yes I meant to remove d.s_description but I copied a wrong line.

Regards.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1619
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: [Solved] Search only in the title of the article
« Reply #8 on: January 19, 2019, 09:34:05 pm »
What was the reason for this? The search was too lazy?

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 763
Re: [Solved] Search only in the title of the article
« Reply #9 on: January 20, 2019, 01:31:39 am »
What was the reason for this? The search was too lazy?

Are you asking @Gilou26 or me? And what do you mean? :)

Regards.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1619
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: [Solved] Search only in the title of the article
« Reply #10 on: January 20, 2019, 10:16:26 am »
 I ask him. Why this feature?

Gilou26

  • Jr. Member
  • **
  • Posts: 77
Re: [Solved] Search only in the title of the article
« Reply #11 on: January 20, 2019, 11:44:10 am »
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

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1619
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: [Solved] Search only in the title of the article
« Reply #12 on: January 20, 2019, 11:55:02 am »
Thanks. I thought it was a duration related reason.