I see what you mean now - you also submitted a support ticket where it got clarified. I will post my colleague's (Eric Dugre) answer here as well for the future reference in case others will have the same need, there are two options:
- Using the field _content: This field of the index stores the searchable content of the page (as opposed to the "Content" field, which you see in the results). This will contain the page content and attachment content, but by default you cannot access it. To access this field, you need to add the CMSSearchStoreContentField key to your web.config: Smart search settings (please read the key description as it has some performance impacts). Once that key is added, you need to rebuild the index.
Afterward, you can access the field like any other field, and highlight text in the attachment:
{%SearchHighlight(GetSearchValue("_content"), "<span style='background-color: #FEFF8F'>", "</span>")%}
- Manually get attachment content: The attachment content is stored in the CMS_Attachment table, AttachmentSearchContent column. You can use the attachment's GUID from the FileAttachment field of your page, then load the attachment data. First, you need to go to Page types > CMS.File > Search fields tab and check "Searchable" for the FileAttachment field. After you save that, you need to rebuild the index.
Now, in your transformation you can get the attachment:
{%nodealiaspath = GetSearchValue("nodealiaspath");
attachment = GetSearchValue("fileattachment");
acontent = Documents[nodealiaspath].AllAttachments[attachment].AttachmentSearchContent;
return;#%}
Content: {%SearchHighlight(acontent, "<span style='background-color: #FEFF8F'>", "</span>")%}
Note that you also need to clear the attachment search cache as mentioned here: Enabling indexing for page attachments.