]> source.dussan.org Git - gitblit.git/commitdiff
Replace deprecated BooleanQuery constructor with builder.
authorFlorian Zschocke <florian.zschocke@devolo.de>
Sat, 21 Jan 2017 18:09:18 +0000 (19:09 +0100)
committerFlorian Zschocke <florian.zschocke@devolo.de>
Sun, 5 Mar 2017 19:27:21 +0000 (20:27 +0100)
Also replace deprecated `search` method with the one without a filter
argument, since the filter isn't used anyhow.

src/main/java/com/gitblit/service/LuceneService.java
src/main/java/com/gitblit/tickets/TicketIndexer.java

index f22cb5a5712ddfaeaa7407054ef766ca28d5093f..9b97ad5b31b7641f650467666d69da5faa66e21a 100644 (file)
@@ -718,10 +718,9 @@ public class LuceneService implements Runnable {
                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
@@ -1028,15 +1027,15 @@ public class LuceneService implements Runnable {
                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
@@ -1054,6 +1053,7 @@ public class LuceneService implements Runnable {
                                searcher = new IndexSearcher(reader);\r
                        }\r
 \r
+                       BooleanQuery query = bldr.build();\r
                        Query rewrittenQuery = searcher.rewrite(query);\r
                        logger.debug(rewrittenQuery.toString());\r
 \r
index 652323a4c5e2a9b6ef8ad284fdb255809de51ac4..b765cc660df99c3d825df883d767cb4b27e65480 100644 (file)
@@ -200,8 +200,7 @@ public class TicketIndexer {
                        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);
@@ -286,8 +285,7 @@ public class TicketIndexer {
        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);
@@ -331,23 +329,23 @@ public class TicketIndexer {
                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());
 
@@ -406,7 +404,7 @@ public class TicketIndexer {
                                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);