1 of 2
1
Plugin: Excerpt
Posted: 01 September 2007 10:58 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

This plugin has been built up from an earlier plugin, with the plan on being an awful lot more efficient and more reliable.

This plugin is designed to be wrapped around the {full_text} variable on your search results template and will return relevant ‘chunks’ of text containing your search terms. Think Google search results.

Parameters:

wrap="”

The html tag name (don’t include the < > parts) to wrap around each highlighted word. The default value is “strong”.

chunk_wrap="”

The html tag name (don’t include the < > parts) to wrap around each relevant ‘chunk’ extracted from the entire {full_text} value. The default value is “span”. If supplied with “none”, nothing will be wrapped around each chunk.

chunk_prepend="”

Data to prepend to each individual chunk returned. This data will be inserted inside the chunk_wrap tags.

chunk_append="”

Like the chunk_prepend parameter, but this inserts the data immediately before the closing chunk_wrap tag. Defaults to ‘… ‘.

output_wrap="”

The html tag name (don’t include the < > parts) to wrap around the entire output. Defaults to nothing.

output_prepend="”

Data to insert in the output, before any chunks but after the opening output_wrap tag, if supplied.

output_append="”

Like the output_prepend parameter, but this will insert the data immediately before the closing output_wrap tag if supplied.

pre_chars="”

The number of characters to include before the highlighted term. Regardless of given value, the pointer will not dissect whole words. The default value is “50”. If given a value such as “50-100” it will choose a random value between 50 and 100.

post_chars="”

The number of characters to include after the hightlighted term. Regardless of given value, the pointer will not dissect whole words. The default value is “50”. If given a value such as “50-100” it will choose a random value between 50 and 100.

chunks="”

The number of relevant chunks to return. Values can be numeric or “all”. The default value is “3”. Setting this parameter to all will return all relevant chunks found.

keywords="”

Instead of acting dynamically, the plugin can be given the search term, or any term, via this parameter.

sort="”

Sort the chunks ascendingly or descendingly from the order in which they were found. values are “asc” or “desc”. Default is “asc”.

order="”

Order the chunks. Currently this parameter accepts only “random”.

Example usage:

(on a search results template)

{exp:search:search_results}
<h2><a href="{auto_path}" title="{title}">{title}</a></h2>
{exp:zm_excerpt output_wrap="p" output_prepend="<dfn>[excerpt] </dfn>"}{full_text}{/exp:zm_excerpt}
{
/exp:search:search_results}

Might return (for each result, on a search for “lorem” in some non-sensical entries)

<h2><a href="http://www.example.com/index.php/template-group/template/nam-tincidunt-pharetra-pede/" title="Nam tincidunt pharetra pede">Nam tincidunt pharetra pede</a></h2>

<
p>
<
dfn>[excerpt] </dfn>
<
span>Curabitur ut tortor. Vivamus nonummy felis a mi. <strong>Lorem</strong> ipsum dolor sit amet, consectetuer adipiscing... </span>
<
span>Aenean lobortis. Proin <strong>lorem</strong>. Aenean nunc nisi, sodales a, tincidunt non,... </span>
<
span>augue purus posuere velit. Cras blandit leo sed <strong>lorem</strong>. Mauris auctor luctus mi. Curabitur erat ante,... </span>
</
p>

Extract and upload to your system/plugins directory.

File Attachments
pi.zm_excerpt.103.zip  (File Size: 6KB - Downloads: 167)
 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 03 September 2007 01:29 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

Updated with new parameters and a single bug fix. Please report any odd results.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 12 September 2007 07:58 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  52
Joined  07-18-2007

Great plugin, works perfect for me.(Till now)
I was just thinking it would be great to have such a plugin. wink

One question: How can I prevent wrapping a tag? I tried chunk_wrap="” without parameters but it still wraps the default tags

 Signature 

“We do not quit playing because we grow old, we grow old because we quit playing” —Ben Franklin

Profile
 
 
Posted: 12 September 2007 09:17 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

Updated.

- Added ‘keywords’ parameter, unrestricting this plugins usage from just the search results template.
- Added sort parameter. (desc/asc) default is ‘asc’.
- Added order parameter, currently only accepts ‘random’
- Removed possible php error with no chunks found.
- Added ability to not wrap chunks with span by using “none” in the chunk_wrap parameter.
- Added ability to create a range of pre/post chars with the effect of each complete excerpt having differing amounts of pre and post text. This helps a page look less ‘machined’.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 12 September 2007 09:51 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  52
Joined  07-18-2007

Just tried your updated version and got a lot of broken span and strong tags
This is my result html

<span>From insights in the activation of the leptin receptor to the design of leptin antagonists
<strong></strong>

Leptin.<strong></strong>..<strong></strong> <<strong></strong>/span><strong></strong><span>primarily produced by adipocytes,<strong></strong> and functions in a negative feedback loop acting on neuronal cells.<strong></strong>..<strong></strong> <<strong></strong>/span><strong></strong><span>the hypothalamus.<strong></strong> Inactivating mutations in the leptin or leptin receptor <strong></strong>(LR)<strong></strong> genes lead to a.<strong></strong>..<strong></strong> <<strong></strong>/span>
   




    
    </
span></span></span>

I’ve left all the spaces and linebreaks from the html output.
And the chunks showing are not the one with the search keyword in it.

 Signature 

“We do not quit playing because we grow old, we grow old because we quit playing” —Ben Franklin

Profile
 
 
Posted: 12 September 2007 10:01 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

Can you show me the parameters you are using? A snippet of the implementation on page will do

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 12 September 2007 10:14 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  52
Joined  07-18-2007

{exp:zm_excerpt output_wrap="p"}{full_text}{/exp:zm_excerpt}

when I use chunk_wrap="none" I get this result

<p>Signalling in the innate immune response
<strong></strong>

Invading pathogens are rapidly sensed by the hosts'<strong></strong>..<strong></strong>. immune system.<strong></strong> The molecular mechanisms underlying pathogen detection and the subsequent cellular.<strong></strong>..<strong></strong> are rapidly being unveiled,<strong></strong> but major knowledge gaps still remain.<strong></strong> We focus on two aspects of the.<strong></strong>..<strong></strong> <<strong></strong>/p>
   
</p>

 Signature 

“We do not quit playing because we grow old, we grow old because we quit playing” —Ben Franklin

Profile
 
 
Posted: 12 September 2007 10:16 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

What happens if you omit that parameter?

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 12 September 2007 10:23 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Avatar
Rank
Total Posts:  52
Joined  07-18-2007

This is the result without any parameters
{exp:zm_excerpt}{full_text}{/exp:zm_excerpt}

<span>Signalling in the innate immune response
<strong></strong>

Invading pathogens are rapidly sensed by the hosts'<strong></strong>..<strong></strong>. <strong></strong></span><strong></strong><span>immune system.<strong></strong> The molecular mechanisms underlying pathogen detection and the subsequent cellular.<strong></strong>..<strong></strong> <<strong></strong>/span><strong></strong><span>are rapidly being unveiled,<strong></strong> but major knowledge gaps still remain.<strong></strong> We focus on two aspects of the.<strong></strong>..<strong></strong> <<strong></strong>/span>
</span></span>

 Signature 

“We do not quit playing because we grow old, we grow old because we quit playing” —Ben Franklin

Profile
 
 
Posted: 12 September 2007 12:48 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

This issue has been fixed in the latest download.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 13 September 2007 04:31 AM   [ Ignore ]   [ # 10 ]  
Grad Student
Avatar
Rank
Total Posts:  52
Joined  07-18-2007

Everything works perfect now but I have a feature request.
When I do a search for a certain word(ie: interact) thats part of another word(ie: interaction) it shows a result but not the excerpt,
could it be possible to show chunks when the word is part of another?

Thanks

 Signature 

“We do not quit playing because we grow old, we grow old because we quit playing” —Ben Franklin

Profile
 
 
Posted: 13 September 2007 05:10 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

I could… but the problem with searching is that it has 4 options - exact phrase / any words / all words / exact word - and the search module doesn’t yet (hint hint for prying eyes) log what type of search you ran. Without knowing that, it is difficult to create an excerpt that would follow the search type that was made.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 17 October 2007 07:05 PM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1457
Joined  03-26-2006

Wow, this looks great. Will give it a shot on my current build. Thanks, the_butcher!

 Signature 

ryan masuga
Masuga DesignMember, EE Pro Network
Peruse my EE Plugins & Extensions

Profile
 
 
Posted: 17 October 2007 07:30 PM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1457
Joined  03-26-2006

I think I’m nuts. I just installed this and put this code on my search results (which were previously working fine, but with no highlighting or anything):

{exp:search:search_results}
<dt><a href="{auto_path}">{title}</a></dt>
{exp:zm_excerpt output_wrap="dd"}{full_text}{/exp:zm_excerpt}
{
/exp:search:search_results}

It’s not returning anything at all - the full text comes back unenclosed by anything. I’ll try re-uploading - any other ideas? Thanks.

 Signature 

ryan masuga
Masuga DesignMember, EE Pro Network
Peruse my EE Plugins & Extensions

Profile
 
 
Posted: 18 October 2007 08:04 AM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1457
Joined  03-26-2006

I got this working with a little help from the_butcher but want to confirm: this does not work with pagination, correct? It is now working on the first page of results, but going to page 2 or 3 ends up with the full text being shown again, and nothing highlighted. This seems to be how almost all the search hilight plugins behave. I’ve tried:

pi.search_hilite.php
pi.search_marker.php
pi.search_term.php
pi.zm_excerpt.php

The only one that seems to work with pagination is the 1st party one, search_hilite - although I like the zm_excerpt one best due to the excerpting, prepending, etc. Should pagination work with this? Thanks!

 Signature 

ryan masuga
Masuga DesignMember, EE Pro Network
Peruse my EE Plugins & Extensions

Profile
 
 
Posted: 18 October 2007 10:12 AM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

It certainly should Ryan, I will delve into this query when I get home and update the thread accordingly smile

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 18 October 2007 10:43 AM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1457
Joined  03-26-2006

Thanks, that would be great. This plugin will make me look like a hero.  cheese

 Signature 

ryan masuga
Masuga DesignMember, EE Pro Network
Peruse my EE Plugins & Extensions

Profile
 
 
Posted: 29 October 2007 12:06 PM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1070
Joined  03-22-2006

This plugin has been updated to version 1.0.3.

Changelog:
- Fixed - Fixed a problem where certain parameter values could have no effect.
- Fixed - Shouldn’t interfere with other code utilising the cache.
- Fixed - Chunk creation should be a little faster.
- Fixed - Fixed an issue where some wrapping tags could break the return string.
- Added - Now checks are made against some safe ‘wrapping’ tags for parameter input.
- Added - Added some default variables as class properties (nearer the top) for easier editing should it be required
- Fixed - Fixed a localisation problem causing no return output.
- Fixed - Fixed an issue where paginated search result would return the complete unparsed input.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 29 October 2007 01:23 PM   [ Ignore ]   [ # 18 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1457
Joined  03-26-2006

This thing is good. Thanks for sending along a “beta” before this release so I could get my project out the door.

 Signature 

ryan masuga
Masuga DesignMember, EE Pro Network
Peruse my EE Plugins & Extensions

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 61010 Total Logged-in Users: 12
Total Topics: 73782 Total Anonymous Users: 8
Total Replies: 398030 Total Guests: 455
Total Posts: 471812    
Members ( View Memberlist )
Newest Members:  kohyeaHRAFFAndrew Doranphantom-am0azamblituxh-nakamurasensakillakynatrocrooter