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

Add events to allow modules to select values used in fulltext search #2069

Merged
merged 1 commit into from Dec 14, 2023

Conversation

jajm
Copy link
Contributor

@jajm jajm commented Jun 29, 2023

Some values may not be wanted in the full-text index, either because of their content size (trying to index large amounts of text can seriously impact overall performances of the application) or because their content is irrelevant or add too much noise to the search results

This patch adds two new events:

  • api.get_fulltext_text.value_criteria
  • api.get_fulltext_text.value_annotation_criteria

Both events have resource and criteria as arguments and can modify criteria.
api.get_fulltext_text.value_annotation_criteria has an additional argument, value.

Some values may not be wanted in the full-text index, either because
of their content size (trying to index large amounts of text can
seriously impact overall performances of the application) or because
their content is irrelevant or add too much noise to the search results

This patch adds two new events:
- api.get_fulltext_text.value_criteria
- api.get_fulltext_text.value_annotation_criteria

Both events have `resource` and `criteria` as arguments and can modify
`criteria`.
api.get_fulltext_text.value_annotation_criteria has an additional
argument, `value`.
@jajm
Copy link
Contributor Author

jajm commented Jun 29, 2023

My personal use case for this is to exclude extracttext:extracted_text from the fulltext search, because indexing large amount of texts takes too much time and can cause crashs (see related discussion: omeka-s-modules/ExtractText#6)

@jimsafley
Copy link
Member

Thank you. It looks like a reasonable addition. We'll review this more thoroughly once we're able to confirm that the events will work with the use case.

@jimsafley
Copy link
Member

Getting back to this. Have you found this to work for your use case?

@jajm
Copy link
Contributor Author

jajm commented Oct 13, 2023

Yes it works. Here's the code I used as an example:

class Module extends AbstractModule
{
    public function attachListeners(SharedEventManagerInterface $sharedEventManager)
    {
        $sharedEventManager->attach('*', 'api.get_fulltext_text.value_criteria', [$this, 'onApiGetFulltextTextValueCriteria']);
    }

    public function onApiGetFulltextTextValueCriteria(Event $event)
    {
        $criteria = $event->getParam('criteria');

        $property = $this->getServiceLocator()->get('Omeka\EntityManager')->getRepository('Omeka\Entity\Property')->findOneBy(['localName' => 'extracted_text']);
        if ($property) {
            $criteria->andWhere(Criteria::expr()->neq('property', $property));
        }
    }
}

@zerocrates zerocrates merged commit 8390be4 into omeka:develop Dec 14, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

None yet

3 participants