Searching in the content of posts
I added the content of the posts to the index-sorted.txt file. The content of multiple files is read when creating the cache in function rebuilt_cache
$posts_cache_sorted[] = array_merge(pathinfo($file), ['content' => preg_replace('/\s+/', '', (file_get_contents($file)))]);
And I added content to the search function get_keyword:
$filter = $arr[1] . ' ' . $arr[2] . ' ' . $v['content'];
Thanks! It's a great addition to HTMLy!
I did a quick test of your code on my, nearly empty, HTMLy installation, because I'm new to HTMLy since today. It seems to work fine, but I have two questions:
- Why does the content of each post appear twice in
index-sorted.txt? - What about the
keyword_count()function? You didn't add$v['content']there. Is this ok or a left-over?
Why does the content of each post appear twice in index-sorted.txt?
For me, such a thing does not occur.
There is also a description field in the file with the content. If you don't enter anything in it, HTMLy will put the beginning of the content there. Maybe this is it?
What about the keyword_count() function? You didn't add $v['content'] there. Is this ok or a left-over?
I didn't notice it. 🤦♂️
Without it, pagination of search results does not work properly.
I will post a fix right away - thanks.
Why does the content of each post appear twice in index-sorted.txt?
For me, such a thing does not occur.
There is also a description field in the file with the content. If you don't enter anything in it, HTMLy will put the beginning of the content there. Maybe this is it?
You're right. It is the meta description field. So it's okay.
thanks!
Hello,
Adding each content to the array when rebuilding the index if we have lots of posts it will have big effect in performance.
So the solution, for example, let say we add/edit post A, this post A will automatically added to the search index, if visitor/bot visiting the page it will added to the index either.
And there is a separate admin page to manage this, for example rebuilt the search index per specific posts manually, check which posts have not been indexed etc. and for this search index, it should not in cache folder but content/data folder, similar to views.json.
Edit: separate mean eg. /admin/search similar to admin/config