Package ubic.gemma.core.search.lucene
Class LuceneQueryUtils
- java.lang.Object
-
- ubic.gemma.core.search.lucene.LuceneQueryUtils
-
public class LuceneQueryUtils extends Object
Utilities for parsing search queries using Lucene.- Author:
- poirigui
-
-
Constructor Summary
Constructors Constructor Description LuceneQueryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<String>extractTerms(SearchSettings settings)Extract terms, regardless of their logical organization.static Set<Set<String>>extractTermsDnf(SearchSettings settings)static Set<Set<String>>extractTermsDnf(SearchSettings settings, boolean allowWildcards)Extract a DNF (Disjunctive Normal Form) from the terms of a query.static booleanisWildcard(SearchSettings settings)Check if the query is a wildcard query.static org.apache.lucene.search.QueryparseSafely(String query, org.apache.lucene.queryParser.QueryParser queryParser)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.QueryParser queryParser)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)Escape the query for a database match.static StringprepareDatabaseQuery(SearchSettings settings, boolean allowWildcards)Obtain a query suitable for a database match.static URIprepareTermUriQuery(String s)static URIprepareTermUriQuery(SearchSettings settings)static Stringquote(String query)Quote the given Lucene query to be used for an exact match.
-
-
-
Method Detail
-
parseSafely
public static org.apache.lucene.search.Query parseSafely(SearchSettings settings, org.apache.lucene.queryParser.QueryParser queryParser) 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.QueryParser queryParser) throws SearchException
Safely parse the given search query into a Lucene query, falling back on a query with special characters escaped if necessary.- Throws:
SearchException
-
extractTerms
public static Set<String> extractTerms(SearchSettings settings) throws SearchException
Extract terms, regardless of their logical organization.Prohibited terms are excluded.
- Throws:
SearchException
-
extractTermsDnf
public static Set<Set<String>> extractTermsDnf(SearchSettings settings) throws SearchException
- Throws:
SearchException
-
extractTermsDnf
public static Set<Set<String>> extractTermsDnf(SearchSettings settings, boolean allowWildcards) 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 will return an empty set.
- Parameters:
allowWildcards- allowPrefixQueryandWildcardQueryclauses- Throws:
SearchException
-
prepareDatabaseQuery
@Nullable public static String prepareDatabaseQuery(SearchSettings settings) throws SearchException
Escape the query for a database match.- Throws:
SearchException- See Also:
prepareDatabaseQuery(SearchSettings, boolean)
-
prepareDatabaseQuery
@Nullable public static String prepareDatabaseQuery(SearchSettings settings, boolean allowWildcards) throws SearchException
Obtain a query suitable for a database match.This method will return 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.The resulting string is free from character that would usually be used for a free-text match unless
allowWildcardsis set to true.- Parameters:
allowWildcards- if true, wildcards are supported (i.e. '*' and '?') and translated to their corresponding LIKE SQL syntax (i.e. '%' and '_'), all other special characters are escaped.- Returns:
- the first suitable term in the query, or null if none of them are applicable for a database query
- Throws:
SearchException
-
prepareDatabaseQuery
@Nullable public static String prepareDatabaseQuery(String query, boolean allowWildcards) throws SearchException
- Throws:
SearchException
-
prepareTermUriQuery
@Nullable public static URI prepareTermUriQuery(String s) throws SearchException
- Throws:
SearchException
-
prepareTermUriQuery
@Nullable public static URI prepareTermUriQuery(SearchSettings settings) throws SearchException
- Throws:
SearchException
-
isWildcard
public static boolean isWildcard(SearchSettings settings)
Check if the query is a wildcard query.
-
-