Skip to content

Scm/index descriptors - #199

Open
StuCM wants to merge 6 commits into
archesproject:mainfrom
flaxandteal:scm/index-descriptors
Open

Scm/index descriptors#199
StuCM wants to merge 6 commits into
archesproject:mainfrom
flaxandteal:scm/index-descriptors

Conversation

@StuCM

@StuCM StuCM commented Jul 23, 2026

Copy link
Copy Markdown

Issue

Search does not take into account the values from the resource descriptors and only take into account term indexed tile values.
This created an issue when we need to search via a number datatype node, which is not indexed into the term search. When a user searches for this number which is displayed in the descriptors nothing is returned.

Fix

Index the computed descriptor (ResourceInstance.descriptors[lang]["name"]) into TermSearch as its own term, under a reserved node alias __descriptor__. The descriptor is exactly the human-readable string a user searches for, so matching
it makes the resource findable regardless of which datatypes compose it.

No schema change: this reuses the existing TermSearch table.

Why not a datatype indexer?

The existing indexers run per-tile / per-node. A descriptor is per-resource and is not a node value, so it does not fit the tile-indexer model. It is also only finalised after Resource.save_descriptors() runs, which is after the tile post_save functions (including the existing SearchIndexingFunction) have already fired - so a tile-level hook would index a stale descriptor.

Changes

  • indexing/index_descriptor.py (new) - build_descriptor_terms(resource) / index_resource_descriptors(resource): builds one TermSearch row per language from the resource descriptor. tileid is NOT NULL but a descriptor is per-resource, so it borrows a real tile: the descriptor's name-nodegroup tile when the primarydescriptors config declares one, otherwise any tile. The tileid is only an FK/CASCADE anchor here - term search is keyed on resourceinstanceid and no nodegroup/permission filtering is applied to term rows - so the fallback is safe.
  • signals.py (new) - a post_save receiver on Resource / ResourceInstance keeps the descriptor term fresh incrementally. save_descriptors() persists the recomputed descriptor via super().save(), so the signal fires with the descriptor already current. Idempotent (delete-then-insert), guarded so it can never break a resource save.
  • apps.py - connect the signal from ready().
  • management/commands/arches_search.py - reindex_database gains a descriptor pass after the tile pass, so a full reindex seeds descriptor terms too.
  • tests/test_descriptor_indexing.py (new) - covers row creation with the borrowed tile, idempotency, and skipping empty / "Undefined" names.

@chiatt chiatt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice new feature, but it introduces a new pattern using a signal rather than the existing arches function (https://github.com/archesproject/arches-search/blob/main/arches_search/functions/search_indexing.py). This approach should really be refactored to add a new 'indexer' that is called by the function rather than using a signal.

@chiatt chiatt linked an issue Jul 26, 2026 that may be closed by this pull request
@StuCM

StuCM commented Jul 27, 2026

Copy link
Copy Markdown
Author

This is a nice new feature, but it introduces a new pattern using a signal rather than the existing arches function (https://github.com/archesproject/arches-search/blob/main/arches_search/functions/search_indexing.py). This approach should really be refactored to add a new 'indexer' that is called by the function rather than using a signal.

I removed the signal and added this in to the post_save as transaction.on_commit. The descriptors update after the tile post save so needed to allow these to update before indexing as otherwise we will hit stale data.

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.

Descriptors not indexed and not searchable

2 participants