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="http://{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>
<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>
Extract and upload to your system/plugins directory.
Updated.
Just tried your updated version and got a lot of broken span and strong tags This is my result html <pre><code>From insights in the activation of the leptin receptor to the design of leptin antagonists </strong>
Leptin.<strong>..</strong> <<strong>/span></strong><span>primarily produced by adipocytes,<strong> and functions in a negative feedback loop acting on neuronal cells.</strong>..<strong> <</strong>/span><strong><span>the hypothalamus.</strong> Inactivating mutations in the leptin or leptin receptor <strong>(LR)</strong> genes lead to a.<strong>..</strong> <<strong>/span>
</span></span></span>[/code]
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.
{exp:zm_excerpt output_wrap="p"}{full_text}{/exp:zm_excerpt}
when I use chunk_wrap=”none” I get this result
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>
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>
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.
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="http://{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.
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!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.