String pattern = MessageFormat.format("{0}:'{'0} AND {1}:\"'{'1'}'\" AND {2}:\"'{'2'}'\"", FIELD_OBJECT_TYPE, FIELD_BRANCH, FIELD_PATH);\r
String q = MessageFormat.format(pattern, SearchObjectType.blob.name(), branch, path);\r
\r
- BooleanQuery query = new BooleanQuery();\r
StandardAnalyzer analyzer = new StandardAnalyzer();\r
QueryParser qp = new QueryParser(FIELD_SUMMARY, analyzer);\r
- query.add(qp.parse(q), Occur.MUST);\r
+ BooleanQuery query = new BooleanQuery.Builder().add(qp.parse(q), Occur.MUST).build();\r
\r
IndexWriter writer = getIndexWriter(repositoryName);\r
int numDocsBefore = writer.numDocs();\r
StandardAnalyzer analyzer = new StandardAnalyzer();\r
try {\r
// default search checks summary and content\r
- BooleanQuery query = new BooleanQuery();\r
+ BooleanQuery.Builder bldr = new BooleanQuery.Builder();\r
QueryParser qp;\r
qp = new QueryParser(FIELD_SUMMARY, analyzer);\r
qp.setAllowLeadingWildcard(true);\r
- query.add(qp.parse(text), Occur.SHOULD);\r
+ bldr.add(qp.parse(text), Occur.SHOULD);\r
\r
qp = new QueryParser(FIELD_CONTENT, analyzer);\r
qp.setAllowLeadingWildcard(true);\r
- query.add(qp.parse(text), Occur.SHOULD);\r
+ bldr.add(qp.parse(text), Occur.SHOULD);\r
\r
IndexSearcher searcher;\r
if (repositories.length == 1) {\r
searcher = new IndexSearcher(reader);\r
}\r
\r
+ BooleanQuery query = bldr.build();\r
Query rewrittenQuery = searcher.rewrite(query);\r
logger.debug(rewrittenQuery.toString());\r
\r
IndexWriter writer = getWriter();
StandardAnalyzer analyzer = new StandardAnalyzer();
QueryParser qp = new QueryParser(Lucene.rid.name(), analyzer);
- BooleanQuery query = new BooleanQuery();
- query.add(qp.parse(repository.getRID()), Occur.MUST);
+ BooleanQuery query = new BooleanQuery.Builder().add(qp.parse(repository.getRID()), Occur.MUST).build();
int numDocsBefore = writer.numDocs();
writer.deleteDocuments(query);
private boolean delete(String repository, long ticketId, IndexWriter writer) throws Exception {
StandardAnalyzer analyzer = new StandardAnalyzer();
QueryParser qp = new QueryParser(Lucene.did.name(), analyzer);
- BooleanQuery query = new BooleanQuery();
- query.add(qp.parse(StringUtils.getSHA1(repository + ticketId)), Occur.MUST);
+ BooleanQuery query = new BooleanQuery.Builder().add(qp.parse(StringUtils.getSHA1(repository + ticketId)), Occur.MUST).build();
int numDocsBefore = writer.numDocs();
writer.deleteDocuments(query);
StandardAnalyzer analyzer = new StandardAnalyzer();
try {
// search the title, description and content
- BooleanQuery query = new BooleanQuery();
+ BooleanQuery.Builder bldr = new BooleanQuery.Builder();
QueryParser qp;
qp = new QueryParser(Lucene.title.name(), analyzer);
qp.setAllowLeadingWildcard(true);
- query.add(qp.parse(text), Occur.SHOULD);
+ bldr.add(qp.parse(text), Occur.SHOULD);
qp = new QueryParser(Lucene.body.name(), analyzer);
qp.setAllowLeadingWildcard(true);
- query.add(qp.parse(text), Occur.SHOULD);
+ bldr.add(qp.parse(text), Occur.SHOULD);
qp = new QueryParser(Lucene.content.name(), analyzer);
qp.setAllowLeadingWildcard(true);
- query.add(qp.parse(text), Occur.SHOULD);
+ bldr.add(qp.parse(text), Occur.SHOULD);
IndexSearcher searcher = getSearcher();
- Query rewrittenQuery = searcher.rewrite(query);
+ Query rewrittenQuery = searcher.rewrite(bldr.build());
log.debug(rewrittenQuery.toString());
sort = new Sort(Lucene.fromString(sortBy).asSortField(desc));
}
int maxSize = 5000;
- TopFieldDocs docs = searcher.search(rewrittenQuery, null, maxSize, sort, false, false);
+ TopFieldDocs docs = searcher.search(rewrittenQuery, maxSize, sort, false, false);
int size = (pageSize <= 0) ? maxSize : pageSize;
int offset = Math.max(0, (page - 1) * size);
ScoreDoc[] hits = subset(docs.scoreDocs, offset, size);