Skip to content

Commit 4f05ef7

Browse files
committed
Histogram snippets is working
1 parent 6fdce0f commit 4f05ef7

8 files changed

Lines changed: 599 additions & 538 deletions

File tree

common/src/java/com/github/oeuvres/alix/lucene/output/DocSpanHighlighter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.lucene.search.ScoreMode;
2424

2525
import com.github.oeuvres.alix.lucene.spans.SpanMatch;
26-
import com.github.oeuvres.alix.lucene.spans.SpanWalkerDeprecated;
2726
import com.github.oeuvres.alix.util.IntIntMap;
2827

2928
/**

common/src/java/com/github/oeuvres/alix/lucene/output/HtmlResults.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.apache.lucene.index.StoredFields;
99

1010
import com.github.oeuvres.alix.lucene.spans.SpanMatch;
11+
import com.github.oeuvres.alix.lucene.spans.SpanWalker.SnippetsConsumer;
1112
import com.github.oeuvres.alix.lucene.spans.SpanListener;
1213
import com.github.oeuvres.alix.util.Detagger;
1314
import com.github.oeuvres.alix.util.Markup;
@@ -29,7 +30,7 @@
2930
* ({@link #lastDocId} + 1). The caller is responsible for turning that into a
3031
* full URL.</p>
3132
*/
32-
public class HtmlResults implements SpanListener
33+
public class HtmlResults implements SnippetsConsumer
3334
{
3435
private final Writer writer;
3536
private final StoredFields storedFields;

common/src/java/com/github/oeuvres/alix/lucene/spans/HistoListener.java

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.oeuvres.alix.lucene.spans;
2+
3+
import java.io.IOException;
4+
import java.util.Objects;
5+
6+
import com.github.oeuvres.alix.lucene.output.HistoNum;
7+
import com.github.oeuvres.alix.lucene.output.HistoNum.Col;
8+
import com.github.oeuvres.alix.lucene.spans.SpanWalker.SnippetsConsumer;
9+
10+
public class HistoSnippets implements SnippetsConsumer
11+
{
12+
private final HistoNum histo;
13+
14+
/**
15+
* Accumulates snippets counts into {@link NumHisto#SNIPPETS} of the given histogram.
16+
*/
17+
public HistoSnippets(final HistoNum histo)
18+
{
19+
this.histo = Objects.requireNonNull(histo);
20+
histo.valueSnippets = new int[histo.length()];
21+
histo.valueDocs = new int[histo.length()];
22+
histo.cols().add(Col.SNIPPETS);
23+
histo.cols().add(Col.DOCS);
24+
}
25+
26+
@Override
27+
public void docSnippets(int docId, Snippets snippets) throws IOException {
28+
final int histoIndex = histo.index(docId, -1);
29+
if (histoIndex < 0) return;
30+
final int snippetsCount = snippets.snips4doc();
31+
if (snippetsCount <= 0) return;
32+
histo.valueSnippets[histoIndex] += snippetsCount;
33+
histo.valueDocs[histoIndex]++;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)