Skip to content

Commit

Permalink
Fix getTermCountsWithAnalyzer when term has a colon in it (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
lintool committed May 2, 2020
1 parent 380d22b commit d75f39c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/io/anserini/index/IndexReaderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ public static IndexReader getReader(String path) throws IOException {
return DirectoryReader.open(dir);
}

public static Map<String, Long> getTermCounts(IndexReader reader, String termStr) throws IOException, ParseException {
public static Map<String, Long> getTermCounts(IndexReader reader, String termStr)
throws IOException {
DefaultEnglishAnalyzer ea = DefaultEnglishAnalyzer.newDefaultInstance();
return getTermCountsWithAnalyzer(reader, termStr, ea);
}

public static Map<String, Long> getTermCountsWithAnalyzer(IndexReader reader, String termStr, Analyzer analyzer) throws IOException, ParseException {
QueryParser qp = new QueryParser(IndexArgs.CONTENTS, analyzer);
TermQuery q = (TermQuery) qp.parse(termStr);
Term t = q.getTerm();
public static Map<String, Long> getTermCountsWithAnalyzer(IndexReader reader, String termStr, Analyzer analyzer)
throws IOException {
Term t = new Term(IndexArgs.CONTENTS, AnalyzerUtils.analyze(analyzer, termStr).get(0));

Map<String, Long> termInfo = Map.ofEntries(
Map.entry("collectionFreq", reader.totalTermFreq(t)),
Expand All @@ -227,7 +227,7 @@ public static Map<String, Long> getTermCountsWithAnalyzer(IndexReader reader, St
* @throws IOException if error encountered during access to index
*/
public static Iterator<IndexTerm> getTerms(IndexReader reader) throws IOException {
return new Iterator<IndexTerm>() {
return new Iterator<>() {
private TermsEnum curTerm = MultiTerms.getTerms(reader, "contents").iterator();
private BytesRef bytesRef = null;

Expand Down

0 comments on commit d75f39c

Please sign in to comment.