Under some circumstances the datasource ID is not set in \Drupal\search_api\Plugin\search_api\processor\Highlight::getFulltextFields. We are using Search API Solr, and are passing the Rendered Item to the index. Even though the server and index are both set up for excerpt and highlight, the $fulltext_fields has an empty key ('') for the rendered item.

I know you need more debugging information, also I am not confident if this is a bug against Search API or Search API Solr, but I'll leave the followup to others who also encounter the issue as right now I don't have time to dig into it further. Attaching a workaround patch which allowed us to use search excerpt with Search API Pages (Views still returns empty results when set to display "search results" instead of rendered entities).

Comments

snufkin created an issue. See original summary.

snufkin’s picture

Status: Active » Needs work
StatusFileSize
new736 bytes

Patch overrides the fulltext fields array with the values from the entry where the key is not set correctly. This is a hacky workaround and does not solve the underlying issue, and will need more work to debug the root cause. It is here for reference only.

snufkin’s picture

Project: Search API » Search API Solr
Component: General code » Code

We think this is due to the way search api solr implements the highlight plugin than search api, so reassigning to that project.

alxbridge’s picture

The patch in #2 works for me, as long as I have another fulltext field defined besides the Rendered Item.

NB I've also encountered this problem with Database search, so I think this belongs to Search API (or possibly both, if it's a problem with the highlight plugin implementation in both).

drunken monkey’s picture

Project: Search API Solr » Search API
Component: Code » Plugins
Status: Needs work » Needs review
StatusFileSize
new1.18 KB

Thanks for reporting this issue.
I think the problem here is that the code doesn't take datasource-independent fields into account, although they can apply to items of all datasources. Of course, at least in the current architecture, datasource-independent fields cannot be extracted from items, so this will currently only cause any issue for backends like Solr, which (sometimes) return field data.
The attached patch should fix this problem cleanly. Please test

However, for Solr, you can also just use Solr's built-in highlighting support and just disable the "Highlight" processor of the Search API.

snufkin’s picture

StatusFileSize
new1.13 KB

Rolling the patch against alpha14, because against -dev our build is failing.

Status: Needs review » Needs work

The last submitted patch, 6: empty_highlighted-2703915-6.patch, failed testing.

The last submitted patch, 6: empty_highlighted-2703915-6.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
rupertj’s picture

Status: Needs review » Reviewed & tested by the community

Snufkin's version of the patch against alpha14 works well for me and fixes the issue. (-dev is currently broken for me too, so I couldn't test that).

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for testing!
However, if you didn't test the version that will actually be committed, please don't mark the issue as RTBC. I need verification of the actual patch – especially with the many major changes the module is currently going through.

drunken monkey’s picture

Status: Needs review » Needs work

This has become out-dated now due to #2575003: Make adding new properties/fields more a first-class operation of processors, which does allow the extraction of processor-provided fields (though we should probably try to make this process a bit smoother).
Also, I just realize that it seems this patch won't add the datasource-independent fields to datasources without fulltext fields after all.
So, probably we need more or less a complete rewrite here.

drunken monkey’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2305021: Test field extraction in processors

Will be fixed in #2305021: Test field extraction in processors, I hope.
Please test the patch posted there and see if it really solves your issue!

rgpublic’s picture

Re #13: I just tried out the new version with the #2305021 fix and it indeed resolves the problem (8.x-1.0-alpha16). For everbody who tries to upgrade:

1) You need to uninstall the search_api module first before reinstalling. Upgrading from alpha15 doesnt work due to some configuration issues. Consequently, you need to recreate you search api server/index.
2) alterPropertyDefinitions has been replaced with getPropertyDefinitions. So if you are defining "virtual" fields to be indexed you need to do it there. See the changes to AddURL class in https://www.drupal.org/files/issues/2575003-24--processor_properties.patch to get an idea of how it's working: It's nearly the same as before, but you need to create instances of ProcessorProperty to define your stuff. You only need to return sth. when $datasource (the only argument of the function) is NOT set. And, finally, IMPORTANT: You need to set "add_properties" = 0 in the stages part of the annotation (comment block at the beginning of your processor class). If you omit that, your shiny new function isnt even called. Took me a while to figure all this out. Hope it helps anyone.

After you do all this, this problem vanishes and you will indeed see the excerpt with your virtual fields included and properly highlighted.