4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: WhiteRabbit on August 09, 2005, 06:22:26 PM
-
Hello people:
I'm making a mod to automatically make URLs to search.php to make possible searching fields by direct click on the field's value on the details page.
I added some code to make search.php to take variables from the GET array, and I did put this function to separate the indexed words from the non-indexed ones in the field value:
function create_searchable_words($base) {
$words = split(' ', $base);
foreach ($words as $key => $word) {
if (strlen($word) > MIN_SEARCH_KEYWORD_LENGTH and strlen($word) < MAX_SEARCH_KEYWORD_LENGTH) {
if ($key == 0) {$final_url = $word;}
else {$final_url = $final_url." ".$word;}
}
}
return $final_url;
}
It's working Ok, but I have some problems with the "searchstopterms.txt" words. As you know, the words on that list aren't indexed, even if they enter in the range of MIN_SEARCH_KEYWORD_LENGTH and MAX_SEARCH_KEYWORD_LENGTH .
I think that somewhere in the code there is already a function that makes what I want: separate the searchable words from a string(as the one that I did make), plus removing the words that are at "searchstopterms.txt" from the string.
Anyone knows where it is?.
Thanks in advance.
WR.
-
If I understand you correctly, the string you're looking for is in search.php file
where :
$stopword_list = get_stopwords();
$search_word_cache = array();
for ($i = 0; $i < sizeof($split_words); $i++) {
if ($split_words[$i] == "and" || $split_words[$i] == "und" || $split_words[$i] == "or" || $split_words[$i] == "oder" || $split_words[$i] == "not") {
$search_word_cache[$i] = ($search_terms) ? "and" : $split_words[$i];
}
elseif ($split_words[$i] != "" && strlen($split_words[$i]) >= MIN_SEARCH_KEYWORD_LENGTH && strlen($split_words[$i]) <= MAX_SEARCH_KEYWORD_LENGTH && !in_array($split_words[$i], $stopword_list)) {
As for the general function, you must be looking for the source from includes/search_utils.php file :
function get_stopwords() {
global $config, $stopwords;
if (empty($stopwords)) {
$stopword_list = @file(ROOT_PATH."lang/".$config['language_dir']."/search_stopterms.txt");
$stopwords = array();
if (!empty($stopword_list)) {
foreach ($stopword_list as $word) {
$stopwords[] = trim($word);
}
}
}
return $stopwords;
}
Hope it helps. ;)
-
Thanks!!!! That was just what I was looking for.
The function is now:
function create_searchable_words($base) {
$stopword_list = get_stopwords();
$words = split(' ', $base);
foreach ($words as $key => $word) {
if (strlen($word) > MIN_SEARCH_KEYWORD_LENGTH && strlen($word) < MAX_SEARCH_KEYWORD_LENGTH) {
if (!in_array($word, $stopword_list)) {
if ($key == 0) {$final_url = $word;}
else {$final_url = $final_url." ".$word;}
}
}
}
return $final_url;
}
I did have to move it to search_utils.php (because I was using a function of that file, and require was not working because some variables was overlapping). I used require on the details page, so I can call the function from there.
Thanks again TheOracle!.
Best regards.
WR.
-
Thanks again TheOracle!.
No problem - enjoy ! 8)
As for the requiring field :
require was not working
Perhaps you did not required like the following way :
require (ROOT_PATH.'includes/search_utils.php');
;)
-
Perhaps you did not required like the following way :
require (ROOT_PATH.'includes/search_utils.php');
;)
Hehehe. I was doing it with the exact same sintaxis. But PHP says that cannot redefine some functions... (may be a loop require/include?). I was requiering the file search_utils.php from functions.php, were I originally wrote the above function, that actually uses the function get_stopwords() from search_utils.php .
Now my function is inside search_utils.php , and I'am calling it from details.php. As far as I can see, all is working OK.
Thanks again anyway.
Best regards.
WR.
-
Ahh ! yes, it is more clear now. :)
Perhaps you're looking for to
change :
include(ROOT_PATH.'includes/search_utils.php');
to :
include_once(ROOT_PATH.'includes/search_utils.php');
in search.php file ? ;)
Note: No additional requirements are needed for amending includes/search_utils.php in that file.
I was requiering the file search_utils.php from functions.php,
As for here, no - you must not as it is already imported.
As far as I can see, all is working OK.
Excellent then. ;)