languagetool-org/languagetool · error · RuntimeException
Could not create query for rule + rule.getId()
Error message
Could not create query for rule + rule.getId()
What it means
Search-index guard: PatternRuleQueryBuilder could not turn the grammar rule (rule.getId()) into any Lucene query because its pattern elements are unsupported for indexing; thrown as UnsupportedPatternRuleException so the caller can skip the rule.
Source
Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java:81
this.indexSearcher = indexSearcher;
this.searchFieldName = searchFieldName;
}
/**
* Iterate over all elements, ignore those not supported, add the other ones to a BooleanQuery.
* @throws UnsupportedPatternRuleException if no query could be created for the rule
*/
public Query buildRelaxedQuery(AbstractPatternRule rule) throws UnsupportedPatternRuleException {
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (PatternToken patternToken : rule.getPatternTokens()) {
try {
BooleanClause clause = makeQuery(patternToken);
builder.add(clause);
} catch (UnsupportedPatternRuleException e) {
//System.out.println("Ignoring because it's not supported: " + element + ": " + e);
// cannot handle - okay to ignore, as we may return too broad matches
} catch (Exception e) {
throw new RuntimeException("Could not create query for rule " + rule.getId(), e);
}
}
BooleanQuery query = builder.build();
if (query.clauses().isEmpty()) {
throw new UnsupportedPatternRuleException("No items found in rule that can be used to build a search query: " + rule);
}
return query;
}
private BooleanClause makeQuery(PatternToken patternToken) throws UnsupportedPatternRuleException {
checkUnsupportedElement(patternToken);
String termStr = patternToken.getString();
String pos = patternToken.getPOStag();
BooleanClause termQuery = getTermQueryOrNull(patternToken, termStr);
BooleanClause posQuery = getPosQueryOrNull(patternToken, pos);
View on GitHub (pinned to 2e990059ce)
Solutions
- Simplify the rule's pattern tokens to plain terms or POS tags
- Skip rules that throw this exception when batch-indexing Wikipedia
- Extend PatternRuleQueryBuilder to support the missing construct
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java:81 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/7f50092108b36a12.
Report an issue: GitHub.