Stemmer
The stemmer
filter reduces words to their base or root form (known as stemming), making it easier to match words with similar meanings across different inflections. The stemmer
filter supports multiple languages, allowing for effective search and indexing in various linguistic contexts.
Configuration
The stemmer
filter is a custom filter in Milvus. To use it, specify "type": "stemmer"
in the filter configuration, along with a language
parameter to select the desired language for stemming.
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stemmer", # Specifies the filter type as stemmer
"language": "english", # Sets the language for stemming to English
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(
new HashMap<String, Object>() {{
put("type", "stemmer");
put("language", "english");
}}
)
);
const analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stemmer", // Specifies the filter type as stop
"language": "english",
}],
};
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "stemmer",
"language": "english",
}}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
{
"type": "stemmer",
"language": "english"
}
]
}'
The stemmer
filter accepts the following configurable parameters.
Parameter |
Description |
---|---|
|
Specifies the language for the stemming process. Supported languages include: |
The stemmer
filter operates on the terms generated by the tokenizer, so it must be used in combination with a tokenizer.
After defining analyzer_params
, you can apply them to a VARCHAR
field when defining a collection schema. This allows Milvus to process the text in that field using the specified analyzer for efficient tokenization and filtering. For details, refer to Example use.
Examples
Before applying the analyzer configuration to your collection schema, verify its behavior using the run_analyzer
method.
Analyzer configuration
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stemmer", # Specifies the filter type as stemmer
"language": "english", # Sets the language for stemming to English
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(
new HashMap<String, Object>() {{
put("type", "stemmer");
put("language", "english");
}}
)
);
// javascript
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "stemmer",
"language": "english",
}}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
{
"type": "stemmer",
"language": "english"
}
]
}'
Verification using run_analyzer
# Sample text to analyze
sample_text = "running runs looked ran runner"
# Run the standard analyzer with the defined configuration
result = MilvusClient.run_analyzer(sample_text, analyzer_params)
print(result)
// java
// javascript
// go
# restful
not support yet
Expected output
['run', 'run', 'look', 'ran', 'runner']