Skip to content

Commit

Permalink
change start offset logic
Browse files Browse the repository at this point in the history
  • Loading branch information
austin007008 committed Apr 16, 2024
1 parent 5448dec commit 219b1e1
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,33 @@ private Set<Excerpt> getExcerpts(PhraseIndexes phraseIndexes) {
* @return the excerpt
*/
private String getExcerpt(String field, int start, int end, Range range, ArrayList<String> hitTermValues) {
if (start < 0) {
start = 0;
}
int prevLeftWordsSkipped = 0;
int currLeftWordsSkipped = 0;
boolean leftLock = false;
int prevRightWordsSkipped = 0;
int currRightWordsSkipped = 0;
boolean rightLock = false;
int timesToTry = 1;
float origHalfSize;
if (start < 0) {
origHalfSize = (float) end / 2;
} else {
origHalfSize = (float) (end - start) / 2;
}
float origHalfSize = (float) (end - start) / 2;
excerptIteratorOptions.put(TermFrequencyExcerptIterator.FIELD_NAME, field);
for (int i = 0; i <= timesToTry; i++) {
// if we still need to process the left half...
if (!leftLock) {
// save the value from the last run (or setting to zero if this is the first run)
prevLeftWordsSkipped = currLeftWordsSkipped;
// set the start of the range to the one passed in minus the amount of skipped words in the left half in the previous run
excerptIteratorOptions.put(TermFrequencyExcerptIterator.START_OFFSET, String.valueOf(start - (i * 20)));
if (i == 0) {
excerptIteratorOptions.put(TermFrequencyExcerptIterator.START_OFFSET, String.valueOf(start));
} else {
if (start - (i * 20) > 0) {
excerptIteratorOptions.put(TermFrequencyExcerptIterator.START_OFFSET, String.valueOf(start - (i * 20)));
} else {
excerptIteratorOptions.put(TermFrequencyExcerptIterator.START_OFFSET, String.valueOf(0));
}
}
}
// if we still need to process the right half...
if (!rightLock) {
Expand Down

0 comments on commit 219b1e1

Please sign in to comment.