WebsiteBaker Community Forum
General Community => Global WebsiteBaker 2.8.x discussion => Topic started 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
-
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
-
i searched the forum but couldnt find it.. but i think I saw it somewhere too :))
thorn, help :))
-
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
-
// 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 :)
-
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.
-
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
-
Hello,
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.
<?php
if(SHOW_SEARCH) {
global $wb;
if(isset($wb->page['language']))
$search_lang = $wb->page['language'];
elseif(isset($_REQUEST['search_lang']))
$search_lang = addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST['search_lang']), ENT_QUOTES));
else
$search_lang = '';
?>
<form name="search" action="<?php echo WB_URL.'/search/index'.PAGE_EXTENSION; ?>" method="post">
<h2><?php echo $TEXT['SEARCH']; ?></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['SUBMIT'])) { echo $TEXT['SEARCH']; } else { echo 'Search'; } ?>" />
</form>
<?php }
?>
Change the file search/search.php (around line 340) [ignore the <?php-markers]:
<?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 = '$module_name' AND p.visibility NOT IN ('none','deleted') AND p.searching = '1' $search_path_SQL
ORDER BY s.section_id, s.position ASC
");
<?php
if(isset($_REQUEST['search_lang'])) {
$search_lang = addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST['search_path']), ENT_QUOTES));
$search_lang_sql = "p.language = '$search_lang' AND";
} else
$search_lang_sql = '';
$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
");
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.
-
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:
<?php
if(SHOW_SEARCH) {
global $wb;
if(isset($wb->page['language']))
$search_lang = $wb->page['language'];
elseif(isset($_REQUEST['search_lang']))
$search_lang = addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST['search_lang']), ENT_QUOTES));
else
$search_lang = '';
?>
<form name="search" action="<?php echo WB_URL.'/search/index'.PAGE_EXTENSION; ?>" method="post">
<h2><?php echo $TEXT['SEARCH']; ?></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['SUBMIT'])) { echo $TEXT['SEARCH']; } else { echo 'Search'; } ?>" />
</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:
<?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 = '$module_name' AND p.visibility NOT IN ('none','deleted') AND p.searching = '1' $search_path_SQL
ORDER BY s.section_id, s.position ASC
");
<?php
if(isset($_REQUEST['search_lang'])) {
$search_lang = addslashes(htmlspecialchars($wb->strip_slashes($_REQUEST['search_path']), ENT_QUOTES));
$search_lang_sql = "p.language = '$search_lang' AND";
} else
$search_lang_sql = '';
$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
");
this code made it work:
$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 :)
-
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):
$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
");
$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
$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
");
$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.
-
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:
$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
-
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...
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
$search_language_sql = "language = '".LANGUAGE."' AND";
EDIT: this is fixed in the above example.
Absent-minded greetings
thorn.
-
Thorn,
It works like a charm !
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