Keyword

[Merged] Joomla Search (Exact Phrase) of K2

More
2 years 3 months ago - 2 years 3 months ago #157864 by ncy
ncy created the topic: [Merged] Joomla Search (Exact Phrase) of K2
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: 2 years 3 months ago by ncy.

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

More
2 years 3 months ago #157880 by Krikor Boghossian
Krikor Boghossian replied the 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.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

More
2 years 3 months ago #157892 by ncy
ncy replied the topic: [Merged] Joomla Search (Exact Phrase) of K2
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.

More
2 years 3 months ago #157901 by Krikor Boghossian
Krikor Boghossian replied the topic: [Merged] Joomla Search (Exact Phrase) of K2
It offers several improvements in terms of searching.
Should you use it, please offer some feedback.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

More
2 months 6 days ago #169606 by Martin Hinchliffe
Martin Hinchliffe replied the 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.

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 6 days ago - 2 months 6 days ago #169608 by Fotis
Fotis replied the topic: [Merged] Joomla Search (Exact Phrase) of K2
That code is OK. Adding it for the coming update this week. Thanks for reminding us.


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member
Last Edit: 2 months 6 days ago by Fotis.

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 6 days ago #169612 by Fotis
Fotis replied the 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


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

More
2 months 6 days ago #169614 by Martin Hinchliffe
Martin Hinchliffe replied the topic: [Merged] Joomla Search (Exact Phrase) of K2
Thanks.

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 6 days ago #169615 by Fotis
Fotis replied the topic: [Merged] Joomla Search (Exact Phrase) of K2
You're welcome.


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

Moderators: william white