SSEP - where determine part of the page

Place for comments, problems, questions, or any issue related to the JavaScript / PHP scripts from this site.
rshweb
Posts:11

SSEP - where determine part of the page

Just one more question
When it displays a part of the pages "Content"
Where does the script determine where in the page to pull the content from?

MarPlo Posts:186
Check the partOfContent() method in the sitesearch.php file.

Code: Select all

// return sub-string around search-words from $content. Receives string $content, and array with words
private function partOfContent($content, $words) {
  $before_after = [5, 9];    // numbers of keys /words [before, after] to get around found key /word

  // clean $content and make it array
  $content = trim(preg_replace(['/ [0-9;"_\-=\'\/\.]+ /i', '/[^'.$this->alchr.' ]/i', '/\s+/i'], ' ', strip_tags($content)));
  $content = explode(' ', $content);
  $max_key = count($content) - 1;
  $key_cnt = [];    // stores keys from $content with $words found

  // set maximum numbers of same word
  $nr_w = count($words);
  if($nr_w == 1) $first_nr = 4;
  else if($nr_w == 2) $first_nr = 3;
  else if($nr_w < 5) $first_nr = 2;
  else $first_nr = 1;

  // get array with keys of $words in $content
  for($i=0; $i<$nr_w; $i++) {
    $keys_f = array_keys(array_map('strtolower',$content), mb_strtolower($words[$i], 'utf-8'));    // all keys found for current word
    $keys_f = array_slice($keys_f, 0, $first_nr);    // keep the first $first_nr
    $nr_kf = count($keys_f);

    // get the keys that form the phrase around each found word /key
    for($i2=0; $i2<$nr_kf; $i2++) {
      $start = max(0, ($keys_f[$i2] - $before_after[0]));
      $end = min(($keys_f[$i2] + $before_after[1]), $max_key);
      for($i3=$start; $i3<=$end; $i3++) $key_cnt[$i3] = 1;
      if(count($key_cnt) > 43) break(2);
    }
  }
  ksort($key_cnt);

  // if less than 20 words for phrase, increments the area around found word (2 from start, 5 from end)
  if(count($key_cnt) < 20) {
    $start = max(0, (key($key_cnt) - 2));
    end($key_cnt);    // move the pointer to last array item
    $end = min((key($key_cnt) + 5), $max_key);
    $key_cnt = [];
    for($i=$start; $i<=$end; $i++) $key_cnt[$i] = 1;
  }

  // build the phrase with rhe words from $content associated to keys in $key_cnt
  $re = '';
  foreach($key_cnt AS $k => $v) $re .= ' '. $content[$k];

  return trim($re);
}
And the following line in the setSearchData() method:

Code: Select all

$resql[$i]['content'] = $this->partOfContent($resql[$i]['content'], $words);   // keep only sub-string of content around $words

rshweb Posts:11
I finally finished up the PHP Resources page
https://rshweb.com/blog-php-resource-tools
And added a few links to this website
Hope that was ok

rshweb Posts:11
just another quick question
The script only indexes 4 or more characters
Can it be set to index 3 or more?
Thanks again

Marius Posts:107
Hello,
Nobody deals with the applications on this site anymore.