Page 1 of 1

SSEP - where determine part of the page

Posted: 22 Jan 2021, 22:57
by rshweb
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?

SSEP - where determine part of the page

Posted: 23 Jan 2021, 06:52
by MarPlo
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

SSEP - where determine part of the page

Posted: 23 Jan 2021, 23:20
by rshweb
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

Re: SSEP - where determine part of the page

Posted: 20 Oct 2021, 22:48
by rshweb
just another quick question
The script only indexes 4 or more characters
Can it be set to index 3 or more?
Thanks again

SSEP - where determine part of the page

Posted: 21 Oct 2021, 06:34
by Marius
Hello,
Nobody deals with the applications on this site anymore.