function addMatch(match) {
            // Pull off the character index
            var c = match.index;
            var newPoints = 0;

            // A match means that we need to do some scoring bookkeeping.
            // Start with points added for any match
            if (DEBUG_SCORES) {
                scoreDebug.match += MATCH_POINTS;
            }
            newPoints += MATCH_POINTS;

            if (match.upper) {
                if (DEBUG_SCORES) {
                    scoreDebug.upper += UPPER_CASE_MATCH;
                }
                newPoints += UPPER_CASE_MATCH;
            }

            // A bonus is given for characters that match at the beginning
            // of the filename
            if (c === lastSegmentStart) {
                if (DEBUG_SCORES) {
                    scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
                }
                newPoints += BEGINNING_OF_NAME_POINTS;
            }

            // If the new character immediately follows the last matched character,
            // we award the consecutive matches bonus. The check for score > 0
            // handles the initial value of lastMatchIndex which is used for
            // constructing ranges but we don't yet have a true match.
            if (score > 0 && lastMatchIndex + 1 === c) {
                // Continue boosting for each additional match at the beginning
                // of the name
                if (c - numConsecutive === lastSegmentStart) {
                    if (DEBUG_SCORES) {
                        scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
                    }
                    newPoints += BEGINNING_OF_NAME_POINTS;
                }

                numConsecutive++;

                var boost = CONSECUTIVE_MATCHES_POINTS * numConsecutive;

                // Consecutive matches that started on a special are a
                // good indicator of intent, so we award an added bonus there.
                if (currentRangeStartedOnSpecial) {
                    boost = boost * 2;
                }

                if (DEBUG_SCORES) {
                    scoreDebug.consecutive += boost;
                }
                newPoints += boost;
            } else {
                numConsecutive = 1;
            }

            // add points for "special" character matches
            if (match instanceof SpecialMatch) {
                if (DEBUG_SCORES) {
                    scoreDebug.special += SPECIAL_POINTS;
                }
                newPoints += SPECIAL_POINTS;
            }

            score += newPoints;

            // points accumulated in the last segment get an extra bonus
            if (c >= lastSegmentStart) {
                lastSegmentScore += newPoints;
            }

            // if the last range wasn't a match or there's a gap, we need to close off
            // the range to start a new one.
            if ((currentRange && !currentRange.matched) || c > lastMatchIndex + 1) {
                closeRangeGap(c);
            }
            lastMatchIndex = c;

            // set up a new match range or add to the current one
            if (!currentRange) {
                currentRange = {
                    text: str[c],
                    matched: true
                };

                // Check to see if this new matched range is starting on a special
                // character. We penalize those ranges that don't, because most
                // people will search on the logical boundaries of the name
                currentRangeStartedOnSpecial = match instanceof SpecialMatch;
            } else {
                currentRange.text += str[c];
            }
        }
function addMatch(match) {
            // Pull off the character index
            var c = match.index;
            var newPoints = 0;

            // A match means that we need to do some scoring bookkeeping.
            // Start with points added for any match
            if (DEBUG_SCORES) {
                scoreDebug.match += MATCH_POINTS;
            }
            newPoints += MATCH_POINTS;

            if (match.upper) {
                if (DEBUG_SCORES) {
                    scoreDebug.upper += UPPER_CASE_MATCH;
                }
                newPoints += UPPER_CASE_MATCH;
            }

            // A bonus is given for characters that match at the beginning
            // of the filename
            if (c === lastSegmentStart) {
                if (DEBUG_SCORES) {
                    scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
                }
                newPoints += BEGINNING_OF_NAME_POINTS;
            }

            // If the new character immediately follows the last matched character,
            // we award the consecutive matches bonus. The check for score > 0
            // handles the initial value of lastMatchIndex which is used for
            // constructing ranges but we don't yet have a true match.
            if (score > 0 && lastMatchIndex + 1 === c) {
                // Continue boosting for each additional match at the beginning
                // of the name
                if (c - numConsecutive === lastSegmentStart) {
                    if (DEBUG_SCORES) {
                        scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
                    }
                    newPoints += BEGINNING_OF_NAME_POINTS;
                }

                numConsecutive++;

                var boost = CONSECUTIVE_MATCHES_POINTS * numConsecutive;

                // Consecutive matches that started on a special are a
                // good indicator of intent, so we award an added bonus there.
                if (currentRangeStartedOnSpecial) {
                    boost = boost * 2;
                }

                if (DEBUG_SCORES) {
                    scoreDebug.consecutive += boost;
                }
                newPoints += boost;
            } else {
                numConsecutive = 1;
            }

            // add points for "special" character matches
            if (match instanceof SpecialMatch) {
                if (DEBUG_SCORES) {
                    scoreDebug.special += SPECIAL_POINTS;
                }
                newPoints += SPECIAL_POINTS;
            }

            score += newPoints;

            // points accumulated in the last segment get an extra bonus
            if (c >= lastSegmentStart) {
                lastSegmentScore += newPoints;
            }

            // if the last range wasn't a match or there's a gap, we need to close off
            // the range to start a new one.
            if ((currentRange && !currentRange.matched) || c > lastMatchIndex + 1) {
                closeRangeGap(c);
            }
            lastMatchIndex = c;

            // set up a new match range or add to the current one
            if (!currentRange) {
                currentRange = {
                    text: str[c],
                    matched: true
                };

                // Check to see if this new matched range is starting on a special
                // character. We penalize those ranges that don't, because most
                // people will search on the logical boundaries of the name
                currentRangeStartedOnSpecial = match instanceof SpecialMatch;
            } else {
                currentRange.text += str[c];
            }
        }
function addMatch ( match ) { // Pull off the character index var c = match . index ; var newPoints = 0 ; // A match means that we need to do some scoring bookkeeping. // Start with points added for any match if ( DEBUG_SCORES ) { scoreDebug . match += MATCH_POINTS ; } newPoints += MATCH_POINTS ; if ( match . upper ) { if ( DEBUG_SCORES ) { scoreDebug . upper += UPPER_CASE_MATCH ; } newPoints += UPPER_CASE_MATCH ; } // A bonus is given for characters that match at the beginning // of the filename if ( c === lastSegmentStart ) { if ( DEBUG_SCORES ) { scoreDebug . beginning += BEGINNING_OF_NAME_POINTS ; } newPoints += BEGINNING_OF_NAME_POINTS ; } // If the new character immediately follows the last matched character, // we award the consecutive matches bonus. The check for score > 0 // handles the initial value of lastMatchIndex which is used for // constructing ranges but we don't yet have a true match. if ( score > 0 && lastMatchIndex + 1 === c ) { // Continue boosting for each additional match at the beginning // of the name if ( c - numConsecutive === lastSegmentStart ) { if ( DEBUG_SCORES ) { scoreDebug . beginning += BEGINNING_OF_NAME_POINTS ; } newPoints += BEGINNING_OF_NAME_POINTS ; } numConsecutive ++ ; var boost = CONSECUTIVE_MATCHES_POINTS * numConsecutive ; // Consecutive matches that started on a special are a // good indicator of intent, so we award an added bonus there. if ( currentRangeStartedOnSpecial ) { boost = boost * 2 ; } if ( DEBUG_SCORES ) { scoreDebug . consecutive += boost ; } newPoints += boost ; } else { numConsecutive = 1 ; } // add points for "special" character matches if ( match instanceof SpecialMatch ) { if ( DEBUG_SCORES ) { scoreDebug . special += SPECIAL_POINTS ; } newPoints += SPECIAL_POINTS ; } score += newPoints ; // points accumulated in the last segment get an extra bonus if ( c >= lastSegmentStart ) { lastSegmentScore += newPoints ; } // if the last range wasn't a match or there's a gap, we need to close off // the range to start a new one. if ( ( currentRange && ! currentRange . matched ) || c > lastMatchIndex + 1 ) { closeRangeGap ( c ) ; } lastMatchIndex = c ; // set up a new match range or add to the current one if ( ! currentRange ) { currentRange = { text : str [ c ] , matched : true } ; // Check to see if this new matched range is starting on a special // character. We penalize those ranges that don't, because most // people will search on the logical boundaries of the name currentRangeStartedOnSpecial = match instanceof SpecialMatch ; } else { currentRange . text += str [ c ] ; } }
Adds a matched character to the appropriate range
Adds a matched character to the appropriate range
Add a match to the match table.