Indexing field of another content in query

Enonic version: 6.15.5
OS: Windows 10

I need to make a query to get objects, based on a text. I used fulltext for this and works. This is an example of this object:

{
    _id: 'a9da5140-87ae-49a5-bf6e-b5f17cb438d7'
    ...
    data: {
        file: 'f2bb898f-d3eb-41a9-be9d-1c33ddc6ac35'
    }
}

This is an example of a query:

fulltext('*.text', 'myword', 'AND')

When I run this query, I need to search too in the field ‘attachment.text’ of the file, and return the object a9da5140-87ae-49a5-bf6e-b5f17cb438d7 if this field has the text ‘myword’.

My question:

In Enonic I can indexing the field ‘attachment.text’ when I make the search in the object that I select the attachment?

Hi…

  1. Are you using node API, or content API?
  2. If you are using content API, is the content a media (uploaded file)?
  3. If you have a media, the contents of the file are automatically indexed and placed in various properties. You can see this from the data toolbox app.
  4. The query example you are providing makes no sense, first field should be the property to search, i.e. fulltext(’_allText’, ‘search string’, ‘AND’)
  1. I using the content API.
  2. Yes, the content is media.

When I search, the media is returned, but I need the content that references the media be returned.
For example, in my example, I need that the content a9da5140-87ae-49a5-bf6e-b5f17cb438d7 be returned, even if the text is in the file.

I see, you will need to run two queries to do this:

  1. Fulltext search across the media you want to match, then
  2. Pass the id’s of the media hits to a new query type “_references in (“a9da5…”,“id2”,“id3” etc )”

_references is a dynamic field available in all contents aggregating all outbound references. So, if it is linking to your hits from search 1, you will get it in search 2.

https://xp.readthedocs.io/en/stable/developer/search/query-references.html