Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When type is "resource" nothing is indexed #9

Open
itsam opened this issue Nov 23, 2023 · 2 comments
Open

When type is "resource" nothing is indexed #9

itsam opened this issue Nov 23, 2023 · 2 comments

Comments

@itsam
Copy link

itsam commented Nov 23, 2023

Let's say one of the indexed field is:

  1. dcterms:title

When you create an item and set dcterms:title to any literal text (e.g. "My nice title") then everything works nice.

If instead of Text though you want to add an Omeka resource then nothing happens because there is no "@value" to use for the indexing. One solution is to check if the field is of type "resource" and then instead of @value to use "display_title"

I hope it's clear what the problem is exactly...

For type: "literal" an example (which works fine) of an item is

    {
      "type": "literal",
      "property_id": 2,
      "property_label": "Title",
      "is_public": true,
      "@value": "My nice title"  <--- you are using this (correctly)
    },

For type: "resource" an example (which doesn't work) of an item is

    {
      "type": "resource",
      "property_id": 2,
      "property_label": "Title",
      "is_public": true,
      "@id": "https:\/\/example.com\/api\/items\/16",
      "value_resource_id": 16,
      "value_resource_name": "items",
      "url": null,
      "display_title": "Another omeka item",    <--- use this instead
      "thumbnail_url": "",
      "thumbnail_title": "",
      "thumbnail_type": null
    },

Thank you in advance

@itsam
Copy link
Author

itsam commented Nov 25, 2023

It seems that at its current state RecreateIndex.php cannot support this as it uses an SQL query to retrieve data and the table value does not include any information about the display_title. So probably a more sophisticated SQL query is needed OR
alternatively instead of SQL to use the Omeka API to retrieve the documents and pick all necessary fields in order to be indexed...

Any thoughts on this?

@itsam
Copy link
Author

itsam commented Nov 26, 2023

OK, for my case I have changed the query as follows: (which I don't propose to be used as is, but in any case I put it here for anyone facing a similar issue)

SELECT
    `value`.`resource_id` as `resource_id`,
    GROUP_CONCAT(
        CONCAT(
            `vocabulary`.`prefix`,
            '_',
            `property`.`local_name`
        ) SEPARATOR "~|~"
    ) AS `fields`,

--  GROUP_CONCAT(`value`.`value` SEPARATOR "~|~") AS `values`
    GROUP_CONCAT(
        CASE
            WHEN `value`.`value` IS NULL THEN (

                SELECT `nested_value`.`value`
                FROM `value` AS `nested_value`
                WHERE `nested_value`.`resource_id` = `value`.`value_resource_id`
                AND `nested_value`.`property_id` = 1  
                LIMIT 1
            )
            ELSE `value`.`value`
        END
        SEPARATOR "~|~"
    ) AS `values`

FROM
    `value` AS `value`
    LEFT JOIN `resource` ON `resource`.`id` = `value`.`resource_id`
    LEFT JOIN `property` ON `property`.`id` = `value`.`property_id`
    LEFT JOIN `vocabulary` ON `vocabulary`.`id` = `property`.`vocabulary_id`
WHERE
    `resource`.`resource_type` = 'Omeka\\Entity\\Item'
    AND `resource`.`is_public` = true
GROUP BY
    `resource`.`id`

a) The nested query is called when value is null which occurs when type is "resource" or "resource:item"
b) I set explicitly property_id = 1 (which in my case corresponds to the title (dcterms_title))
c) if you need you can replace with nested_value.property_id = value.property_id

This is just a proposal. It works for my case but it's not generic enough to cover all cases (it's a good start though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant