-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose DelimitedTermFrequencyTokenFilter
Relates: #9413 This commit exposes Lucene's delimited term frequency token filter to be able to provide term frequencies along with terms. Signed-off-by: Russ Cam <[email protected]>
- Loading branch information
Showing
5 changed files
with
97 additions
and
3 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
46 changes: 46 additions & 0 deletions
46
...rc/main/java/org/opensearch/analysis/common/DelimitedTermFrequencyTokenFilterFactory.java
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,46 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.analysis.common; | ||
|
||
import org.apache.lucene.analysis.TokenStream; | ||
import org.apache.lucene.analysis.miscellaneous.DelimitedTermFrequencyTokenFilter; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.env.Environment; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.index.analysis.AbstractTokenFilterFactory; | ||
|
||
public class DelimitedTermFrequencyTokenFilterFactory extends AbstractTokenFilterFactory { | ||
public static final char DEFAULT_DELIMITER = '|'; | ||
private static final String DELIMITER = "delimiter"; | ||
private final char delimiter; | ||
|
||
DelimitedTermFrequencyTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { | ||
super(indexSettings, name, settings); | ||
delimiter = parseDelimiter(settings); | ||
} | ||
|
||
@Override | ||
public TokenStream create(TokenStream tokenStream) { | ||
return new DelimitedTermFrequencyTokenFilter(tokenStream, delimiter); | ||
} | ||
|
||
private static char parseDelimiter(Settings settings) throws IllegalArgumentException { | ||
String delimiter = settings.get(DELIMITER); | ||
if (delimiter == null) { | ||
return DEFAULT_DELIMITER; | ||
} else if (delimiter.length() == 1) { | ||
return delimiter.charAt(0); | ||
} | ||
|
||
throw new IllegalArgumentException( | ||
"Setting [" + DELIMITER + "] must be a single, non-null character. [" + delimiter + "] was provided." | ||
); | ||
} | ||
} | ||
|
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
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