Page 1 of 2

Ability to Search by Tags

Posted: 15 Jan 2017, 18:21
by namford
Hi Jan / All,

I saw in a post from you in 2015, that you wanted to enhance Phoca Gallery Search Plugin to be able to Search By Tags. Is this available? If not, is there some hack I can use to make this possible? If anyone can help me with what code to add in which file, I would be very grateful. My request is quite urgent, so I really appreciate if someone can help me implement this.

Thank you!
Namford

Re: Ability to Search by Tags

Posted: 17 Jan 2017, 12:28
by Jan
Hi, the search plugin searches for Phoca Gallery tags since version 4.0.4 so in version 4.2.2 (latest version) this should normaly work :idea:

Jan

Re: Ability to Search by Tags

Posted: 19 Jan 2017, 11:21
by namford
Hi Jan, thanks for replying!

We had 4.0.4, so I just upgraded to 4.2.2 and still not working. Plugin is enabled and we are using smart search (it didn't work with normal search either when we had v4.0.4).

These are the 10 pictures i'm trying to return in the search:
http://phasmidstudygroup.org/index.php/ ... ?tagid=473

tag 473 is "Genus=Lamponius" and 10 photos are tagged with this.

But search returns only 9 photos, because it is searching inphoto name, not tag (and one photo does not have Lamponius in name):
http://phasmidstudygroup.org/index.php/ ... us&Search=

Please could you take a look? I can PM you login details if needed, but obviously won't post them here.

Thank you

Re: Ability to Search by Tags

Posted: 21 Jan 2017, 00:16
by namford
Jan, I'd like to work on fixing this this weekend - please could you reply on this? Thank you

Re: Ability to Search by Tags

Posted: 21 Jan 2017, 00:21
by Jan
Hi, this was addes to standard search not smart search plugin.

switch ($phrase)
{
case 'exact':
$text = $db->quote('%'.$db->escape($text, true).'%', false);
$wheres2 = array();
$wheres2[] = 'a.title LIKE '.$text;
$wheres2[] = 'a.alias LIKE '.$text;
//$wheres2[] = 'a.name LIKE '.$text;
$wheres2[] = 'a.metakey LIKE '.$text;
$wheres2[] = 'a.metadesc LIKE '.$text;
$wheres2[] = 'a.description LIKE '.$text;

Code: Select all

$wheres2[]	= 't.title LIKE '.$text;
				$wheres2[]	= 't.alias LIKE '.$text;
Are the tags Phoca Gallery tags?

Jan

Re: Ability to Search by Tags

Posted: 21 Jan 2017, 00:27
by namford
Thanks Jan. Yes, they are PG tags - you can see them displayed on the images here: http://phasmidstudygroup.org/index.php/ ... ?tagid=473

As mentioned, with v4.0.4, this feature was not working with standard search.

Which property in the code you posted is for the tag? I don't see one called 'tag'.

Re: Ability to Search by Tags

Posted: 22 Jan 2017, 19:12
by namford
Jan / anyone,

I presume I need to add that extra search code to plugins/finder/phocagallery/phocagallery.php, but which function? I can't see a function that looks appropriate for this. Please help, I need to get this working ASAP.

Thank you

Re: Ability to Search by Tags

Posted: 22 Jan 2017, 20:37
by namford
I have modified this as follows - but what do I do next? Also, will this return multiple rows (since we have several tags per image)?

protected function getListQuery($query = null)
{
$db = JFactory::getDbo();
// Check if we can use the supplied SQL query.
$query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
->select('a.id, a.catid, a.title, a.alias, "" AS link, a.description AS summary')
->select('a.metakey, a.metadesc, a.metadata, a.language, a.ordering')
->select('"" AS created_by_alias, "" AS modified, "" AS modified_by')
//->select('"" AS publish_start_date, "" AS publish_end_date')
->select('a.published AS state, a.params, a.approved, 1 as access')
->select('c.title AS category, c.alias as categoryalias, c.published AS cat_state, c.access AS cat_access')
->select('t.title AS tag');

// Handle the alias CASE WHEN portion of the query
$case_when_item_alias = ' CASE WHEN ';
$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
$case_when_item_alias .= ' THEN ';
$a_id = $query->castAsChar('a.id');
$case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
$case_when_item_alias .= ' ELSE ';
$case_when_item_alias .= $a_id.' END as slug';
$query->select($case_when_item_alias);

$case_when_category_alias = ' CASE WHEN ';
$case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
$case_when_category_alias .= ' THEN ';
$c_id = $query->castAsChar('c.id');
$case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':');
$case_when_category_alias .= ' ELSE ';
$case_when_category_alias .= $c_id.' END as catslug';
$query->select($case_when_category_alias)

->from('#__phocagallery AS a')
->join('LEFT', '#__phocagallery_categories AS c ON c.id = a.catid')
->join('LEFT', '#__phocagallery_tagsref AS r ON r.imgid = a.id')
->join('LEFT', '#__phocagallery_tags AS t ON t.id = r.tagid')

->where('a.approved = 1');
return $query;
}

Re: Ability to Search by Tags

Posted: 25 Jan 2017, 23:46
by namford
Jan, please can you help me?

Re: Ability to Search by Tags

Posted: 27 Jan 2017, 19:35
by Jan
Hi, not sure if I didn't misunderstand.

I have talked about searching tags, not about displaying the in search outcome. Now the tags are searched - so if you add some tag from Phoca Gallery to search, the image will be found (but the tag is not displayed in search outcomes)

Not sure if the SQL will return tag, but in every case if it returns some, it will be only one (to get all, e.g. new query needs to be done, or contcat_ws or similar function needs to be used)

Where is the function getListQuery from?