At long last, we're moving to forums powered by, well, Movable Type itself. You'll want to bookmark http://forums.movabletype.org/ for future reference, and in the meantime you can view these old forums as a read-only archive of past posts. Thanks for being part of the community!
![]() ![]() |
Dec 13 2002, 12:33 PM
Post
#1
|
|
|
Group: Members Posts: 178 Joined: 1-January 02 Member No.: 1,295 |
Is there a way to highlight the search terms on the MTSearch results, like most search engines do? That would be great! As always, Thank You Movable Typers!
-------------------- Joshua Kaufman | unraveled
|
|
|
|
Dec 13 2002, 12:41 PM
Post
#2
|
|
|
Group: Super Administrators Posts: 7,354 Joined: 9-October 01 Member No.: 1,862 |
|
|
|
|
Dec 16 2002, 07:03 PM
Post
#3
|
|
|
Group: Members Posts: 178 Joined: 1-January 02 Member No.: 1,295 |
Thanks, but I'm looking for a way to highlight the search term in the search results, not the archive page when clicking from the search results.
I guess this would involve modifying the actual search code? Come on, I can't be the only one who wants the search results to look like Google's! -------------------- Joshua Kaufman | unraveled
|
|
|
|
Dec 16 2002, 07:12 PM
Post
#4
|
|
|
Group: Super Administrators Posts: 7,354 Joined: 9-October 01 Member No.: 1,862 |
Yeah, I'm using php for it on the ind. archive, and you can't use that in default.tmpl. It definitely would be cool to do! *tracks topic*
|
|
|
|
Dec 16 2002, 07:36 PM
Post
#5
|
|
|
Group: Super Administrators Posts: 15,212 Joined: 8-November 01 From: Plano, Texas Member No.: 1,274 |
####, if someone would just tell me how to make this work on my site, I'd be #### happy!!!!!
-------------------- |
|
|
|
Dec 23 2002, 06:41 AM
Post
#6
|
|
|
Group: Members Posts: 178 Joined: 1-January 02 Member No.: 1,295 |
I just realized that for this to be useful, MT-Search must first have contextual sampling like Google. Right now, when you use MT-Search it simply returns as excerpt from the entry in the search results, which may or may not contain the search term. Before we can think about highlighting terms in the search results, the search results must contain the term, that is, have contextual sampling. Contextual sampling + highlighting the search term = more usable search!
-------------------- Joshua Kaufman | unraveled
|
|
|
|
Dec 23 2002, 06:52 AM
Post
#7
|
|
|
Group: Super Administrators Posts: 7,354 Joined: 9-October 01 Member No.: 1,862 |
You can display the EntryBody in the search results, just edit default.tmpl. The reason the method I'm using doesn't work for what you're looking for is because you can't use php in a .cgi template. So using some other method to highlight should work just fine, though I haven't had a chance to work on this so I don't have anything to offer just now. :p
|
|
|
|
Dec 23 2002, 01:52 PM
Post
#8
|
|
|
Group: Members Posts: 178 Joined: 1-January 02 Member No.: 1,295 |
EntryBody? That's huuuge! The search results page is already long. I wouldn't want to make it any longer.
-------------------- Joshua Kaufman | unraveled
|
|
|
|
Dec 23 2002, 01:56 PM
Post
#9
|
|
|
Group: Super Administrators Posts: 7,354 Joined: 9-October 01 Member No.: 1,862 |
Yeah, I sort of read it wrong what you said. :p *contextual* :)
But I use EntryBody in my search template because mine isn't huge. |
|
|
|
Nov 16 2003, 06:49 PM
Post
#10
|
|
|
Group: Members Posts: 2 Joined: 16-November 03 From: Toronto Member No.: 17,839 |
Anything come of this? The last post in this thread was almost a year ago...
I'm very excited by the potential for: 1. contextual excerpt in the search results (which may be either entry text or comment text) 2. search term highlighting |
|
|
|
Oct 26 2005, 02:31 PM
Post
#11
|
|
|
Group: Members Posts: 45 Joined: 8-August 05 Member No.: 32,419 |
Anything come of this yet? I too am interested in search term highlighting. The last past has now been nearly 2 years.
Thanks -------------------- |
|
|
|
Nov 9 2005, 12:19 PM
Post
#12
|
|
|
Group: Members Posts: 4 Joined: 5-November 05 Member No.: 33,580 |
*bump*
this would be mighty cool. |
|
|
|
Feb 12 2008, 02:15 PM
Post
#13
|
|
|
Group: Members Posts: 3 Joined: 28-January 08 Member No.: 52,268 |
(updated: changed <span> to <em> in MTEntryBody for semantic reasons)
(updated: my URI changed) I think I found a simple solution (tested and working in Movable Type 4.1): It requires the two following plugins: MTTagInvoke and MTRegex (might be working with the new included regex, but I haven't tested that), as well as a single line of CSS. Open your search results template for modification. Place the following code at the top of it: CODE <mt:SetVarBlock name="search_result">(<mt:SearchString regex="s/ /\)\\\|\(/gi" />)</mt:SetVarBlock> In the part of it with the results output change either MTEntryBody or MTExcerpt to: CODE <mt:TagInvoke tag_name="MTEntryBody"><mt:TagInvokeAttribute name="regex">s|<mt:Var name="search_result" />|<em class="highlight">$&</em>|gi</mt:TagInvokeAttribute><mt:TagInvokeAttribute name="words">100</mt:TagInvokeAttribute></mt:TagInvoke> This will give a 100 word excerpt - and highlighted search terms (at least if they are within the first 100 words). If you want to have highlighted title results as well, you'd want to use this for it: CODE <mt:TagInvoke tag_name="MTEntryTitle"><mt:TagInvokeAttribute name="regex">s|<mt:Var name="search_result" />|<em class="highlight">$&</em>|gi</mt:TagInvokeAttribute></mt:TagInvoke> Now open your CSS and put the following code somewhere into it: CODE .highlight { background-color: yellow; } Don't forget saving ;-) Results should be visible immediately. See a live example at my search results page (sorry, shameless self promotion). – Ben This post has been edited by asimaythink: Jun 14 2008, 01:25 AM |
|
|
|
May 24 2008, 09:11 AM
Post
#14
|
|
|
Group: Members Posts: 17 Joined: 14-October 06 Member No.: 37,172 |
This highlights search terms ... and much more.
For example, if I do a search for "Arc de Triomphe" (for my paris blog) I get highlighted results for words such as DEcember and DEcide. Anyway to fix that? Cheers |
|
|
|
Jun 1 2008, 04:30 AM
Post
#15
|
|
|
Group: Members Posts: 3 Joined: 28-January 08 Member No.: 52,268 |
This highlights search terms ... and much more. For example, if I do a search for "Arc de Triomphe" (for my paris blog) I get highlighted results for words such as DEcember and DEcide. Anyway to fix that? Cheers Hello hass, sorry for the late answer. I think you mean only whole words shall be highlighted (bla bla de bla bla but not bla blade bla). My regex searches for ocurrances of the strings, not for words itself. You'd have to modify the regex for this, and this is where it starts to become complicated, as you'd have to define what a word is (not linguistical, rather "what it looks like": a sole string that must be either preceded or followed by a space, except when (partially) embraced in quotes, braces etc., maybe followed by a dot, by comma, by semicolon etc, and all the other gazillion variations over this). So I'm afraid this would be just too complicated. So, yes, there's a way to fix that, but I'm sorry, it's not easy. Once MT 4.2 goes final, I'll surely look into this again as this version has search refined. - Ben |
|
|
|
Jun 8 2008, 07:38 PM
Post
#16
|
|
|
Group: Members Posts: 17 Joined: 14-October 06 Member No.: 37,172 |
This highlights search terms ... and much more. For example, if I do a search for "Arc de Triomphe" (for my paris blog) I get highlighted results for words such as DEcember and DEcide. Anyway to fix that? Cheers Hello hass, sorry for the late answer. I think you mean only whole words shall be highlighted (bla bla de bla bla but not bla blade bla). My regex searches for ocurrances of the strings, not for words itself. You'd have to modify the regex for this, and this is where it starts to become complicated, as you'd have to define what a word is (not linguistical, rather "what it looks like": a sole string that must be either preceded or followed by a space, except when (partially) embraced in quotes, braces etc., maybe followed by a dot, by comma, by semicolon etc, and all the other gazillion variations over this). So I'm afraid this would be just too complicated. So, yes, there's a way to fix that, but I'm sorry, it's not easy. Once MT 4.2 goes final, I'll surely look into this again as this version has search refined. - Ben Thanks Ben No, currently the search pulls up partial word matches too. So, for example, when searching for the word me I see the letters M amd E in camera highligthed. Similarly, if I search for "psu" then I see highlighted Lorem Ipsum. Naturally, this makes the utility of this code somewhat limited since it has the potential to pull up too make false hits. However, if you are going to fix this in the future, please consider two requests in addition to the highlight search terms: First, that the highlighted search terms should be displayed in the context of the sentence that the terms appear in, rather than the entire body of the enry. So for example just show the highlighted terms with 10 words before and 10 words after. Second, that there be a way to selectively limit the search by category and by date range, and ideally a way to sort the search results by date order and number of hits (relevancy) and such. If MT provides this more robust search functionality, and finally makes an easy way for people to re-order their categories list rather than resort to workarounds, that will remove two issues that are unecessarily making life hard! Cheers |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 11.25.09 - 12:13 AM |