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

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

Introduction

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

Prototype

SpellCheckCollation

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  ww  w .  j  a  v a 2 s  .c  o m*/
                    }
                    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);
                }
            }
        }
    }
}