Class LuceneQueryUtils
Restored for HS-7 search restoration Step 3 (see SEARCH_RECCE.md). This is a
subset of the pre-strip LuceneQueryUtils: we keep parseSafely(SearchSettings, QueryParser, Consumer),
escape(String), extractTerms(SearchSettings, Consumer), prepareDatabaseQuery(SearchSettings, Consumer), and
isWildcard(SearchSettings) — the surface that DatabaseSearchSource and
HibernateSearchSource actually call. DNF extraction (used by ontology
search) is deferred along with the ontology source.
- Author:
- poirigui
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringEscape all reserved Lucene characters in the given query.extractTerms(SearchSettings settings, Consumer<Throwable> issueReporter) Extract terms, regardless of their logical organization.extractTermsDnf(SearchSettings settings, boolean allowWildcards, Consumer<Throwable> issueReporter) Extract a DNF (Disjunctive Normal Form) from the terms of a query.extractTermsDnf(SearchSettings settings, Consumer<Throwable> issueReporter) static booleanisWildcard(SearchSettings settings) Check if the query is a wildcard query.static org.apache.lucene.search.QueryparseSafely(String query, org.apache.lucene.queryparser.classic.QueryParser queryParser, Consumer<Throwable> report) Safely parse the given search query into a Lucene query, falling back on a query with special characters escaped if necessary.static org.apache.lucene.search.QueryparseSafely(SearchSettings settings, org.apache.lucene.queryparser.classic.QueryParser queryParser, Consumer<Throwable> issueReporter) Safely parse the given search settings into a Lucene query, falling back on a query with special characters escaped if necessary.static StringprepareDatabaseQuery(String query, boolean allowWildcards) static StringprepareDatabaseQuery(SearchSettings settings, boolean allowWildcards, Consumer<Throwable> issueReporter) Obtain a query suitable for a database match.static StringprepareDatabaseQuery(SearchSettings settings, Consumer<Throwable> issueReporter) static URIprepareTermUriQuery(SearchSettings settings, Consumer<Throwable> issueReporter) static StringQuote the given Lucene query to be used for an exact match.
-
Constructor Details
-
LuceneQueryUtils
public LuceneQueryUtils()
-
-
Method Details
-
parseSafely
public static org.apache.lucene.search.Query parseSafely(SearchSettings settings, org.apache.lucene.queryparser.classic.QueryParser queryParser, @Nullable Consumer<Throwable> issueReporter) throws SearchException Safely parse the given search settings into a Lucene query, falling back on a query with special characters escaped if necessary.- Throws:
SearchException
-
parseSafely
public static org.apache.lucene.search.Query parseSafely(String query, org.apache.lucene.queryparser.classic.QueryParser queryParser, @Nullable Consumer<Throwable> report) throws SearchException Safely parse the given search query into a Lucene query, falling back on a query with special characters escaped if necessary.- Parameters:
report- a consumer for potentialParseExceptionwhen attempting to parse the query, ignored if null- Throws:
SearchException
-
escape
-
extractTerms
public static Set<String> extractTerms(SearchSettings settings, @Nullable Consumer<Throwable> issueReporter) throws SearchException Extract terms, regardless of their logical organization. Prohibited terms are excluded.- Throws:
SearchException
-
extractTermsDnf
public static Set<Set<String>> extractTermsDnf(SearchSettings settings, @Nullable Consumer<Throwable> issueReporter) throws SearchException - Throws:
SearchException
-
extractTermsDnf
public static Set<Set<String>> extractTermsDnf(SearchSettings settings, boolean allowWildcards, @Nullable Consumer<Throwable> issueReporter) throws SearchException Extract a DNF (Disjunctive Normal Form) from the terms of a query.Clauses can be nested (i.e.
a OR (d OR (c AND (d AND e))) as long asORandANDare not interleaved. Prohibited clauses are ignored unless they break the DNF structure, in which case this returns an empty set.- Parameters:
allowWildcards- allowPrefixQueryandWildcardQueryclauses- Throws:
SearchException
-
prepareDatabaseQuery
@Nullable public static String prepareDatabaseQuery(SearchSettings settings, @Nullable Consumer<Throwable> issueReporter) throws SearchException - Throws:
SearchException- See Also:
-
prepareDatabaseQuery
@Nullable public static String prepareDatabaseQuery(SearchSettings settings, boolean allowWildcards, @Nullable Consumer<Throwable> issueReporter) throws SearchException Obtain a query suitable for a database match.This method returns the first global term in the query that is not prohibited. If
allowWildcardsis set to true, prefix and wildcard terms will be considered as well and translated to SQL LIKE syntax.- Throws:
SearchException
-
prepareDatabaseQuery
@Nullable public static String prepareDatabaseQuery(String query, boolean allowWildcards) throws SearchException - Throws:
SearchException
-
isWildcard
Check if the query is a wildcard query. -
quote
-
prepareTermUriQuery
@Nullable public static URI prepareTermUriQuery(SearchSettings settings, @Nullable Consumer<Throwable> issueReporter) throws SearchException - Throws:
SearchException
-