0

I'm building a search engine with Apache SOLR (8.7.0) where PDF files are indexed and searched through, that part is working (with search_api_attachments in case you're wondering). However, the client wants to show a link to the node where this file was referenced from. This is using plain file fields, no media library. Is there a way to either index the node ID with the file, or get this reference somehow in the view with a relationship or something? Spent a good day on it but couldn't figure it out, maybe I'm just overlooking it. Or is this something that would require me writing a custom hook to add the field to the index? (it seems like quite a general use case to me though)

1
  • I'm going to reference this issue that I just found: drupal.stackexchange.com/questions/289890/… Although I prefer it to be in SOLR, I guess a similar (improved) logic could be used to do the same but put it in solr rather as only looking it up when the content is viewed. – Bram Dec 18 '20 at 21:06
1

I am not sure if this can be done with a generic file field. It could be possible if it was a media or entity reference field. I think the simplest approach is to use hook_search_api_solr_documents_alter to find and add the node ID to the document when it is being indexed.

You can, possibly, then use the new field to create a relationship to Node table in the view to display the link or simply handle it on the theme level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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