apache / apache/lucene

Make remaining mutable Queries immutable [LUCENE-7078]

Open
#8,134 1 comment 0 reactions 0 assignees View on GitHub
legacy-jira-fix-version:6.7 legacy-jira-fix-version:7.0 legacy-jira-priority:Minor module:core/search type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

See #7589
Mutable queries are an issue for automatic filter caching since modifying a query after it has been put into the cache will corrupt the cache. We should make all queries immutable (up to the boost) to avoid this issue.

Since they are part of the public API I would suggest splitting them in an immutable class and a builder like was done for most other Queries **before** releasing an official 6.x version

I did a quick scan through all derived classes of Query and I compiled the following list (ignoring sources in test or contrib folders)
Some of them are already marked as experimental (but should perhaps receive the "official" `@lucene`.experimental tag ?)
For some it's possibly not an issue since they should never end up in a filter cache (like MoreLikeThisQuery ?), but then a comment specifying the exception to the rule should perhaps be added.

- lucene/queries:
- org.apache.lucene.queries.CommonTermsQuery
- org.apache.lucene.queries.CustomScoreQuery (marked as `@lucene`.experimental)
- org.apache.lucene.queries.mlt.MoreLikeThisQuery
- lucene/suggest:
- org.apache.lucene.search.suggest.document.ContextQuery (marked as `@lucene`.experimental)
- lucene/facet:
- org.apache.lucene.facet.DrillDownQuery (marked as `@lucene`.experimental)

---
Migrated from [LUCENE-7078](https://issues.apache.org/jira/browse/LUCENE-7078) by Luc Vanlerberghe (@LucVL), updated Jun 08 2017
Linked issues:
- [SOLR-8802](https://issues.apache.org/jira/browse/SOLR-8802)
- #8120

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the listed query classes: CommonTermsQuery, CustomScoreQuery, MoreLikeThisQuery, ContextQuery, and DrillDownQuery, along with issue #7589 and linked issue #8120. Determine which remaining queries can be split into immutable classes and builders, then verify that mutability is limited to boost and document any query that should not enter the filter cache.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.