WebsiteBaker Community Forum

General Community => Global WebsiteBaker 2.8.x discussion => Topic started by: crnogorac081 on July 18, 2009, 03:43:53 PM

Title: search and languages
Post by: crnogorac081 on July 18, 2009, 03:43:53 PM
can a search function be made something like this:

if page language from which I searc = en,
 then search function shuld search only in the pages with that (en) language ?

cheers
Title: Re: search and languages
Post by: ruebenwurzel on July 18, 2009, 04:00:58 PM
Hello,

yes this is possible. there exist a few non dokumented parameters in search from thorn with wich you can realize this. didn't find the post where it is described, maybe ask thorn.

Matthias

Title: Re: search and languages
Post by: crnogorac081 on July 18, 2009, 04:22:49 PM
i searched the forum but couldnt find it.. but i think I saw it somewhere too :))

thorn, help :))
Title: Re: search and languages
Post by: ruebenwurzel on July 18, 2009, 05:02:54 PM
Hello,

in German, but the posted code should help you:

https://forum.WebsiteBaker.org/index.php/topic,12141.msg73707.html#msg73707 (https://forum.WebsiteBaker.org/index.php/topic,12141.msg73707.html#msg73707)

But there exists another thing too, i know  :?

Matthias
Title: Re: search and languages
Post by: crnogorac081 on July 18, 2009, 10:13:34 PM
Code: [Select]
// looks in modules/module/ and modules/module_searchext/
...
$query = $database->query("SELECT DISTINCT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND directory NOT LIKE '%_searchext' AND LANGUAGE = $search_lang ");


This is from search.php file.. I think it should look like something like this but unfortunately, not working :)

I hope I am on the right path :)
Title: Re: search and languages
Post by: thorn on July 18, 2009, 11:23:17 PM
Hello,

all you have to do is to add the "search_path" parameter to your search query, i.e. http://localhost/search/index.php?search_path=/en/&string=searchstring.

https://forum.WebsiteBaker.org/index.php/topic,12141.msg73707.html#msg73707
shows how to add a customised search-form to your template.

See also https://forum.WebsiteBaker.org/index.php/topic,10058.msg59467.html#msg59467


thorn.
Title: Re: search and languages
Post by: crnogorac081 on July 19, 2009, 01:03:18 AM
Yes, I saw that, but that is if you have site structure like www.localhost/en/english_pages.php and www.localhost/de/deuche_pages.php , than the path parametar determines if the search will work in /en or /de folder, am I correct ?


I used easy miltilanguage snipet, and there I dont have /en and /de folders.. All pages are in menu's root..

for eg.

Page-1 -- page language is EN
Page-2 -- page language is EN

Seite-1 -- page language is DE
Seite-2 -- page language is DE

Now, if I am on page 1 - which has LANGUAGE; = EN, search function should search only in pages which have ?lang=EN at the end of url , like: www.localhost/pages/page-1.php?lang=EN  and not in  www.localhost/pages/seite-1.php?lang=DE
Title: Re: search and languages
Post by: thorn on July 19, 2009, 02:26:09 AM
Hello,

Quote
I used easy miltilanguage snipet, and there I dont have /en and /de folders.. All pages are in menu's root..

yes, you are right. In this case search_path is not what you are looking for.
But as far as i know the LANG parameter is present only while changing from one language to another, isn't it?.
In your case, the language is set in table pages, column language.

Try this (untested): EDIT: Do not use this code! See here (https://forum.WebsiteBaker.org/index.php/topic,14555.msg91574.html#msg91574) for a better solution.

Add a new parameter to the search-form in your Template.
Code: (Template) [Select]
<?php
    
if(SHOW_SEARCH) {
        global 
$wb;
        if(isset(
$wb->page[&#39;language&#39;]))
          
$search_lang $wb->page[&#39;language&#39;];
        
elseif(isset($_REQUEST[&#39;search_lang&#39;]))
          
$search_lang addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST[&#39;search_lang&#39;]), ENT_QUOTES));
        
else
          
$search_lang = &#39;&#39;;
?>

<form name="search" action="<?php echo WB_URL.&#39;/search/index&#39;.PAGE_EXTENSION; ?>" method="post">
<h2><?php echo $TEXT[&#39;SEARCH&#39;]; ?></h2>  
<input type="hidden" name="search_lang" value="<?php echo $search_lang ?>">
<input type="text" name="string" /><br /><br />
<input type="submit" name="submit" value="<?php if(isset($TEXT[&#39;SUBMIT&#39;])) { echo $TEXT[&#39;SEARCH&#39;]; } else { echo &#39;Search&#39;; } ?>" />
</form>
<?php }
?>


Change the file search/search.php (around line 340) [ignore the <?php-markers]:
Code: (Original) [Select]
<?php
$sections_query 
$database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM 
$table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE s.module = &#39;
$module_name&#39; AND p.visibility NOT IN (&#39;none&#39;,&#39;deleted&#39;) AND p.searching = &#39;1&#39; $search_path_SQL
    ORDER BY s.section_id, s.position ASC
"
);
Code: (Changed) [Select]
<?php
if(isset($_REQUEST[&#39;search_lang&#39;])) {
  
$search_lang addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST[&#39;search_path&#39;]), ENT_QUOTES));
  
$search_lang_sql "p.language = &#39;$search_lang&#39; AND";
} else
  
$search_lang_sql = &#39;&#39;;
$sections_query $database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM 
$table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE 
$search_lang_sql s.module = &#39;$module_name&#39; AND p.visibility NOT IN (&#39;none&#39;,&#39;deleted&#39;) AND p.searching = &#39;1&#39; $search_path_SQL
    ORDER BY s.section_id, s.position ASC
"
);

You have to change the search-form on the search-page itself, too (in advanced options).
But first check if the above changes work as expected.


thorn.
Title: Re: search and languages
Post by: crnogorac081 on July 19, 2009, 07:39:57 PM
Hi thorn,

the code didn't work at first, but with some playing i managed to make it work :), at least a part of it.

Here is modifications of your code:


Code: (Template) [Select]
<?php
    
if(SHOW_SEARCH) {
        global 
$wb;
        if(isset(
$wb->page[&#39;language&#39;]))
          
$search_lang $wb->page[&#39;language&#39;];
        
elseif(isset($_REQUEST[&#39;search_lang&#39;]))
          
$search_lang addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST[&#39;search_lang&#39;]), ENT_QUOTES));
        
else
          
$search_lang = &#39;&#39;;
?>

<form name="search" action="<?php echo WB_URL.&#39;/search/index&#39;.PAGE_EXTENSION; ?>" method="post">
<h2><?php echo $TEXT[&#39;SEARCH&#39;]; ?></h2>   
<input type="hidden" name="search_lang" value="<?php echo $search_lang ?>">
<input type="text" name="string" /><br /><br />
<input type="submit" name="submit" value="<?php if(isset($TEXT[&#39;SUBMIT&#39;])) { echo $TEXT[&#39;SEARCH&#39;]; } else { echo &#39;Search&#39;; } ?>" />
</form>
<?php }
?>


Thiw was not required to do, the search can stay as it is. Also in Advanced search options, nothing is required to change.

In this part:

Code: (Original search/search.php) [Select]
<?php
$sections_query 
$database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM 
$table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE s.module = &#39;
$module_name&#39; AND p.visibility NOT IN (&#39;none&#39;,&#39;deleted&#39;) AND p.searching = &#39;1&#39; $search_path_SQL
    ORDER BY s.section_id, s.position ASC
"
);
Code: (Changed) [Select]
<?php
if(isset($_REQUEST[&#39;search_lang&#39;])) {
  
$search_lang addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST[&#39;search_path&#39;]), ENT_QUOTES));
  
$search_lang_sql "p.language = &#39;$search_lang&#39; AND";
} else
  
$search_lang_sql = &#39;&#39;;
$sections_query $database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM 
$table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE 
$search_lang_sql s.module = &#39;$module_name&#39; AND p.visibility NOT IN (&#39;none&#39;,&#39;deleted&#39;) AND p.searching = &#39;1&#39; $search_path_SQL
    ORDER BY s.section_id, s.position ASC
"
);

this code made it work:
Code: (Which worked) [Select]
$search_lang_sql = "p.language = '$search_lang' AND";

$sections_query = $database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM $table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE $search_lang_sql s.module = '$module_name' AND p.visibility NOT IN ('none','deleted') AND p.searching = '1' $search_path_SQL
    ORDER BY s.section_id, s.position ASC
");

It works now, but if you search a whole word. For example if you type: english , and have word "english" in pages on EN and DE, the search result will show only page on one language. But if you type only "eng" , it will show pages in both languages..

Also I think this should be added in the next release of WB, maybe 2.9 , if you choose Page Languages, in search options to choose if you want this seach filtered by language or not..

cheers

p.s.: thorn, you are a god :)
Title: Re: search and languages
Post by: thorn on July 19, 2009, 10:16:44 PM
Hallo,

da habe ich tatsächlich zu umständlich gedacht  :roll:

Die benutzte Anzeigesprache wird tatsächlich in LANGUAGE mitgeschleppt, auch auf der Seite mit den Suchergebnissen, die ja bekanntlich keine echte Seite darstellt [keine page_id hat].

Folglich reicht das hier (Datei search.php):
Code: (Original bei ca. Zeile 340) [Select]
$sections_query = $database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM $table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE s.module = '$module_name' AND p.visibility NOT IN ('none','deleted') AND p.searching = '1' $search_path_SQL
    ORDER BY s.section_id, s.position ASC
");
Code: (geändert) [Select]
$search_language_sql = "p.language = '".LANGUAGE."' AND";
$sections_query = $database->query("
    SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
           p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
           p.visibility, p.viewing_groups, p.viewing_users
    FROM $table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
    WHERE $search_language_sql s.module = '$module_name' AND p.visibility NOT IN ('none','deleted') AND p.searching = '1' $search_path_SQL
    ORDER BY s.section_id, s.position ASC
");

und nochmal etwas tiefer
Code: (Original bei ca. Zeile 430) [Select]
$query_pages = $database->query("
    SELECT page_id, page_title, menu_title, link, description, keywords, modified_when, modified_by,
           visibility, viewing_groups, viewing_users
    FROM $table
    WHERE visibility NOT IN ('none','deleted') AND searching = '1' $search_path_SQL
");
Code: (geändert) [Select]
$search_language_sql = "language = '".LANGUAGE."' AND";
$query_pages = $database->query("
    SELECT page_id, page_title, menu_title, link, description, keywords, modified_when, modified_by,
           visibility, viewing_groups, viewing_users
    FROM $table
    WHERE $search_language_sql visibility NOT IN ('none','deleted') AND searching = '1' $search_path_SQL
");

Bevor man das aber generell in WB übernimmt, müßte man sich nochmal überlegen ob man das immer so haben will, oder nur wenn "Seitensprache" eingeschaltet ist. Denn dann müßte man noch gegen PAGE_LANGUAGES prüfen.


thorn.
Title: Re: search and languages
Post by: crnogorac081 on July 19, 2009, 10:45:36 PM
Hi Thorn,

I dont know a bit of german, but I followed the code, and when I add extra parametar in line ~430:

$search_language_sql = "p.language = '".LANGUAGE."' AND";
$query_pages = $database->query("
    SELECT page_id, page_title, menu_title, link, description, keywords, modified_when, modified_by,
           visibility, viewing_groups, viewing_users
    FROM $table
    WHERE $search_language_sql visibility NOT IN ('none','deleted') AND searching = '1' $search_path_SQL
");

The page design and content breaks below search result.. And when I remove $search_language_sql  from WHERE line , page doesnt break..

wierd... :?

----- Update:

Just turned on error reporting and I got this: Fatal error: Call to a member function numRows() on a non-object in I:\WebsiteBaker Portable1_2\htdocs\wb2\search\search.php on line 454

and that line is:
Code: [Select]
   $search_language_sql = "p.language = '".LANGUAGE."' AND";
    $query_pages = $database->query("
        SELECT page_id, page_title, menu_title, link, description, keywords, modified_when, modified_by,
               visibility, viewing_groups, viewing_users
        FROM $table
        WHERE $search_language_sql visibility NOT IN ('none','deleted') AND searching = '1' $search_path_SQL
    ");
    if($query_pages->numRows() > 0) {     ------------------ THIS IS LINE 454
Title: Re: search and languages
Post by: thorn on July 19, 2009, 11:25:40 PM
I dont know a bit of german, but I followed the code,
Oh sorry, in time of writing i didn't realise that this is an English-speaking thread...

Quote
Just turned on error reporting and I got this: Fatal error: Call to a member function numRows() on a non-object in I:\WebsiteBaker Portable1_2\htdocs\wb2\search\search.php on line 454
Ah, my fault! An copy-n-paste issue  :roll:
On line ~430 p.language has to be language
Code: [Select]
$search_language_sql = "language = '".LANGUAGE."' AND";EDIT: this is fixed in the above example.

Absent-minded greetings
thorn.
Title: Re: search and languages
Post by: crnogorac081 on July 19, 2009, 11:55:35 PM
Thorn,

It works like a charm !

Code: [Select]
Oh sorry, in time of writing i didn't realise that this is an English-speaking thread...

Now all people who speaks deuche can see this.

In combination with Snippet: Easy Multilanguage Link ( https://forum.WebsiteBaker.org/index.php/topic,14037.0.html ) , WB is very powerfull tool for multilanguage sites.

cheers