[Fixed] Search with no result, related to language ?

More
12 years 6 months ago #26198 by mazataza
when activating lang filter the flexicontent doesn't return any result. i found the part of the code which case the problem, may you could find better solution:
Code:
### Eclipse Workspace Patch 1.0 #P INF Index: plugins/search/flexisearch/flexisearch.php =================================================================== --- plugins/search/flexisearch/flexisearch.php (revision 4) +++ plugins/search/flexisearch/flexisearch.php (working copy) @@ -1,6 +1,6 @@ <?php /** - * @version 1.0 $Id: flexisearch.php 677 2011-07-24 15:19:52Z ggppdk $ + * @version 1.0 $Id: flexisearch.php 1147 2012-02-22 08:24:48Z ggppdk $ * @package Joomla * @subpackage FLEXIcontent * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr @@ -119,9 +119,9 @@ // Get language, joomfish or J1.7+ language selector will append lang variable to the URL $lang = JRequest::getWord('lang', '' ); + $langFactory= JFactory::getLanguage(); + $tagLang = $langFactory->getTag(); if(empty($lang)){ - $langFactory= JFactory::getLanguage(); - $tagLang = $langFactory->getTag(); //Well, the substr is not even required as flexi saves the Joomla language tag... so we could have kept the $tagLang tag variable directly. $lang = substr($tagLang ,0,2); } @@ -180,9 +180,9 @@ if (in_array('FlexisearchTitle', $searchAreas)) {$wheres2[] = 'a.title LIKE '.$text;} if (in_array('FlexisearchDesc', $searchAreas)) {$wheres2[] = 'a.introtext LIKE '.$text; $wheres2[] = 'a.fulltext LIKE '.$text;} if (in_array('FlexisearchMeta', $searchAreas)) {$wheres2[] = 'a.metakey LIKE '.$text; $wheres2[] = 'a.metadesc LIKE '.$text;} - if (in_array('FlexisearchFields', $searchAreas)) {$wheres2[] = "f.field_type='text' AND f.issearch=1 AND fir.value LIKE ".$word;} + if (in_array('FlexisearchFields', $searchAreas)) {$wheres2[] = "f.field_type='text' AND f.issearch=1 AND fir.value LIKE ".$text;} if (in_array('FlexisearchTags', $searchAreas)) {$wheres2[] = 't.name LIKE '.$text;} - $where = '(' . implode(') OR (', $wheres2) . ')'; + if (count($wheres2)) $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': @@ -197,12 +197,15 @@ if (in_array('FlexisearchMeta', $searchAreas)) {$wheres2[] = 'a.metakey LIKE '.$word; $wheres2[] = 'a.metadesc LIKE '.$word;} if (in_array('FlexisearchFields', $searchAreas)) {$wheres2[] = "f.field_type='text' AND f.issearch=1 AND fir.value LIKE ".$word;} if (in_array('FlexisearchTags', $searchAreas)) {$wheres2[] = 't.name LIKE '.$word;} - $wheres[] = '(' . implode(') OR (', $wheres2) . ')'; + if (count($wheres2)) $wheres[] = '(' . implode(') OR (', $wheres2) . ')'; } - $where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')'; + if (count($wheres)) { + $where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')'; + } break; } if (!$where) {return array();} + //if ( empty($where) ) $where = '1'; switch ($ordering) { case 'oldest': @@ -253,8 +256,8 @@ // filter by active language $andlang = ''; if ($app->isSite() && $app->getLanguageFilter() && $filter_lang) { - $andlang .= ' AND a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'; - $andlang .= ' AND c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'; + $andlang .= ' AND a.language in (' . $db->Quote($tagLang) . ',' . $db->Quote('*') . ')'; + $andlang .= ' AND c.language in (' . $db->Quote($tagLang) . ',' . $db->Quote('*') . ')'; } // search articles @@ -265,38 +268,38 @@ $query->clear(); $query->select( ' a.id as id, ' - .'a.title AS title, ' - .'a.metakey AS metakey, ' - .'a.metadesc AS metadesc, ' - .'a.modified AS created, ' // TODO ADD a PARAMETER FOR CONTROLING the use of modified by or created by date as "created" - .'t.name AS tagname, ' - .'fir.value as field, ' - .'CONCAT(a.introtext, a.fulltext) AS text, ' - .' CONCAT_WS( " / ", '. $db->Quote( JText::_( 'FLEXICONTENT' ) ) .', c.title, a.title ) AS section, ' - .'CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END AS slug, ' - .'CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug, ' - .'"2" AS browsernav ' + .' a.title AS title,' + .' a.metakey AS metakey,' + .' a.metadesc AS metadesc,' + .' a.modified AS created,' // TODO ADD a PARAMETER FOR CONTROLING the use of modified by or created by date as "created" + .' t.name AS tagname,' + .' fir.value as field,' + .' CONCAT(a.introtext, a.fulltext) AS text,' + .' CONCAT_WS( " / ", '. $db->Quote( JText::_( 'FLEXICONTENT' ) ) .', c.title, a.title ) AS section,' + .' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END AS slug,' + .' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug,' + .' "2" AS browsernav' ); $query->from('#__content AS a ' - .'LEFT JOIN #__flexicontent_items_ext AS ie ON a.id = ie.item_id ' - .'LEFT JOIN #__flexicontent_fields_item_relations AS fir ON a.id = fir.item_id ' - .'LEFT JOIN #__categories AS c ON a.catid = c.id ' - .'LEFT JOIN #__flexicontent_tags_item_relations AS tir ON a.id = tir.itemid ' - .'LEFT JOIN #__flexicontent_fields AS f ON fir.field_id = f.id ' - .'LEFT JOIN #__flexicontent_tags AS t ON tir.tid = t.id ' + .' LEFT JOIN #__flexicontent_items_ext AS ie ON a.id = ie.item_id' + .' LEFT JOIN #__flexicontent_fields_item_relations AS fir ON a.id = fir.item_id' + .' LEFT JOIN #__categories AS c ON a.catid = c.id' + .' LEFT JOIN #__flexicontent_tags_item_relations AS tir ON a.id = tir.itemid' + .' LEFT JOIN #__flexicontent_fields AS f ON fir.field_id = f.id' + .' LEFT JOIN #__flexicontent_tags AS t ON tir.tid = t.id ' . $joinaccess ); $query->where(' ('. $where .') ' - .'AND ie.type_id IN('.$types.') ' - .'AND a.state IN (1, -5) AND c.published = 1 ' - .'AND (a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).') ' - .'AND (a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).') ' - . $andaccess - // Filter by language - . $andlang + .' AND ie.type_id IN('.$types.') ' + .' AND a.state IN (1, -5) AND c.published = 1 ' + .' AND (a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).') ' + .' AND (a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).') ' + . $andaccess // Filter by user access + . $andlang // Filter by current language ); $query->group('a.id'); $query->order($order); + //die( "<pre>".$query."</pre>"); $db->setQuery($query, 0, $limit); $list = $db->loadObjectList();

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

More
12 years 6 months ago #26207 by ggppdk
In J1.5 you should enable language filter if you have items with different language, but not if you use Joomfish to translate items

Please provide more details


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

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

More
12 years 5 months ago #26231 by mazataza
I used Joomla 2.5 and not J1.5 the site has worked bevore i update to latest FLEXIContent - 2.0 - RC5 r1338 (i can't remember which RC i used bevore.

All artilces are assigned to specific langauge and I don't use joomfish.

in flexisearch.php you will notice that this
Code:
// filter by active language $andlang = ''; if ($app->isSite() && $app->getLanguageFilter() && $filter_lang) { $andlang .= ' AND a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'; $andlang .= ' AND c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'; }

that the variable
Code:
$tag
is not initialized elsewhere thus will be replaced with an empty string and the the SQL will not find any item which is assigned to a langauge.

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

More
12 years 5 months ago #26232 by ggppdk
Yes,
Replace
Code:
$andlang .= ' AND a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'; $andlang .= ' AND c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')';
with
Code:
$andlang .= ' AND ( a.language LIKE ' . $db->Quote( $lang .'%' ) . ' OR a.language="*" ) '; $andlang .= ' AND ( c.language LIKE ' . $db->Quote( $lang .'%' ) . ' OR c.language="*" ) ';

Currently we are working on standard and advanced search


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

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

More
12 years 5 months ago #26234 by mazataza
it hasn't worked with using
Code:
$andlang .= ' AND ( a.language LIKE ' . $db->Quote($lang .'%' ) . ' OR a.language="*" ) '; $andlang .= ' AND ( c.language LIKE ' . $db->Quote($lang .'%' ) . ' OR c.language="*" ) ';

but worked by adding:
Code:
$tag = JFactory::getLanguage()->getTag();

the reason, is the variable "$lang" has ony the first part of lang tag. for example for arabic ar-SA the language tag is "ar-SA" but $lang is just "ar", thus no result will be found.

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

More
12 years 5 months ago #26235 by ggppdk
Actually it should work unless you have disabled lang variable in the URL, or maybe i have a different local flexisearch.php file

This is done in System plugin:
System - Language Filter
-- Remove URL Language Code
setting this to "No" will append the lang variable in the URL and the code i provided will work.

I see now that in J2.5
$tag = JFactory::getLanguage()->getTag();
return the current active language, this was not the case in J1.5, which did not natively support switching frontend language and Joomfish was needed for this.

This means that we do not need to enable the lang variable in the URL.

Thus the best code would be:
Code:
// filter by active language $andlang = ''; $lang = substr(JFactory::getLanguage()->getTag(), 0,2); if ($app->isSite() && $app->getLanguageFilter() && $filter_lang) { $andlang .= ' AND ( a.language LIKE ' . $db->Quote( $lang .'%' ) . ' OR a.language="*" ) '; $andlang .= ' AND ( c.language LIKE ' . $db->Quote( $lang .'%' ) . ' OR c.language="*" ) '; }


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

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

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.347 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline