Enhanved Item Relations with relation comments – need help for searching

Hi guys,

we're using Omeka for a interdisciplinary university project. At some point we realized that simple relations between two items were not expressive enough, so I added a tiny edit field to annotate any relation that you create – for example a page number for a literature reference, a year number for a birthplace reference, … you name it, it's pretty handy.

The item relationship comment enhancement is quite straightforward, it pretty much just adds an additional field to the {prefix}_item_relations_relations table that can be filled through an additional edit field when adding a new relationship. … If you're really, really interested in that, I could point you to my respective GitHub repository to get it.

- - - - -

But here comes the problem:

Besides the possibility of adding these comments, those are obviously text fields that should be searchable. At the moment, I'm trying to think about at least improving hookAdminItemsSearch() to add a text field to the relationship search for comment searching.

However: Wouldn't it be much better to tie this search into the regular full text search (FTS)?

1st approach: I understand that the FTS utilizes the {prefix}_search_texts table that is being filled upon saving an item. Item Relations indeed has an hookAfterSaveItem($args) – but I can't figure out how to add my own addSearchText() to enhance the item's full text inside the "Save item relations" branch.

If this was indeed possible – could someone please hint me how to retrieve the respective item object that would let me use addSearchText() at this point?

… However: To my understanding (and experiments), this wouldn't actually suffice. The "Save item relations" branch of hookAfterSaveItem() is executed only for newly created relations that are still inside $args['post']. Meaning: When re-editing an item (which definitely results into re-generating its search texts), the existing relations are no longer processed – essentially meaning that their comment fields wouldn't find their way into the search text again. Duh ...

2nd approach: As described inside the "Best Practices for Plugin Development" guide, I was thinking about giving Item Relations a Mixin_Search().

However, Item Relations is not an Omeka_Record_AbstractRecord record, it's an Omeka_Plugin_AbstractPlugin plugin – so if I'm not totally mistaken, I can't actually do this. Is that correct?

3rd approach: Could I create yet another plugin that could enhance after_save_item with its own hookAfterSaveItem($args) even more? My idea would be that this would be called

- after the item is saved,

- after the item relations have been created or deleted,

- to be able to gather which items relations are actually in place now, to concatenate the item's relation comments to the item's search text in search_texts.

- - - - -

Some ideas? Any idea? ;-) I'd be really happy for any insight or at least suggestion where to look further.

I'm not 100% sure I'm following how you are using Item Relations here, since I don't think it would be especially searchable. But if it is close to working for your needs, I'm good with that!

There's not a completely smooth approach that I can see, but something akin to your #2 approach might get close, with a change to the existing Item Relations code.

The Mixin_Search isn't part of the Plugin class -- it's part of the model. Look in the models directory for ItemRelationsRelation.php. Changes there might make it behave as you would like, using the search mixin.

Yes – a regular Item Relations is not worth searching in full-text. The search for specific relations in subject or object items is enough.

What you missed is that I implemented an enhancement to Item Relations that will give you a comment field for every relation you create. This "annotated relations" feature can be switched on and off, so you don't have to use it if you don't like it.

But when used, every relation has an edit field that can be filled with e.g. a year number, a page number, a birthday - just about anything.

As a matter of fact, I went for approach #3: I enhanced hookAdminItemsSearch() with an additional search field in item-relations-advanced-search.php and the actual search being implemented in hookItemsBrowseSql().

... Which still doesn't provide simple FTS yet.