theonedev/onedev · error · TooGeneralQueryException

Symbol query is too general: ${term}

Error message

Symbol query is too general: ${term}

What it means

SymbolQueryOption.applyConstraints indexes a symbol search term into Lucene fields. If the term contains only wildcard characters ('?' and '*') with no literal characters, the query would match every symbol, so TooGeneralQueryException is thrown. This prevents pathological full-scan symbol queries.

Source

Thrown at server-core/src/main/java/io/onedev/server/search/code/query/SymbolQueryOption.java:124

		
		if (fileNames != null) {
			BooleanQuery.Builder subQueryBuilder = new BooleanQuery.Builder();
			for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
				subQueryBuilder.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), SHOULD);
			BooleanQuery subQuery = subQueryBuilder.build();
			if (subQuery.clauses().size() != 0)
				builder.add(subQuery, MUST);
		}

		boolean tooGeneral = true;
		for (char ch: term.toCharArray()) {
			if (ch != '?' && ch != '*') {
				tooGeneral = false;
				break;
			}
		}
		if (tooGeneral)
			throw new TooGeneralQueryException("Symbol query is too general: " + term);

		if (primary != null) {
			String fieldName;
			if (primary)
				fieldName = BLOB_PRIMARY_SYMBOLS.name();
			else
				fieldName = BLOB_SECONDARY_SYMBOLS.name();

			builder.add(new WildcardQuery(new Term(fieldName, term.toLowerCase())), MUST);
		} else {
			BooleanQuery.Builder termQueryBuilder = new BooleanQuery.Builder();
			termQueryBuilder.add(new WildcardQuery(new Term(BLOB_PRIMARY_SYMBOLS.name(), term.toLowerCase())), SHOULD);
			termQueryBuilder.add(new WildcardQuery(new Term(BLOB_SECONDARY_SYMBOLS.name(), term.toLowerCase())), SHOULD);
			builder.add(termQueryBuilder.build(), MUST);
		}
	}

	@Override

View on GitHub (pinned to d44925c47c)

Solutions

  1. Add at least one literal (non-wildcard) character to the term, e.g. 'get*' instead of '*'.
  2. Pre-validate the term before creating the query: reject terms matching ^[?*]+$ .
  3. Catch TooGeneralQueryException in the search path and prompt the user to refine the query.

Example fix

// before
new SymbolQuery().withOption(new SymbolQueryOption("*", false, true, true));
// after
new SymbolQuery().withOption(new SymbolQueryOption("get*", false, true, true));
Defensive patterns

Strategy: validation

Validate before calling

if (term == null || term.matches("[?*]+"))
    throw new IllegalArgumentException("Symbol search term needs at least one literal character");

Type guard

boolean isUsableSymbolTerm(String term) {
    return term != null && term.chars().anyMatch(c -> c != '?' && c != '*');
}

Try / catch

try {
    query = new SymbolQuery().withOption(new SymbolQueryOption(term, false, true, true));
} catch (TooGeneralQueryException e) {
    return Result.error("Symbol query too general: " + term);
}

Prevention

When it happens

Trigger: Building a SymbolQuery whose option term is made up solely of '*' and/or '?' (e.g. '*', '???') and applying its constraints during a code symbol search.

Common situations: User enters '*' in the symbol search box of code search; programmatic symbol search built from unvalidated user input; a saved search left with only wildcard characters.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/91064248ade1e9b9. Report an issue: GitHub.