Skip to content

Conversation

@kwahlin
Copy link
Contributor

@kwahlin kwahlin commented Nov 5, 2025

No description provided.

(At least issuance is a co-dependence.)
Split up for easier test runs.
and move mappings to separate JSON file (as an initial step, with the
goal of picking the mappings directly from definitions data).
branchedelac and others added 27 commits October 28, 2025 17:07
Adds functionality for merging query trees. When merging two trees **A** and **B**, only the parts of **B** that are compatible with **A** are kept, ensuring that the merged query remains valid.

This is used to apply filters from the `_r` parameter and from `apps.jsonld`. Given  
- Q = input from `_q`  
- R = filters from `_r`  
- S = configured filters  

the merge sequence is:  
1. Merge R into Q → QR  
2. Merge S into QR → QRS (final query with all filters applied)

Before merging, we need to know the subject types being queried. If Q specifies a type (e.g. `type:Agent`), we use that, otherwise we take it from R or S, resulting in `Q + Type(R)` (if present) or `Q + Type(S)`.

For `_o` queries with curated predicates, some predicates may be incompatible with the current subject type. For example, if `Type(QRS) = Work` but a predicate `p` has domain `Agent`, we must include `type:Agent` in the query or no results will be returned for `p`. In that case, the query becomes `QRS OR (type:Agent AND p:o)`.

For `_p` + `_o` queries, the domain of `p` takes precedence, i.e. the subject type of the query is determined entirely by `p`. If `p = instanceOf`, then `Type(QRS)` is set to `Instance`.

Once the type of Q is set, we only merge the parts of R and S compatible with that type. See [QueryTree.merge()](https://github.com/libris/librisxl/blob/0bed4a0e965376608a58b3f39d59ea8e4916a926/whelk-core/src/main/groovy/whelk/search2/querytree/QueryTree.java#L48) and corresponding [unit tests](https://github.com/libris/librisxl/blob/0bed4a0e965376608a58b3f39d59ea8e4916a926/whelk-core/src/test/groovy/whelk/search2/querytree/QueryTreeSpec.groovy#L351) for details.

Other improvements:
- Proper search mapping is now generated for `_r`.
- Work/Instance filters are adjusted automatically, e.g. `type:Audio` → `instanceOf.type:Audio` when merging into an `Instance` query, and `hasInstanceType:Electronic` → `type:Electronic`.
- The query tree reduction logic (`Node.reduce()` / `Node.implies()`) has been refined to ensure correctness during merges.
- `AppParams` simplified to store raw filters only.
- `Filter` + `AliasedFilter` consolidated into single `FilterAlias` class.
- `SelectedFilters` renamed to `SelectedFacets` and now only handles statistics/slices.
- Skipped `p` aggregation for `_o` + `_p` queries since there is no current use case and this avoids unnecessary complexity with multi-query handling.
i.e. from an instance don't pull in all other instances linked to the
same work. This fixes the problem where searching for an ISBN finds all
other instances linked to the same work. For now only applied to
integral relations.
…by-isbn

fix(embellish): don't follow the same integral relation in reverse
* Handle hyphen-separated years as range

* Refactor: Move @id/_str path appending to ES conversion phase

* Simplify logic in SelectedFacets
Copy link
Contributor

@olovy olovy left a comment

Choose a reason for hiding this comment

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

🚢

@olovy olovy force-pushed the feature/typenormalization branch from bbf6593 to bb5f342 Compare November 11, 2025 14:26
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.

7 participants