Active
Project:
Views (for Drupal 7)
Version:
7.x-3.5
Component:
search data
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Jul 2011 at 13:18 UTC
Updated:
23 Oct 2013 at 07:55 UTC
Hello, I would like to show a search result "snippet" and highlight searched terms using an exposed filter, similar to the core search results. Has anyone done this?
Comments
Comment #1
rickmanelius commentedI'm not sure exactly. But here's how one could approach it.
There are probably some other caveats (I'm not sure how easy it would be to do other fields, you have to grab the search term from the view object, etc). But that would be a start.
Comment #2
dawehner#1 sounds like a good plan.
In general this needs custom code at the moment, so good luck with it.
Perhaps you could create some kind of contrib module which everyone can use.
Comment #3
cwyant commentedI was hoping there was an easier way. Basically, I want it to appear similar to the core search results. Can I borrow some code from the search template?
Comment #4
dawehnerNoone prevent you from doing it.
Comment #5
cwyant commentedThis is somewhat beyond me. It's not a big deal, but I would appreciate some help if anyone has the time.
Comment #6
rickmanelius commentedSorry cwyant. I have no use for such a use case and it's way more work than I'm willing to donate. If it's beyond your skills, you can always try to hire it out.
Comment #8
quickly commentedthis is a really useful feature... I wonder why it is not implemented in views... This is such a common requirement, someone should provide a solution to it...
Comment #9
jasonawantHello,
I've put together a rough solution by modifying the following blog post suggestion.
http://www.bigcitydev.com/node/18
1) Create the node template file using your view's row style template name suggestion. For example, if your view name is 'blog_search', create a node template like 'node--view--blog_search.tpl.php'
2) Add a snippet at top of the new node template file to 1) grab the keys from the url query string and 2) send which ever fields you want through the search_excerpt() function using the keys.
Here's an example sending the body through the function.
You could also use this in a view field template like comment#1 suggested, but use the search_exerpt() instead of a regular expression.
Hope that helps someone. I'm sure a more elegant solution can be made.
Jason.
Comment #10
chefnelone commentedI also think this is very useful feature which would be nice to get it working in a simpler way.
Comment #11
nicolas bouteille commentedDefinitely a must according to me too, and not fixed at all as far as I know even though I'm impatient to try solution #9.
Updating the version to current one, switching it back to active, to feature request, to search data.
Comment #12
nicolas bouteille commentedI'd like to add that solutions #1 and #9 were what worked for me for now. Still think this should be a field available on the UI though.
Comment #13
dawehnerDoes someone know whether core search provide that kind of feature?
Comment #14
gChen07 commentedNot fixed at all.. This feature should really be in all search result pages.. I'm thinking about the "Keyword Highlighter" module where you can select text to be highlight.. I think it is possible to just make selected text equal to the search text for the search result to be highlighten also.. Just can't find the right file code to do so.. please help
Comment #15
wOOge commentedRelating to post #9 — here is some updated code to go into your
views-view-field--VIEWNAME--VIEWDISPLAY--field-body.tpl:Comment #16
demonde commentedI suggest to use these variables working for search filter & argument: