Hi, thanks for all your great work on Search API. I'm working on porting Fuzzy Search to Search API. I need to be able to create a result excerpt based on the search terms so I can use fuzzy highlighting.

I'd like to provide an alternate fuzzy excerpt or maybe even fuzzy fulltext view mode for the Search pages module. Then I'd like to be able to reuse my highlighting algorithms in the Search api views module.

It seems I could alter the search_api_page add and edit forms to add my options, and then alter the theme registry to take over the preprocessing, but maybe there's a way to do this built in that I'm missing?

I saw #1064520: Add a processor for highlighting, which makes me think one way to do this would be to add a hook in search_pages so modules can provide new view modes, and then let the module put it in $results[]['excerpt'].

So to sum up 2 ideas.
1. Let modules add new view mode options.
2. Let modules do 1 and also take over the theming of the results.

I'd appreciate your pointers. I have time to work on api changes for this if you need.

Thanks

CommentFileSizeAuthor
#3 views-excerpt-field-1147466.patch1.86 KBawolfey
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

I think that the way to do this (which would also not be centered on search pages and therefore be easily reusable with Views) is to provide a processor, which could then add the highlighted data into the 'excerpt' key. It can also collect data before the search is executed and have a configuration form. As you correctly cite, search pages in "Themed as search results" view mode will use that key as the text displayed.

Regarding Views, I just realize we currently don't provide a "Search excerpt" field that allows access to this data in Views. But this should be rather easy to add, I guess.

awolfey’s picture

There's a rough, but working, dev version of Fuzzy Search up now. I will try to work on getting the excerpt into views.

awolfey’s picture

Title: Best way to provide alternate view mode? » Provide excerpt in Search pages and Views
Version: 7.x-1.0-beta8 » 7.x-1.x-dev
Category: support » feature
Status: Active » Needs review
FileSize
1.86 KB

Here's the patch for the excerpt field in views.

It occurred to me that service classes may want to provide other views fields (that are not indexed) and that search api could provide an abstract way to deal with them so that each service class doesn't have to do its own views integration.

But for now here's just the excerpt field.

drunken monkey’s picture

Works perfectly, thanks!

I only changed this line

if (isset($results[$id]['excerpt']) && $this->fields['search_api_excerpt']) {

wrapping the second expression in !empty() to avoid notices.

If anyone should know of any reason this patch shouldn't be committed, speak now or forever hold your peace!

drunken monkey’s picture

Status: Needs review » Fixed

OK, committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.