-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Conditional stemming for 'persian' analyzer #113482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cbuescher
merged 19 commits into
elastic:lucene_snapshot
from
cbuescher:persian-analyzer-l10
Oct 2, 2024
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
17b1493
Conditional stemming for 'persian' analyzer
cbuescher 884d894
Guard yaml stemming test with cluster feature
cbuescher 7de8e97
spotless
cbuescher 6fdeb79
Add full cluster restart test
cbuescher b132af7
Delete yaml test that is covered elsewhere
cbuescher ddb3f4d
Merge branch 'lucene_snapshot' into persian-analyzer-l10
cbuescher 6b4c080
Move node feature around
cbuescher b7dcf4c
Merge branch 'lucene_snapshot' into persian-analyzer-l10
cbuescher afc0ef2
Fix test compilation
cbuescher bf67cf9
Remove RestFeatures from diff
cbuescher e32f074
Merge branch 'lucene_snapshot' into persian-analyzer-l10
cbuescher 180baef
Fix wrong lang-analyzer docs
cbuescher 19ed019
Merge branch 'lucene_snapshot' into persian-analyzer-l10
cbuescher 11003e4
Add changelog
cbuescher c17e63f
Merge branch 'lucene_snapshot' into persian-analyzer-l10
cbuescher 57b0686
Revert changes in AnalyzerProvider interface
cbuescher a20d54b
Update changelog
cbuescher 558a0c6
Mute org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT te…
elasticsearchmachine 8477a40
Merge branch 'lucene_snapshot' into persian-analyzer-l10
cbuescher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,26 @@ | ||
pr: 113482 | ||
summary: The 'persian' analyzer has stemmer by default | ||
area: Analysis | ||
type: breaking | ||
issues: [] | ||
breaking: | ||
title: The 'persian' analyzer has stemmer by default | ||
area: Analysis | ||
details: >- | ||
Lucene 10 has added a final stemming step to its PersianAnalyzer that we | ||
expose as 'persian' analyzer. Existing indices will keep the old | ||
non-stemming behaviour while new indices will see the updated behaviour with | ||
added stemming. | ||
Users that want to maintain the non-stemming behaviour need to define their | ||
own analyzer as outlines in | ||
https://www.elastic.co/guide/en/elasticsearch/reference/8.15/analysis-lang-analyzer.html#persian-analyzer. | ||
Users that want to use the new stemming behaviour for existing indices will | ||
have to reindex their data. | ||
impact: >- | ||
Indexing with the 'persian' analyzer will produce slightly different token. | ||
Users should check if this impacts their search results. If they want to | ||
maintain the legacy non-stemming behaviour they can define their own | ||
analyzer equivalent as explained in | ||
https://www.elastic.co/guide/en/elasticsearch/reference/8.15/analysis-lang-analyzer.html#persian-analyzer. | ||
notable: false | ||
|
This file contains hidden or 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
78 changes: 78 additions & 0 deletions
78
...-common/src/test/java/org/elasticsearch/analysis/common/PersianAnalyzerProviderTests.java
This file contains hidden or 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,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.analysis.common; | ||
|
||
import org.apache.lucene.analysis.Analyzer; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.IndexVersion; | ||
import org.elasticsearch.index.IndexVersions; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.ESTokenStreamTestCase; | ||
import org.elasticsearch.test.IndexSettingsModule; | ||
import org.elasticsearch.test.index.IndexVersionUtils; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.apache.lucene.tests.analysis.BaseTokenStreamTestCase.assertAnalyzesTo; | ||
|
||
/** | ||
* Tests Persian Analyzer factory and behavioural changes with Lucene 10 | ||
*/ | ||
public class PersianAnalyzerProviderTests extends ESTokenStreamTestCase { | ||
|
||
public void testPersianAnalyzerPostLucene10() throws IOException { | ||
IndexVersion postLucene10Version = IndexVersionUtils.randomVersionBetween( | ||
random(), | ||
IndexVersions.UPGRADE_TO_LUCENE_10_0_0, | ||
IndexVersion.current() | ||
); | ||
Settings settings = ESTestCase.indexSettings(1, 1) | ||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) | ||
.put(IndexMetadata.SETTING_VERSION_CREATED, postLucene10Version) | ||
.build(); | ||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); | ||
Environment environment = new Environment(settings, null); | ||
|
||
PersianAnalyzerProvider persianAnalyzerProvider = new PersianAnalyzerProvider( | ||
idxSettings, | ||
environment, | ||
"my-analyzer", | ||
Settings.EMPTY | ||
); | ||
Analyzer analyzer = persianAnalyzerProvider.get(); | ||
assertAnalyzesTo(analyzer, "من کتاب های زیادی خوانده ام", new String[] { "كتاب", "زياد", "خوانده" }); | ||
} | ||
|
||
public void testPersianAnalyzerPreLucene10() throws IOException { | ||
IndexVersion preLucene10Version = IndexVersionUtils.randomVersionBetween( | ||
random(), | ||
IndexVersionUtils.getFirstVersion(), | ||
IndexVersionUtils.getPreviousVersion(IndexVersions.UPGRADE_TO_LUCENE_10_0_0) | ||
); | ||
Settings settings = ESTestCase.indexSettings(1, 1) | ||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) | ||
.put(IndexMetadata.SETTING_VERSION_CREATED, preLucene10Version) | ||
.build(); | ||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); | ||
Environment environment = new Environment(settings, null); | ||
|
||
PersianAnalyzerProvider persianAnalyzerProvider = new PersianAnalyzerProvider( | ||
idxSettings, | ||
environment, | ||
"my-analyzer", | ||
Settings.EMPTY | ||
); | ||
Analyzer analyzer = persianAnalyzerProvider.get(); | ||
assertAnalyzesTo(analyzer, "من کتاب های زیادی خوانده ام", new String[] { "كتاب", "زيادي", "خوانده" }); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.