-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to Solr 8.6 * Adding a test workflow * Fix workflow name * Working on fixing the random number error * Bringing over the highlighter helpers * Release workflow
- Loading branch information
Showing
9 changed files
with
285 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Java CI | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set release version Name | ||
run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF#refs/*/} | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
env: | ||
MAVEN_OPTS: -Dtest.solr.allowed.securerandom=NativePRNG | ||
- name: Stage jar | ||
run: cp target/*.jar payload-component-${{ env.RELEASE_VERSION }}.jar | ||
- name: Create Release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.RELEASE_VERSION }} | ||
release_name: ${{ env.RELEASE_VERSION }} | ||
draft: false | ||
prerelease: false | ||
- name: Upload Release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./payload-component-${{ env.RELEASE_VERSION }}.jar | ||
asset_name: payload-component-${{ env.RELEASE_VERSION }}.jar | ||
asset_content_type: application/java-archive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Java CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
env: | ||
MAVEN_OPTS: -Dtest.solr.allowed.securerandom=NativePRNG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
.idea/* | ||
target/* | ||
solr-payloads.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.o19s.hl; | ||
|
||
import org.apache.lucene.search.highlight.Formatter; | ||
import org.apache.solr.common.params.HighlightParams; | ||
import org.apache.solr.common.params.SolrParams; | ||
import org.apache.solr.highlight.HighlightingPluginBase; | ||
import org.apache.solr.highlight.SolrFormatter; | ||
|
||
public class OffsetFormatter extends HighlightingPluginBase implements SolrFormatter { | ||
@Override | ||
public Formatter getFormatter(String fieldName, SolrParams params) { | ||
return new SimpleOffsetFormatter( | ||
params.getFieldParam(fieldName, HighlightParams.SIMPLE_PRE, "<em data-num-tokens=\"$numTokens\" data-score=\"$score\" data-end-offset=\"$endOffset\" data-start-offset=\"$startOffset\">"), | ||
params.getFieldParam(fieldName, HighlightParams.SIMPLE_POST, "</em>") | ||
); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "OffsetFormatter"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.o19s.hl; | ||
|
||
import org.apache.lucene.search.highlight.Formatter; | ||
import org.apache.lucene.search.highlight.TokenGroup; | ||
|
||
public class SimpleOffsetFormatter implements Formatter { | ||
private static final String DEFAULT_PRE_TAG = "<b>"; | ||
private static final String DEFAULT_POST_TAG = "</b>"; | ||
|
||
private String preTag; | ||
private String postTag; | ||
|
||
public SimpleOffsetFormatter() { | ||
this(DEFAULT_PRE_TAG, DEFAULT_POST_TAG); | ||
} | ||
|
||
public SimpleOffsetFormatter(String preTag, String postTag) { | ||
this.preTag = preTag; | ||
this.postTag = postTag; | ||
} | ||
|
||
@Override | ||
public String highlightTerm(String matchedText, TokenGroup tokenGroup) { | ||
if (tokenGroup.getTotalScore() <= 0) { | ||
return matchedText; | ||
} | ||
|
||
// Allocate StringBuilder with the right number of characters from the | ||
// beginning, to avoid char[] allocations in the middle of appends. | ||
StringBuilder returnBuffer = new StringBuilder(preTag.length() + matchedText.length() + postTag.length()); | ||
|
||
String replacedPre = preTag | ||
// Total score for the group | ||
.replace("$score", Float.toString(tokenGroup.getTotalScore())) | ||
|
||
// Offsets | ||
.replace("$endOffset", Integer.toString(tokenGroup.getEndOffset())) | ||
.replace("$startOffset", Integer.toString(tokenGroup.getStartOffset())) | ||
|
||
// Number of tokens in the group | ||
.replace("$numTokens", Integer.toString(tokenGroup.getNumTokens())); | ||
|
||
returnBuffer.append(replacedPre); | ||
returnBuffer.append(matchedText); | ||
returnBuffer.append(postTag); | ||
return returnBuffer.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.o19s.hl; | ||
|
||
import org.apache.solr.SolrTestCaseJ4; | ||
import org.apache.solr.util.TestHarness; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
|
||
public class OffsetTests extends SolrTestCaseJ4 { | ||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
initCore("solrconfig.xml","schema.xml"); | ||
} | ||
|
||
@Test | ||
public void testOffsets() { | ||
HashMap<String, String> args = new HashMap<>(); | ||
args.put("defType", "edismax"); | ||
args.put("hl", "true"); | ||
args.put("hl.fl", "content"); | ||
args.put("qf", "content"); | ||
args.put("q.alt", "*:*"); | ||
TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory( | ||
"standard", 0, 200, args); | ||
|
||
assertU(adoc("content", "A long day's night.", | ||
"id", "1")); | ||
assertU(commit()); | ||
assertU(optimize()); | ||
assertQ("Offset test", | ||
sumLRF.makeRequest("night"), | ||
"//lst[@name='highlighting']/lst[@name='1']", | ||
"//lst[@name='1']/arr[@name='content']/str[contains(text(),'data-num-tokens=\"1\"')]", | ||
"//lst[@name='1']/arr[@name='content']/str[contains(text(),'data-score=\"1.0\"')]", | ||
"//lst[@name='1']/arr[@name='content']/str[contains(text(),'data-start-offset=\"13\"')]", | ||
"//lst[@name='1']/arr[@name='content']/str[contains(text(),'data-end-offset=\"18\"')]" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters