0

I'm using Apache SOLR as search engine. Everything works fine, indexing as I want, showing the data as I want. I only need to show the PDF which belongs to a certain snippet on a search result. Example:

Result 1: Node Title
Snippet1 -> snippet from node
Snippet2 -> snippet found in pdf x on this node
Snippet3 -> snippet found in node


Result 2: Node Title
Snippet1 -> snippet from node
Snippet2 -> snippet found in pdf x on this node
Snippet3 -> snippet found in node


Result : Node Title
Snippet1 -> snippet from node
Snippet2 -> snippet found in pdf x on this node
Snippet3 -> snippet found in node

The idea is, to have a list of snippets which can be either on the node itself or in a pdf (or any other file) which is attached to this node and link to it (in file case).

Tika extension and Apachesolr_attachments are in place and working.

I get the $vars['snippets'] from hook_apachesolr_search_snippets($vars) and I can modify the output. But I don't see how I could add more information to it.

Any help appreciated.

1 Answer 1

1

you can add extra field to solr. you need to implement hook_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id)

and there $document->addField('pdf_field_name', 'your_url');

also you need to implement hook_apachesolr_query_prepare(DrupalSolrQueryInterface $query)

and add there $query->addParam('fl', 'pdf_field_name');

then in your search-result.tpl.php $pdf_field_name should be available (after reindexing)

2
  • Thank you for your answer. This is ok so far. Your solution works for one part. But the snippet still does not know to which pdf file in which field it belongs. Any ideas about that? How could I enhance the infos there?
    – Lance
    Commented Dec 2, 2014 at 12:41
  • Or in other words, is there a way to extend this '['snippets']['content'][0]' with the filename of the field the snippet belongs too?
    – Lance
    Commented Dec 3, 2014 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.