Skip to content

Commit

Permalink
updates to resolve #2055
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong committed Jul 10, 2019
1 parent 1279d55 commit 7bc1edf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected void determineCPE(Dependency dependency) throws CorruptIndexException,
protected void collectTerms(Map<String, MutableInt> terms, Iterable<Evidence> evidence) {
for (Evidence e : evidence) {
String value = cleanseText(e.getValue());
if (value.isEmpty()) {
if (StringUtils.isBlank(value)) {
continue;
}
if (value.length() > 1000) {
Expand Down Expand Up @@ -484,6 +484,8 @@ private boolean appendWeightedSearch(StringBuilder sb, String field, Map<String,
}
sb.append(field).append(":(");
boolean addSpace = false;
boolean addedTerm = false;

for (Map.Entry<String, MutableInt> entry : terms.entrySet()) {
final StringBuilder boostedTerms = new StringBuilder();
final int weighting = entry.getValue().intValue();
Expand All @@ -497,6 +499,7 @@ private boolean appendWeightedSearch(StringBuilder sb, String field, Map<String,
} else {
addSpace = true;
}
addedTerm=true;
if (LuceneUtils.isKeyword(word)) {
sb.append("\"");
LuceneUtils.appendEscapedLuceneQuery(sb, word);
Expand Down Expand Up @@ -525,7 +528,7 @@ private boolean appendWeightedSearch(StringBuilder sb, String field, Map<String,
}
}
sb.append(")");
return true;
return addedTerm;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ public synchronized TopDocs search(String searchString, int maxQueryResults) thr
* analyzers
*/
public synchronized Query parseQuery(String searchString) throws ParseException, IndexException {
if (searchString == null || searchString.trim().isEmpty()) {
if (searchString == null || searchString.trim().isEmpty()
|| "product:() AND vendor:()".equals(searchString)) {
throw new ParseException("Query is null or empty");
}
LOGGER.debug(searchString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ public void testAddEvidenceWithoutDuplicateTerms() {
assertEquals(expValue, terms.get(expResult).intValue());
}

@Test
public void testCollectTerms() {
Map<String, MutableInt> terms = new HashMap<>();
List<Evidence> evidence = new ArrayList<>();
evidence.add(new Evidence("\\@", "\\*", "\\+", Confidence.HIGHEST));
CPEAnalyzer instance = new CPEAnalyzer();
instance.collectTerms(terms, evidence);
assertTrue(terms.isEmpty());
}

/**
* Test of buildSearch method, of class CPEAnalyzer.
*/
Expand Down Expand Up @@ -267,4 +277,18 @@ public void testBuildSearch() {
result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
assertEquals(expResult, result);
}

@Test
public void testBuildSearchBlank() {
Map<String, MutableInt> vendor = new HashMap<>();
Map<String, MutableInt> product = new HashMap<>();
vendor.put(" ", new MutableInt(1));
product.put(" ", new MutableInt(1));
Set<String> vendorWeighting = new HashSet<>();
Set<String> productWeightings = new HashSet<>();

CPEAnalyzer instance = new CPEAnalyzer();
String result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
assertNull(result);
}
}

0 comments on commit 7bc1edf

Please sign in to comment.