Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to allow leading wildcard in queries #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions documentation/manual/home.textile
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ bc. play.search.path=/tmp/myDevApplication
play.search.analyser=org.apache.lucene.analysis.standard.StandardAnalyzer
play.search.lucene.version=30
play.search.defaultSearchField=allfield
play.search.allowLeadingWildcard=false

**play.search.path** is where the module stores its indexes
**play.search.analyser** is the lucene analyzer class used for indexation.
**play.search.lucene.version** is the lucene's version (for compatibility mode). Default: 30
**play.search.defaultSearchField** is the default field name used when parsing queries. Default : allfield (special field containing all other fields)
**play.search.allowLeadingWildcard** When set to true, * or ? are allowed as the first character of a query. Note that this can produce very slow queries on big indexes. Default: false

h3. <a> Lucene Version </a>

Expand Down
5 changes: 3 additions & 2 deletions src/play/modules/search/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ public List<QueryResult> executeQuery(boolean fetch) throws SearchException {
try {
if (topDocs == null) {
String defaultField = Play.configuration.getProperty("play.search.defaultSearchField", "allfield");
org.apache.lucene.search.Query luceneQuery =
new QueryParser(Search.getLuceneVersion(), defaultField, Search.getAnalyser()).parse(query);
QueryParser queryParser = new QueryParser(Search.getLuceneVersion(), defaultField, Search.getAnalyser());
queryParser.setAllowLeadingWildcard(Play.configuration.getProperty("play.search.allowLeadingWildcard", "false").equals("true"));
org.apache.lucene.search.Query luceneQuery = queryParser.parse(query);
BooleanQuery.setMaxClauseCount(Integer.parseInt(Play.configuration.getProperty(
"play.search.maxClauseCount", "1024")));
topDocs = indexSearcher.search(luceneQuery, null, Integer.MAX_VALUE, getSort());
Expand Down