Author Topic: Removing the search_stopterms words from a string.  (Read 6093 times)

0 Members and 1 Guest are viewing this topic.

Offline WhiteRabbit

  • Newbie
  • *
  • Posts: 29
    • View Profile
Removing the search_stopterms words from a string.
« 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:

Code: [Select]
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.

TheOracle

  • Guest
Re: Removing the search_stopterms words from a string.
« Reply #1 on: August 09, 2005, 07:51:52 PM »
If I understand you correctly, the string you're looking for is in search.php file

where :

Quote

$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 :

Quote

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. ;)

Offline WhiteRabbit

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Removing the search_stopterms words from a string.
« Reply #2 on: August 10, 2005, 02:58:39 AM »
Thanks!!!! That was just what I was looking for.

The function is now:

Code: [Select]
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.

TheOracle

  • Guest
Re: Removing the search_stopterms words from a string.
« Reply #3 on: August 10, 2005, 03:14:58 AM »
Quote

Thanks again TheOracle!.


No problem - enjoy ! 8)

As for the requiring field :

Quote

require was not working


Perhaps you did not required like the following way :

Code: [Select]

require (ROOT_PATH.'includes/search_utils.php');


;)

Offline WhiteRabbit

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Removing the search_stopterms words from a string.
« Reply #4 on: August 10, 2005, 04:11:09 AM »

Perhaps you did not required like the following way :

Code: [Select]

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.

TheOracle

  • Guest
Re: Removing the search_stopterms words from a string.
« Reply #5 on: August 10, 2005, 04:13:49 AM »
Ahh ! yes, it is more clear now. :)

Perhaps you're looking for to

change :

Quote

include(ROOT_PATH.'includes/search_utils.php');


to :

Code: [Select]

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.

Quote

I was requiering the file search_utils.php from functions.php,


As for here, no - you must not as it is already imported.

Quote

As far as I can see, all is working OK.


Excellent then. ;)

 

Post your comments here