Example usage for org.apache.solr.spelling SpellCheckCollation setMisspellingsAndCorrections

List of usage examples for org.apache.solr.spelling SpellCheckCollation setMisspellingsAndCorrections

Introduction

In this page you can find the example usage for org.apache.solr.spelling SpellCheckCollation setMisspellingsAndCorrections.

Prototype

public void setMisspellingsAndCorrections(NamedList<String> misspellingsAndCorrections) 

Source Link

Usage

From source file:org.dice.solrenhancements.spellchecker.DiceSpellCheckComponent.java

License:Apache License

@SuppressWarnings("unchecked")
private void collectShardCollations(SpellCheckMergeData mergeData, NamedList spellCheckResponse,
        int maxCollationTries) {
    Map<String, SpellCheckCollation> collations = mergeData.collations;
    NamedList suggestions = (NamedList) spellCheckResponse.get("suggestions");
    if (suggestions != null) {
        List<Object> collationList = suggestions.getAll("collation");
        List<Object> collationRankList = suggestions.getAll("collationInternalRank");
        int i = 0;
        if (collationList != null) {
            for (Object o : collationList) {
                if (o instanceof String) {
                    SpellCheckCollation coll = new SpellCheckCollation();
                    coll.setCollationQuery((String) o);
                    if (collationRankList != null && collationRankList.size() > 0) {
                        coll.setInternalRank((Integer) collationRankList.get(i));
                        i++;//from w w w .j  a va2s. c  om
                    }
                    SpellCheckCollation priorColl = collations.get(coll.getCollationQuery());
                    if (priorColl != null) {
                        coll.setInternalRank(Math.max(coll.getInternalRank(), priorColl.getInternalRank()));
                    }
                    collations.put(coll.getCollationQuery(), coll);
                } else {
                    NamedList expandedCollation = (NamedList) o;
                    SpellCheckCollation coll = new SpellCheckCollation();
                    coll.setCollationQuery((String) expandedCollation.get("collationQuery"));
                    coll.setHits((Integer) expandedCollation.get("hits"));
                    if (maxCollationTries > 0) {
                        coll.setInternalRank((Integer) expandedCollation.get("collationInternalRank"));
                    }
                    coll.setMisspellingsAndCorrections(
                            (NamedList) expandedCollation.get("misspellingsAndCorrections"));
                    SpellCheckCollation priorColl = collations.get(coll.getCollationQuery());
                    if (priorColl != null) {
                        coll.setHits(coll.getHits() + priorColl.getHits());
                        coll.setInternalRank(Math.max(coll.getInternalRank(), priorColl.getInternalRank()));
                    }
                    collations.put(coll.getCollationQuery(), coll);
                }
            }
        }
    }
}