Skip to content

Commit

Permalink
Or, you know, KISS and just get rid of the inheritance...
Browse files Browse the repository at this point in the history
Revert the whole bytecode approach, just remove the tight coupling
introduced by the inheritance and it's compatible with all Lucene
versions without nasty hacks.
  • Loading branch information
jbaiter committed Sep 12, 2024
1 parent 4a2b69f commit 1606f54
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 136 deletions.
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,23 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${version.maven-javadoc-plugin}</version>
<configuration>
<additionalOptions>-Xdoclint:none</additionalOptions>
<additionalJOption>-Xdoclint:none</additionalJOption>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,33 @@
import org.apache.lucene.search.uhighlight.FieldOffsetStrategy;
import org.apache.lucene.search.uhighlight.OffsetsEnum;
import org.apache.lucene.search.uhighlight.Passage;
import org.apache.lucene.search.uhighlight.PassageFormatter;
import org.apache.lucene.search.uhighlight.PassageScorer;
import org.apache.lucene.search.uhighlight.UnifiedHighlighter;
import org.apache.lucene.util.BytesRef;

/** A customization of {@link FieldHighlighter} to support OCR fields */
public class OcrFieldHighlighter extends FieldHighlighterAdapter {
public class OcrFieldHighlighter {
private final ConcurrentHashMap<Integer, Integer> numMatches;

private final String field;
private final FieldOffsetStrategy fieldOffsetStrategy;
private final PassageScorer passageScorer;
private final int maxPassages;
private final int maxNoHighlightPassages;

public OcrFieldHighlighter(
String field,
FieldOffsetStrategy fieldOffsetStrategy,
PassageScorer passageScorer,
int maxPassages,
int maxNoHighlightPassages) {
super(field, fieldOffsetStrategy, passageScorer, maxPassages, maxNoHighlightPassages);
this.numMatches = new ConcurrentHashMap<>();
this.field = field;
this.fieldOffsetStrategy = fieldOffsetStrategy;
this.passageScorer = passageScorer;
this.maxPassages = maxPassages;
this.maxNoHighlightPassages = maxNoHighlightPassages;
}

/**
Expand Down Expand Up @@ -111,7 +123,6 @@ public OcrSnippet[] highlightFieldForDoc(
}
}

@Override
protected Passage[] highlightOffsetsEnums(OffsetsEnum off) {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -265,11 +276,14 @@ private Passage maybeAddPassage(
}

/** We don't provide summaries if there is no highlighting, i.e. no matches in the OCR text */
@Override
protected Passage[] getSummaryPassagesNoHighlight(int maxPassages) {
return new Passage[] {};
}

public UnifiedHighlighter.OffsetSource getOffsetSource() {
return this.fieldOffsetStrategy.getOffsetSource();
}

public int getNumMatches(int docId) {
return numMatches.getOrDefault(docId, -1);
}
Expand Down
Binary file not shown.

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/resources/com/github/dbmdz/solrocr/lucene/README.md

This file was deleted.

0 comments on commit 1606f54

Please sign in to comment.