Jump to content

[Solved] How To Modify The "full Text" Search To "sub String" Search? (V1.5.3.1)


SuperDuper

Recommended Posts

I have the same problem.

If I search for "hx20v" it comes back with nothing. But if I search for "dsc-hx20v" it comes with 2 results.

In the back office I do a search for hx20v, comes back with 4 results.

 

Why's the back office search better than the front office search?

 

I'm also using 1.5.3.1

 

Andy

Edited by CameraTek (see edit history)
Link to comment
Share on other sites

Hi,

 

You can use the Alias function.

(Preferences > Search)

 

Hope it helps.

 

Hello, thanks for your reply.

It works, but there are many items in my shop.

Actually I can not add Alias manually for all items.

 

Can we modify the .php to achieve it?

Thanks again.

Link to comment
Share on other sites

Then, you can modify the file (.../classes/search.php) to substring all the searches with (%) variable or whatever you want.

 

From line 190 to 197

 

AND sw.word LIKE
 '.($word[0] == '-'
  ? ' \''.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
  : '\''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
 );
   if ($word[0] != '-')
 $score_array[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';

 

Like this

AND sw.word LIKE
 '.($word[0] == '-'
  ? ' \'%'.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
  : '\'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
 );
   if ($word[0] != '-')
 $score_array[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';

 

But with this the search makes much more effort and the performance probably will be affected or can cause an overload.

it would be better to use something like a wildcard, but I don't know of any on presta.

Link to comment
Share on other sites

Then, you can modify the file (.../classes/search.php) to substring all the searches with (%) variable or whatever you want.

 

From line 190 to 197

 

AND sw.word LIKE
 '.($word[0] == '-'
  ? ' \''.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
  : '\''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
 );
if ($word[0] != '-')
 $score_array[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';

 

Like this

AND sw.word LIKE
 '.($word[0] == '-'
  ? ' \'%'.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
  : '\'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
 );
if ($word[0] != '-')
 $score_array[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';

 

But with this the search makes much more effort and the performance probably will be affected or can cause an overload.

it would be better to use something like a wildcard, but I don't know of any on presta.

 

Wow!! Fantastic, it works.

Now we can search the items in substring text.

Thank you.

 

[sOLVED]

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hi,

 

We've done this and it somehow works but now I have so many results. lol

 

For example:

 

Search term: HP 092A

 

Search results: Brother 350, Brother 360,....... until I go to page 7... and that's the time "HP" appears.

 

What I mean is that - is it possible for the search results to just prioritize the "HP"? Because what happened with the results is that it even though I key in HP, it still displayed "Brother" items.

 

Please help.

Link to comment
Share on other sites

Hi,

 

We've done this and it somehow works but now I have so many results. lol

 

For example:

 

Search term: HP 092A

 

Search results: Brother 350, Brother 360,....... until I go to page 7... and that's the time "HP" appears.

 

What I mean is that - is it possible for the search results to just prioritize the "HP"? Because what happened with the results is that it even though I key in HP, it still displayed "Brother" items.

 

Please help.

 

Did you try to use the weight function? (preferences>search)

you can give a greater weight to the name i.e. (or where you think it would be better)

 

Anyways i do not recomend you to use this code in your case, because it gives a lot of work to the search engine.

instead you can use the tags or the alias to make the search more efficient.

 

Regards.

Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...