Keyword

[Merged] Joomla Search (Exact Phrase) of K2

More
8 years 2 months ago - 8 years 2 months ago #157864 by ncy
I couldn't find any previous mention of this, so I thought I'd post my findings. With the plugin "Search - K2" enabled, I can search K2 articles with no problem using "All words" and "Any words", but "Exact Phrase" didn't work. I tracked it down to the SQL call in /plugins/search/k2/k2.php. Instead of using "=" in the "where" clause, I changed it to LIKE, and enclosed the $text in '%' chars. This follows the Joomla code in /plugins/search/content/content.php.

The following code worked for me.

Line 104:
if ($phrase == 'exact') {
  $text = JString::trim($text, '"');

  $escaped = K2_JVERSION == '15' ? $db->getEscaped($text, true) : $db->escape($text, true);

  // Enclose in '%' for the LIKE clauses
  $quoted = $db->Quote('%' . $escaped . '%');

  // Change all '=' to 'LIKE'
  $where = " ( LOWER(i.title) LIKE ".$quoted." OR LOWER(i.introtext) LIKE ".$quoted." OR LOWER(i.`fulltext`) LIKE ".$quoted." OR LOWER(i.extra_fields_search) LIKE ".$quoted." OR LOWER(i.image_caption) LIKE ".$quoted." OR LOWER(i.image_credits) LIKE ".$quoted." OR LOWER(i.video_caption) LIKE ".$quoted." OR LOWER(i.video_credits) LIKE ".$quoted." OR LOWER(i.metadesc) LIKE ".$quoted." OR LOWER(i.metakey) LIKE ".$quoted.") ";
}
Last edit: 8 years 2 months ago by ncy.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #157880 by Krikor Boghossian
Replied by Krikor Boghossian on topic [Merged] Joomla Search (Exact Phrase) of K2
Hello and thank you so much for your contribution.

Have you tried the DEV version?
github.com/getk2/k2

It offers improvements in the search functionality.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
8 years 2 months ago #157892 by ncy
You're welcome :). Haven't tried the DEV version yet, been sticking with just the stable version since I am in a production environment.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #157901 by Krikor Boghossian
Replied by Krikor Boghossian on topic [Merged] Joomla Search (Exact Phrase) of K2
It offers several improvements in terms of searching.
Should you use it, please offer some feedback.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #169606 by Martin Hinchliffe
Replied by Martin Hinchliffe on topic [Merged] Joomla Search (Exact Phrase) of K2
A couple of years on this still appears to be a problem, which I find unusual.
I have just applied the fix mentioned above and it really works.

Surely if this is a problem someone would have fixed this?
Or are people doing something else?
Maybe I am not configuring something correctly?

I am using K2 version 2.9 on joomla 3.8

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #169608 by JoomlaWorks
Replied by JoomlaWorks on topic [Merged] Joomla Search (Exact Phrase) of K2
That code is OK. Adding it for the coming update this week. Thanks for reminding us.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 6 years 1 month ago by JoomlaWorks.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #169612 by JoomlaWorks
Replied by JoomlaWorks on topic [Merged] Joomla Search (Exact Phrase) of K2
Merged in 2.9.1. You can get it from: github.com/getk2/k2/archive/master.zip

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #169614 by Martin Hinchliffe
Replied by Martin Hinchliffe on topic [Merged] Joomla Search (Exact Phrase) of K2
Thanks.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #169615 by JoomlaWorks
Replied by JoomlaWorks on topic [Merged] Joomla Search (Exact Phrase) of K2
You're welcome.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum