I’m trying to modify the theme/search/index.php page to show keyword in context (KWIC) in the results. Is there a method for accessing the relevant results?

I did a var_dump on $searchText and I see a pretty complex object (object(Omeka_Db)) in ["_db":protected]
and buried deep inside the Omeka_Db object is the fulltext that I’d want to extract a section of.

Does Omeka have a method for doing that? I fear that the “protected” aspect may mean that it’s not accessible. I couldn’t figure out raw PHP syntax that would support accessing that (e.g. $searchText->[’"_db":protected’] )

Is there a way to do this?

I saw that the LiveBook plugin does have some sort of KWIC support, but I’m not sure that I want to go that route – although if anyone is using both PDFText and LiveBook, I’d be interested in hearing how that works.

The metadata view helper docs describe:
$metadata (string|array) – The metadata field to retrieve. If a string, refers to a property of the record itself. If an array, refers to an Element: the first entry is the set name, the second is the element name.

So I think my set name is “PDF Text” and my element name is “Text”, but it doesn’t seem to work. Any ideas what I’m doing wrong? I’ve tried swapping the order of the array elements just in case, but it didn’t work either.

A couple things: typically you’d just use the global function metadata in a theme view like this, rather than creating an instance of the helper.

Likely the source of your issue here: the PDF Text element set is, to my recollection, only specified for Files, not Items. If you make that metadata call on an Item, it will give you this kind of error since the element doesn’t exist for Items. If Files and Items are mixed in your results and you only want this to run on the Files, you can simply check the record type, which is already pulled out in the search results view.

If you are having Items as the results and want to get at the file metadata… you could loop over the files for the item and call metadata on them… or you could probably do a query to get at the actual “search text” table text column, as an alternative… we don’t select it as part of the actual search process but you could use get_record to re-request it from the database and you should get everything including the text column.