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
-
- Posts: 10
SSEP - where determine part of the page
MarPlo
Check the partOfContent() method in the sitesearch.php file.
And the following line in the setSearchData() method:
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);
}
Code: Select all
$resql[$i]['content'] = $this->partOfContent($resql[$i]['content'], $words); // keep only sub-string of content around $words
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
https://rshweb.com/blog-php-resource-tools
And added a few links to this website
Hope that was ok
Similar Topics
-
Link to part of another page (not working)
PHP - MySQL
First post
I`m searching for few hours now but can`t find a solution to link to a part off a page ??? I try to use this...Last post
In one comment-page I have this...
It is strange I tried alot things nothing working correctly.
Meight my Question is wrong, Because I try from a page a link to another page but the... -
Delete part of query string from url without page reload
JavaScript - jQuery - Ajax
The delPartUrl() function from the following JavaScript code can be used to delete part of query string from page url in browser, without affecting...
-
SSEP - BUT Cannot save its Page Data
Scripts from this website
First post
Every time I try to index the site it comes back with this message for some of the pages:Last post
BUT Cannot save its Page Data
It indexed 323 pages but...
nice, and nice script, you know what your doing
If you ever want to write a post, article or blog...
Maybe on PHP Resources ?
Id be glad to add it... -
SSEP-Multiple Results from a Single Page
Scripts from this website
First post
Hi,Last post
SSEP - Site Search Engine PHP-Ajax is a great script.
I only wish to index a single page and have multiple search results appear for that...
Hi,
Thanks for clarifying that. Not suitable for my purpose, but still an excellent script.
Regards, -
SSEP - double search results, copy of current page as search result
Scripts from this website
First post
Hi there,Last post
first of all I'd like to say thank you for this nice script.
I have implemented your script into my website:
haushalts-geld.de
and...
Thank you. And you do all that in your free time, amazing. You're awesome.