htmly icon indicating copy to clipboard operation
htmly copied to clipboard

Searching in the content of posts

Open mieszkou opened this issue 3 years ago • 6 comments

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'];

mieszkou avatar May 21 '22 00:05 mieszkou

Thanks! It's a great addition to HTMLy!

Hjertesvikt avatar May 21 '22 05:05 Hjertesvikt

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:

  1. Why does the content of each post appear twice in index-sorted.txt?
  2. What about the keyword_count() function? You didn't add $v['content'] there. Is this ok or a left-over?

bttrx avatar May 22 '22 11:05 bttrx

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.

mieszkou avatar May 22 '22 14:05 mieszkou

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.

bttrx avatar May 22 '22 15:05 bttrx

thanks!

dirmanhana avatar Jun 02 '22 05:06 dirmanhana

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

danpros avatar Dec 27 '23 01:12 danpros