SenseNet / sn-client

Monorepo for sensenet client packages 🐱‍💻
https://sensenet.com
GNU General Public License v2.0
25 stars 37 forks source link

[BUG] Query of reference field value #1391

Closed VargaJoe closed 2 years ago

VargaJoe commented 2 years ago

Reference fields are not indexed properly: in case of multiple references only the last id is indexed on the content. The result is that the main content cannot be found using a content query by the reference field.

Investigation

Reference FieldIndexHandler returns a list of integer index fields. This is not compatible with the rest of the code below. The problem: we need to return a single indexfield here that contains an array of integer values. But there is no underlying API for that, only for strings. If we try to convert reference ids to strings here (creating a string array), search still does not work. https://github.com/SenseNet/sensenet/blob/06fb544fa32db4b6bd5084b1b947dae7743ba73e/src/ContentRepository/Search/Indexing/FieldIndexHandler.cs#L997

IndexDocumentProvider adds them one by one: https://github.com/SenseNet/sensenet/blob/06fb544fa32db4b6bd5084b1b947dae7743ba73e/src/ContentRepository/Search/Indexing/IndexDocumentProvider.cs#L99

But IndexDocument overwrites older entries in the dictionary, because the field name is the same: https://github.com/SenseNet/sensenet/blob/06fb544fa32db4b6bd5084b1b947dae7743ba73e/src/Search/Indexing/IndexDocument.cs#L312

Original client-side error

Client function loadCollection seems to not work properly when queried reference field.

   const result = await repo.loadCollection({
      path: contentPath,
      oDataOptions: {
        query: `ReferenceField:('${referencedContent.Id}')`,
        select: 'all'
      },

When the content only has one referenced value, the result is perfectly fine, but when reference field has multiple value, the result will only work with one of the referenced content id. Presumably with the latest addition, the other id will result an empty array. When multiple id is given to the query, there is only the same one result.

(Path instead of the Id won't work at all)

tusmester commented 2 years ago

This is a backend (indexing) issue: when we index a reference field, only the last index field is persisted, which leads to the issue above.