Hello,

Thank you for putting all the patch together and maintaining the module.

I have some issues to display Highlight.

Sarnia require a numeric id for the entity, I am using solr _version_ field.

My Solr Index got a field id "file path" and the pattern is not known by drupal, the index is generated by another application.

Looking at the method below in search_api_solr/includes/service.inc

protected function extractResults(SearchApiQueryInterface $query, $response) {


      $index_id = $this->getIndexId($index->machine_name);
      $solr_id = $this->createId($index_id, $result['id']);
      $excerpt = $this->getExcerpt($response, $solr_id, $result['fields'], $fields);

}

I can see that we are assuming the solr id field follow the pattern of an index created by drupal.
The excerpt is in the response but can't be extracted by sarnia due to the logic in search_api_solr.

What will be the best option to fix this issue? Any idea?

I am looking at overriding the methods below in sarnia/service.inc


protected function extractResults(SearchApiQueryInterface $query, $response) {

}

protected function getExcerpt($response, $id, array &$fields, array $field_mapping) {
}

Is it the best way to do it? Any suggestion or advice is welcome.

I have attached the patch that works for me.

Thank you

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ibakayoko’s picture

by overriding extractResults i was able to get the snippet as long as you have a field named content.

ibakayoko’s picture

Issue summary: View changes
FileSize
5.33 KB
ibakayoko’s picture

Assigned: Unassigned » ibakayoko
Status: Active » Needs review
jmdeleon’s picture

Status: Needs review » Needs work

Hi... I'm trying out this patch and I get the following messages:

Notice: Undefined index: id in SarniaSolrService->extractResults() (line 503 of ... /sites/all/modules/contrib/sarnia/service.inc).

It appears at that line 503, you make an assumption that the set of fields will include a unique-value 'id' field. In one of the use cases I have, the unique field is not named 'id'. You might want to test for its existence and handle accordingly.

ZeiP’s picture

Worked well with an index containing the id field. Thanks!

ibakayoko’s picture

Assigned: ibakayoko » Unassigned
seanB’s picture

The patch works for me! Coding standards are not being followed, so that could be improved...

jmdeleon’s picture

If the original submitter of the patch -- or anyone else -- would like to clean it up:

  1. follow coding standards
  2. cleanly handle the case where there is no 'id' field

I would welcome integrating this patch.

I don't have use-cases in the current work I do with Sarnia where an excerpt needs to be returned, so any patch ought to be tested by others, as well as the original use-case.

mparker17’s picture

Fixed coding standards.

Still to do: cleanly handle the case where there is no 'id' field.

Feedback welcome.

jmdeleon’s picture

Patch in #9 applied cleanly, continuing to evaluate it.

jmdeleon’s picture

Still looking at this one... would like to be able to cleanly handle the lack of an 'id' field before I commit this.

heddn’s picture

Status: Needs work » Reviewed & tested by the community

This fixed the issue for me. With a couple of us saying that, I think this is good to go.

  • jmdeleon committed 4d26829 on 7.x-1.x authored by mparker17
    Issue #2507513 by mparker17, ibakayoko: Search:Excerpt not displayed
    
jmdeleon’s picture

Status: Reviewed & tested by the community » Fixed
jmdeleon’s picture

Status: Fixed » Closed (fixed)
ianstew41’s picture

HI All
I was having some trouble but only just realised why. When I hit save to enable the highlight filter, it's status does not change to enabled. I.e. if I reload the page, it is still disabled. Anyone any idea what might cause that? I have changed my setup so that the _version_ field provides the ID.