Contents search widget

So, you may add the contents search widget to the blog demo as follows. Here is the diff.

http://code.google.c…rce/detail?r=19

Actually, though this is the enhancement of the yii-blogdemo-enhanced, it can be applied to the original blog demo because this does not related to other enhancements much.

Quote

Actually, though this is the enhancement of the yii-blogdemo-enhanced, it can be applied to the original blog demo because this does not related to other enhancements much.

I have confirmed this. BTW, as I have raised the discussion on a bug as follows, please be careful. I surely am going to fix it.

http://www.yiiframew…pic,2182.0.html

It has been solved. The google code will be fixed shortly.

http://www.yiiframew…pic,2182.0.html

Very Good. I am just about to add my tip on how to add search capability.

Sorry but it may be incomplete.  :cry: I am searching right way to resolve it.

I think I was able to fix the bug. You can see the diff at the google code, but I can show the code central for your reference.

http://code.google.c…rce/detail?r=20

protected/controllers/PostController.php:

New release. :)

I have added the enhancement of high-lighting the searched words. It is better seeing than reading this explanation. Try out this enhanced blog demo, or even simple blog with search.

screenshot:

Posted Image

Just want to say: you are so helpful with your examples/demos

Thank you.

Thank you :D This encourages me a lot!

Won’t formatting break the searching? If you have a single post with the content


something *unexpected*

and you search for “something unexpected”, I suppose there won’t be any match because of the formatting.

It’d be better, if non-word characters were acceptable between search keywords in my opinion.

Yet there will be questions without answers, because if you had a post something like


pointing to an <a href="http://example.com">external</a> site

and you were looking for "external site", searching would not return this post either.

(You probably want to search in pure markdown text, but the case is not different in it either.)

I’m looking forward to hearing your opinion.

Hi pestaa,

I actually had a trouble with markdown languages as you mentioned. At first I tried to search the words in Post.content, but changed my mind to search in Post.contentDisplay with this reason. And I added the functionality to ignore the contents in the tags starting with '<' and ending with '>'. This is the current algorithm. Do you think you may have a better idea?

Your solution is fairly good, although I can still think of an edge case.

Let’s assume we have


dash - between

in our post, now if we tried to search for “dash between”, won’t this script find anything, will it?

Thus I still recommend to accept nonword characters between keywords.