org.apache.solr.handler.component.SpellCheckMergeData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.component;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.search.spell.SuggestWord;
import org.apache.solr.client.solrj.response.SpellCheckResponse;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.spelling.SpellCheckCollation;
public class SpellCheckMergeData {
// original token -> corresponding Suggestion object (keep track of start,end)
public Map origVsSuggestion = new HashMap<>();
// original token string -> summed up frequency
public Map origVsFreq = new HashMap<>();
// original token string -> # of shards reporting it as misspelled
public Map origVsShards = new HashMap<>();
// original token string -> set of alternatives
// must preserve order because collation algorithm can only work in-order
public Map> origVsSuggested = new LinkedHashMap<>();
// alternative string -> corresponding SuggestWord object
public Map suggestedVsWord = new HashMap<>();
public Map collations = new HashMap<>();
// The original terms from the user's query.
public Set originalTerms = null;
public int totalNumberShardResponses = 0;
/**
* Removes the original word from all maps where original words are used as keys, as well as any
* collations that contain this original word as a misspelling
*/
public void removeOriginal(final String original) {
origVsFreq.remove(original);
origVsShards.remove(original);
origVsSuggested.remove(original);
final Iterator> iter = collations.entrySet().iterator();
iter.forEachRemaining(
e -> {
final NamedList misspellings = e.getValue().getMisspellingsAndCorrections();
if (null != misspellings && null != misspellings.get(original)) {
iter.remove();
}
});
}
public boolean isOriginalToQuery(String term) {
if (originalTerms == null) {
return true;
}
return originalTerms.contains(term);
}
}