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 2f1f8b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ protected String generatePhrase(WordsAndScores[] terms) {
if (terms[i] == null) {
termsToOutput[i] = null;
} else {
String outputWord = terms[i].getWordToOutput();
// if the term to put in this position is in the stop list, increment the corresponding *skippedWords and put nothing in this position
if (terms[i].getWordToOutput() == null) {
if (outputWord == null) {
if (i <= (terms.length / 2)) {
leftSkippedWords++;
} else {
Expand All @@ -369,7 +370,7 @@ protected String generatePhrase(WordsAndScores[] terms) {
termsToOutput[i] = null;
} else {
// if the term to output is valid, put it in the same position in the new array
termsToOutput[i] = terms[i].getWordToOutput();
termsToOutput[i] = outputWord;
if ((bef || aft) && (terms[i].getHasHitTerm())) {
if (!lock) {
afterIndex = i;
Expand Down
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 2f1f8b2

Please sign in to comment.