public static void insertTerm(Term[] terms, Term term, InsertTermType type) {
        Term self = terms[term.getOffe()];

        if (self == null) {
            terms[term.getOffe()] = term;
            return;
        }

        int len = term.getName().length();

        // 如果是第一位置
        if (self.getName().length() == len) {
            if (type == InsertTermType.REPLACE) {
                term.setNext(self.next());
                terms[term.getOffe()] = term;
            } else if (type == InsertTermType.SCORE_ADD_SORT) {
                self.score(self.score() + term.score());
                self.selfScore(self.selfScore() + term.selfScore());
            }
            return;
        }

        if (self.getName().length() > len) {
            term.setNext(self);
            terms[term.getOffe()] = term;
            return;
        }

        Term next = self;
        Term before = self;
        while ((next = before.next()) != null) {
            if (next.getName().length() == len) {
                if (type == InsertTermType.REPLACE) {
                    term.setNext(next.next());
                    before.setNext(term);
                } else if (type == InsertTermType.SCORE_ADD_SORT) {
                    next.score(next.score() + term.score());
                    next.selfScore(next.selfScore() + term.selfScore());
                }
                return;
            } else if (next.getName().length() > len) {
                before.setNext(term);
                term.setNext(next);
                return;
            }
            before = next;
        }

        before.setNext(term); // 如果都没有命中
    }
public static void insertTerm ( Term [ ] terms , Term term , InsertTermType type ) { Term self = terms [ term . getOffe ( ) ] ; if ( self == null ) { terms [ term . getOffe ( ) ] = term ; return ; } int len = term . getName ( ) . length ( ) ; if ( self . getName ( ) . length ( ) == len ) { if ( type == InsertTermType . REPLACE ) { term . setNext ( self . next ( ) ) ; terms [ term . getOffe ( ) ] = term ; } else if ( type == InsertTermType . SCORE_ADD_SORT ) { self . score ( self . score ( ) + term . score ( ) ) ; self . selfScore ( self . selfScore ( ) + term . selfScore ( ) ) ; } return ; } if ( self . getName ( ) . length ( ) > len ) { term . setNext ( self ) ; terms [ term . getOffe ( ) ] = term ; return ; } Term next = self ; Term before = self ; while ( ( next = before . next ( ) ) != null ) { if ( next . getName ( ) . length ( ) == len ) { if ( type == InsertTermType . REPLACE ) { term . setNext ( next . next ( ) ) ; before . setNext ( term ) ; } else if ( type == InsertTermType . SCORE_ADD_SORT ) { next . score ( next . score ( ) + term . score ( ) ) ; next . selfScore ( next . selfScore ( ) + term . selfScore ( ) ) ; } return ; } else if ( next . getName ( ) . length ( ) > len ) { before . setNext ( term ) ; term . setNext ( next ) ; return ; } before = next ; } before . setNext ( term ) ; }
将一个term插入到链表中的对应位置中, 如果这个term已经存在参照type type 0.跳过 1. 替换 2.累积分值 保证顺序,由大到小

@param terms
@param term