Can I add image captions to _alltext of referring content?


#1

Subject kinda says it all. I have an article with included images. The images have captions. Is there any way I can make XP automatically index the caption (and displayname) of the image indexed in the _alltext field of the parent element?

I would like to use this to improve the search function on a site. It makes more sense in our use case to present the actual content page to the user in the search results, rather than the image object.


#2

Short answer: No, because XP content is stored in the repo as a database (master data), it is not a “search index”. Indexing across items causes tons of potential issues and has side-effects you will not like.

Long answer: You can create this functionality by index the data you want in another repo (search index). Fill this repo with content using server events, batch jobs or even crawling - and you get exactly the indexing you are looking for!


#3

Hmmm. These server events sound interesting. I was unaware of such functionality. Are there public hooks I can use for this? Do you have an example?


#4

Events are kind of “advanced level”, and needs better docs. However here is something to start with:
http://repo.enonic.com/public/com/enonic/xp/docs/6.15.5/docs-6.15.5-libdoc.zip!/module-event.html

Listeners should most likely be placed in main.js (as they will then instantly be active when an app is started). Once you get events, you may start reacting to them.

I believe there are explicit content events too…