From 7ea5cb8e0936784c830ecb2c1326945277e49a44 Mon Sep 17 00:00:00 2001 From: Roman Chyla Date: Mon, 3 Oct 2016 19:30:43 -0400 Subject: [PATCH] The cites collector is behaving weirdly --- .../AqpAdsabsCarefulAnalyzerProcessor.java | 7 +++++-- .../lucene/search/TestCitationsSearch.java | 18 +++++++++++++++--- ...AqpDebuggingQueryNodeProcessorPipeline.java | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/processors/AqpAdsabsCarefulAnalyzerProcessor.java b/contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/processors/AqpAdsabsCarefulAnalyzerProcessor.java index c0b1a3a06..dae114f4e 100644 --- a/contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/processors/AqpAdsabsCarefulAnalyzerProcessor.java +++ b/contrib/adsabs/src/java/org/apache/lucene/queryparser/flexible/aqp/processors/AqpAdsabsCarefulAnalyzerProcessor.java @@ -66,11 +66,14 @@ protected QueryNode postProcessNode(QueryNode node) if (node instanceof WildcardQueryNode) { field = ((WildcardQueryNode) node).getFieldAsString(); value = ((WildcardQueryNode) node).getTextAsString(); + if (value.indexOf('*') == 0 || value.indexOf('?') == 0) + return node; //let the analyzer decide the fate + for (String suffix: new String[]{"_wildcard", ""}) { if (hasAnalyzer(field + suffix)) { - tokens = analyze(field + suffix, "foo*bar"); + tokens = analyze(field + suffix, value); - if (tokens.length > 1 || value.indexOf('*') == 0 || value.indexOf('?') == 0) + if (tokens.length > 1) return node; // break, let the analyzer decide the fate if (!tokens[0].equals(value)) { diff --git a/contrib/adsabs/src/test/org/apache/lucene/search/TestCitationsSearch.java b/contrib/adsabs/src/test/org/apache/lucene/search/TestCitationsSearch.java index d9d3b2fbd..e5bbe0beb 100644 --- a/contrib/adsabs/src/test/org/apache/lucene/search/TestCitationsSearch.java +++ b/contrib/adsabs/src/test/org/apache/lucene/search/TestCitationsSearch.java @@ -4,11 +4,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Random; +import java.util.Set; import monty.solr.util.MontySolrAbstractTestCase; import monty.solr.util.MontySolrSetup; @@ -136,12 +139,12 @@ public void testCitesCollector() throws Exception { HashMap references = createRandomDocs(0, new Float(maxHits * 0.4f).intValue()); - assertU(commit()); // closes the writer, create a new segment + assertU(commit("waitSearcher", "true")); // closes the writer, create a new segment references.putAll(createRandomDocs(new Float(maxHits * 0.3f).intValue(), new Float(maxHits * 0.7f).intValue())); - assertU(commit()); // closes the writer, create a new segment + assertU(commit("waitSearcher", "true")); // closes the writer, create a new segment references.putAll(createRandomDocs(new Float(maxHits * 0.71f).intValue(), new Float(maxHits * 1.0f).intValue())); assertU(commit("waitSearcher", "true")); // closes the writer, create a new segment @@ -339,12 +342,21 @@ private boolean hitsEquals(int[] thisDocCites, HashMap cites, Sc return false; } } + Set exp = new HashSet(); ArrayList expected = new ArrayList(); for (int r: thisDocCites) { if (cites.containsKey(r)) { - expected.add(r); + exp.add(r); } } + for (Integer x: exp) { + expected.add(x); + } + Collections.sort(expected); + Collections.sort(result); + + + assertEquals(expected, result); if (!(result.containsAll(expected) && expected.containsAll(result))) { System.err.println("expected: " + expected.toString() + " actual: " + result.toString()); } diff --git a/contrib/antlrqueryparser/src/java/org/apache/lucene/queryparser/flexible/aqp/util/AqpDebuggingQueryNodeProcessorPipeline.java b/contrib/antlrqueryparser/src/java/org/apache/lucene/queryparser/flexible/aqp/util/AqpDebuggingQueryNodeProcessorPipeline.java index 5515be472..e1938fd17 100644 --- a/contrib/antlrqueryparser/src/java/org/apache/lucene/queryparser/flexible/aqp/util/AqpDebuggingQueryNodeProcessorPipeline.java +++ b/contrib/antlrqueryparser/src/java/org/apache/lucene/queryparser/flexible/aqp/util/AqpDebuggingQueryNodeProcessorPipeline.java @@ -43,6 +43,7 @@ public QueryNode process(QueryNode queryTree) throws QueryNodeException { newMap = oldMap; int i = 1; + System.out.println( this.getClass().toGenericString()); System.out.println(" 0. starting"); System.out.println("--------------------------------------------"); System.out.println(oldVal);