finish lucene 6 test compatability for fmgr
Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/2f79f68f Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/2f79f68f Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/2f79f68f Branch: refs/heads/master Commit: 2f79f68f3243c04402572b74532b9a20622b5c16 Parents: 2820d5d Author: Tom Barber <[email protected]> Authored: Fri Jul 8 23:00:20 2016 +0100 Committer: Lewis John McGibbney <[email protected]> Committed: Thu Mar 9 21:35:22 2017 -0800 ---------------------------------------------------------------------- .../oodt/cas/filemgr/catalog/LuceneCatalog.java | 66 +++++++++++--------- .../cli/action/LuceneQueryCliAction.java | 10 ++- .../oodt/cas/filemgr/tools/CASAnalyzer.java | 5 +- 3 files changed, 46 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/2f79f68f/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java ---------------------------------------------------------------------- diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java index b54e8f7..4c9ed96 100644 --- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java +++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java @@ -448,20 +448,25 @@ public class LuceneCatalog implements Catalog { SortField.Type.STRING, true)); //TODO FIX NUMBER OF RECORDS TopDocs check = searcher.search(query, 1, sort); - TopDocs topDocs = searcher.search(query, check.totalHits, sort); + if(check.totalHits>0) { + TopDocs topDocs = searcher.search(query, check.totalHits, sort); - ScoreDoc[] hits = topDocs.scoreDocs; + ScoreDoc[] hits = topDocs.scoreDocs; - // should be > 0 hits - if (hits.length > 0) { - // just get the first hit back - Document productDoc = searcher.doc(hits[0].doc); - CompleteProduct prod = toCompleteProduct(productDoc, getRefs, - false); - return prod.getProduct(); - } else { - LOG.log(Level.FINEST, "Request for product by name: [" - + productName + "] returned no results"); + // should be > 0 hits + if (hits.length > 0) { + // just get the first hit back + Document productDoc = searcher.doc(hits[0].doc); + CompleteProduct prod = toCompleteProduct(productDoc, getRefs, + false); + return prod.getProduct(); + } else { + LOG.log(Level.FINEST, "Request for product by name: [" + + productName + "] returned no results"); + return null; + } + } + else{ return null; } @@ -732,22 +737,27 @@ public class LuceneCatalog implements Catalog { + "]"); //TODO FIX NUMBER OF RECORDS TopDocs check = searcher.search(booleanQuery.build(), 1, sort); - TopDocs topDocs = searcher.search(booleanQuery.build(), check.totalHits, sort); + if(check.totalHits>0) { + TopDocs topDocs = searcher.search(booleanQuery.build(), check.totalHits, sort); - ScoreDoc[] hits = topDocs.scoreDocs; + ScoreDoc[] hits = topDocs.scoreDocs; - if (hits.length > 0) { - products = new Vector<Product>(n); - int i = 0; - while (products.size() < Math.min(n, hits.length)) { - Document productDoc = searcher.doc(hits[i].doc); - CompleteProduct prod = toCompleteProduct(productDoc, false, - false); - products.add(prod.getProduct()); - i++; + if (hits.length > 0) { + products = new Vector<Product>(n); + int i = 0; + while (products.size() < Math.min(n, hits.length)) { + Document productDoc = searcher.doc(hits[i].doc); + CompleteProduct prod = toCompleteProduct(productDoc, false, + false); + products.add(prod.getProduct()); + i++; + } + } else { + LOG.log(Level.WARNING, "Top N query produced no products!"); } - } else { - LOG.log(Level.WARNING, "Top N query produced no products!"); + } + else{ + return null; } } catch (IOException e) { @@ -1468,15 +1478,11 @@ public class LuceneCatalog implements Catalog { String startVal = ((RangeQueryCriteria) queryCriteria).getStartValue(); String endVal = ((RangeQueryCriteria) queryCriteria).getEndValue(); boolean inclusive = ((RangeQueryCriteria) queryCriteria).getInclusive(); - Term startTerm = null, endTerm = null; + Term startTerm = null; if (!startVal.equals("")) { startTerm = new Term(queryCriteria.getElementName(), startVal); } - if (!endVal.equals("")) { - endTerm = new Term(queryCriteria.getElementName(), endVal); - } - return TermRangeQuery.newStringRange(startTerm.field(), startVal, endVal, inclusive,inclusive); }else { throw new CatalogException("Invalid QueryCriteria [" http://git-wip-us.apache.org/repos/asf/oodt/blob/2f79f68f/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java ---------------------------------------------------------------------- diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java index 85e06cd..c91790c 100644 --- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java +++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java @@ -20,6 +20,7 @@ package org.apache.oodt.cas.filemgr.cli.action; import com.google.common.collect.Lists; import org.apache.commons.lang.Validate; +import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; @@ -80,8 +81,7 @@ public class LuceneQueryCliAction extends AbstractQueryCliAction { private Query parseQuery(String query) throws ParseException { // note that "__FREE__" is a control work for free text searching - return (Query) new QueryParser(FREE_TEXT_BLOCK, new CASAnalyzer()) - .parse(query); + return (Query) new QueryParser(FREE_TEXT_BLOCK, new WhitespaceAnalyzer()).parse(query); } private QueryCriteria generateCASQuery(Query luceneQuery) @@ -110,8 +110,12 @@ public class LuceneQueryCliAction extends AbstractQueryCliAction { BytesRef startT = ((TermRangeQuery) luceneQuery).getLowerTerm(); BytesRef endT = ((TermRangeQuery) luceneQuery).getUpperTerm(); //TODO CHECK Inclusive + boolean inc = false; + if(((TermRangeQuery) luceneQuery).includesLower() && ((TermRangeQuery) luceneQuery).includesUpper()){ + inc = true; + } return new RangeQueryCriteria(((TermRangeQuery) luceneQuery).getField(), startT - .utf8ToString(), endT.utf8ToString()/*, ((TermRangeQuery) luceneQuery).isInclusive()*/); + .utf8ToString(), endT.utf8ToString(), inc); } else if (luceneQuery instanceof BooleanQuery) { List<BooleanClause> clauses = ((BooleanQuery) luceneQuery).clauses(); BooleanQueryCriteria bqc = new BooleanQueryCriteria(); http://git-wip-us.apache.org/repos/asf/oodt/blob/2f79f68f/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/CASAnalyzer.java ---------------------------------------------------------------------- diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/CASAnalyzer.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/CASAnalyzer.java index 9470c62..bfe2384 100644 --- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/CASAnalyzer.java +++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/CASAnalyzer.java @@ -78,14 +78,15 @@ public class CASAnalyzer extends Analyzer { } /** Builds an analyzer with the given stop words. */ public CASAnalyzer(CharArraySet stopWords) { - //stopSet = StopFilter.makeStopSet(stopWords); + stopSet = StopFilter.makeStopSet(stopWords.toArray(new String[stopWords.size()])); + } /** * Constructs a {@link org.apache.lucene.analysis.standard.StandardTokenizer} filtered by a {@link * StandardFilter}, a {@link LowerCaseFilter} and a {@link StopFilter}. */ - /*public TokenStream tokenStream(String fieldName, Reader reader) { + /*4public TokenStream tokenStream(String fieldName, Reader reader) { TokenStream result = new WhitespaceTokenizer(reader); result = new StandardFilter(result); result = new StopFilter(result, stopSet);
