2424import org .apache .lucene .search .similarities .AfterEffectL ;
2525import org .apache .lucene .search .similarities .BM25Similarity ;
2626import org .apache .lucene .search .similarities .BasicModel ;
27- import org .apache .lucene .search .similarities .BasicModelBE ;
28- import org .apache .lucene .search .similarities .BasicModelD ;
2927import org .apache .lucene .search .similarities .BasicModelG ;
3028import org .apache .lucene .search .similarities .BasicModelIF ;
3129import org .apache .lucene .search .similarities .BasicModelIn ;
3230import org .apache .lucene .search .similarities .BasicModelIne ;
33- import org .apache .lucene .search .similarities .BasicModelP ;
3431import org .apache .lucene .search .similarities .BooleanSimilarity ;
3532import org .apache .lucene .search .similarities .ClassicSimilarity ;
3633import org .apache .lucene .search .similarities .DFISimilarity ;
@@ -74,24 +71,35 @@ private SimilarityProviders() {} // no instantiation
7471 static final String DISCOUNT_OVERLAPS = "discount_overlaps" ;
7572
7673 private static final Map <String , BasicModel > BASIC_MODELS ;
74+ private static final Map <String , String > LEGACY_BASIC_MODELS ;
7775 private static final Map <String , AfterEffect > AFTER_EFFECTS ;
76+ private static final Map <String , String > LEGACY_AFTER_EFFECTS ;
7877
7978 static {
8079 Map <String , BasicModel > models = new HashMap <>();
81- models .put ("be" , new BasicModelBE ());
82- models .put ("d" , new BasicModelD ());
8380 models .put ("g" , new BasicModelG ());
8481 models .put ("if" , new BasicModelIF ());
8582 models .put ("in" , new BasicModelIn ());
8683 models .put ("ine" , new BasicModelIne ());
87- models .put ("p" , new BasicModelP ());
8884 BASIC_MODELS = unmodifiableMap (models );
8985
86+ Map <String , String > legacyModels = new HashMap <>();
87+ // TODO: be and g and both based on the bose-einstein model.
88+ // Is there a better replacement for d and p which use the binomial model?
89+ legacyModels .put ("be" , "g" );
90+ legacyModels .put ("d" , "ine" );
91+ legacyModels .put ("p" , "ine" );
92+ LEGACY_BASIC_MODELS = unmodifiableMap (legacyModels );
93+
9094 Map <String , AfterEffect > effects = new HashMap <>();
91- effects .put ("no" , new AfterEffect .NoAfterEffect ());
9295 effects .put ("b" , new AfterEffectB ());
9396 effects .put ("l" , new AfterEffectL ());
9497 AFTER_EFFECTS = unmodifiableMap (effects );
98+
99+ Map <String , String > legacyEffects = new HashMap <>();
100+ // l is simpler than b, so this should be a better replacement for "no"
101+ legacyEffects .put ("no" , "l" );
102+ LEGACY_AFTER_EFFECTS = unmodifiableMap (legacyEffects );
95103 }
96104
97105 private static final Map <String , Independence > INDEPENDENCE_MEASURES ;
@@ -124,9 +132,23 @@ private SimilarityProviders() {} // no instantiation
124132 * @param settings Settings to parse
125133 * @return {@link BasicModel} referred to in the Settings
126134 */
127- private static BasicModel parseBasicModel (Settings settings ) {
135+ private static BasicModel parseBasicModel (Version indexCreatedVersion , Settings settings ) {
128136 String basicModel = settings .get ("basic_model" );
129137 BasicModel model = BASIC_MODELS .get (basicModel );
138+
139+ if (model == null ) {
140+ String replacement = LEGACY_BASIC_MODELS .get (basicModel );
141+ if (replacement != null ) {
142+ if (indexCreatedVersion .onOrAfter (Version .V_7_0_0_alpha1 )) {
143+ throw new IllegalArgumentException ("Basic model [" + basicModel + "] isn't supported anymore, please use another model." );
144+ } else {
145+ DEPRECATION_LOGGER .deprecated ("Basic model [" + basicModel + "] isn't supported anymore and has arbitrarily been replaced with [" + replacement + "]." );
146+ model = BASIC_MODELS .get (replacement );
147+ assert model != null ;
148+ }
149+ }
150+ }
151+
130152 if (model == null ) {
131153 throw new IllegalArgumentException ("Unsupported BasicModel [" + basicModel + "], expected one of " + BASIC_MODELS .keySet ());
132154 }
@@ -139,9 +161,23 @@ private static BasicModel parseBasicModel(Settings settings) {
139161 * @param settings Settings to parse
140162 * @return {@link AfterEffect} referred to in the Settings
141163 */
142- private static AfterEffect parseAfterEffect (Settings settings ) {
164+ private static AfterEffect parseAfterEffect (Version indexCreatedVersion , Settings settings ) {
143165 String afterEffect = settings .get ("after_effect" );
144166 AfterEffect effect = AFTER_EFFECTS .get (afterEffect );
167+
168+ if (effect == null ) {
169+ String replacement = LEGACY_AFTER_EFFECTS .get (afterEffect );
170+ if (replacement != null ) {
171+ if (indexCreatedVersion .onOrAfter (Version .V_7_0_0_alpha1 )) {
172+ throw new IllegalArgumentException ("After effect [" + afterEffect + "] isn't supported anymore, please use another effect." );
173+ } else {
174+ DEPRECATION_LOGGER .deprecated ("After effect [" + afterEffect + "] isn't supported anymore and has arbitrarily been replaced with [" + replacement + "]." );
175+ effect = AFTER_EFFECTS .get (replacement );
176+ assert effect != null ;
177+ }
178+ }
179+ }
180+
145181 if (effect == null ) {
146182 throw new IllegalArgumentException ("Unsupported AfterEffect [" + afterEffect + "], expected one of " + AFTER_EFFECTS .keySet ());
147183 }
@@ -263,8 +299,8 @@ public static DFRSimilarity createDfrSimilarity(Settings settings, Version index
263299
264300
265301 return new DFRSimilarity (
266- parseBasicModel (settings ),
267- parseAfterEffect (settings ),
302+ parseBasicModel (indexCreatedVersion , settings ),
303+ parseAfterEffect (indexCreatedVersion , settings ),
268304 parseNormalization (settings ));
269305 }
270306
0 commit comments