pub fn score_acronyms(query: &Query, subject: &Text) -> Option<AcronymResult> {
    // single char strings are not an acronym
    if query.len() <= 1 || subject.len() <= 1 {
        return None;
    }

    let mut matches = vec![];
    let mut count = 0;
    let mut sep_count = 0;
    let mut sum_position = 0;
    let mut same_case = 0;

    let query_iter = query.lowercase_iter().enumerate();
    let mut subject_iter = subject.lowercase_iter().enumerate();

    let mut progress = 0;
    'query_loop: for (qindex, query_grapheme) in query_iter {
        if progress == subject.len() {
            // The subject text has been consumed, we can stop
            break 'query_loop;
        }

        'subject_loop: for (index, subject_grapheme) in &mut subject_iter {
            progress += 1;

            if query_grapheme == subject_grapheme {
                if is_word_separator(query_grapheme) {
                    // separators don't score points, but we keep track of them
                    sep_count += 1;

                    break 'subject_loop;
                } else if is_start_of_word(subject, index) {
                    // only count graphemes that are start of a word
                    sum_position += index;
                    count += 1;

                    // we don't need to trace back the matches
                    // we only return the acronym score if the number of
                    // acronym's matches equals the query length, with means
                    // the number of matches will equal that length as well
                    matches.push(index);

                    if query.grapheme_at(qindex) == subject.grapheme_at(index) {
                        same_case += 1;
                    }

                    break 'subject_loop;
                }
            }
        }
    }

    if count < 2 {
        return None;
    }

    let full_world = if count == query.len() {
        // the query doesn't have any separator so it might be
        // the unique acronym inside subject
        is_a_unique_acronym(subject, count)
    } else {
        false
    };
    let score = score_pattern(count, query.len(), same_case, true, full_world);

    if score <= 0.0 {
        return None;
    }

    let position = sum_position as f32 / count as f32;

    Some(AcronymResult::new(
        score,
        position,
        count + sep_count,
        matches,
    ))
}
/// Calculate the score of the acronyms represented by the query, if any
Calculate the score of the acronyms represented by the query, if any
Calculate the score of the acronyms represented by the query if any
pub fn score_acronyms(query: &Query, subject: &Text) -> Option<AcronymResult> {
    // single char strings are not an acronym
    if query.len() <= 1 || subject.len() <= 1 {
        return None;
    }
    let mut matches = vec![];
    let mut count = 0;
    let mut sep_count = 0;
    let mut sum_position = 0;
    let mut same_case = 0;
    let query_iter = query.lowercase_iter().enumerate();
    let mut subject_iter = subject.lowercase_iter().enumerate();
    let mut progress = 0;
    'query_loop: for (qindex, query_grapheme) in query_iter {
        if progress == subject.len() {
            // The subject text has been consumed, we can stop
            break 'query_loop;
        }
        'subject_loop: for (index, subject_grapheme) in &mut subject_iter {
            progress += 1;
            if query_grapheme == subject_grapheme {
                if is_word_separator(query_grapheme) {
                    // separators don't score points, but we keep track of them
                    sep_count += 1;
                    break 'subject_loop;
                } else if is_start_of_word(subject, index) {
                    // only count graphemes that are start of a word
                    sum_position += index;
                    count += 1;
                    // we don't need to trace back the matches
                    // we only return the acronym score if the number of
                    // acronym's matches equals the query length, with means
                    // the number of matches will equal that length as well
                    matches.push(index);
                    if query.grapheme_at(qindex) == subject.grapheme_at(index) {
                        same_case += 1;
                    }
                    break 'subject_loop;
                }
            }
        }
    }
    if count < 2 {
        return None;
    }
    let full_world = if count == query.len() {
        // the query doesn't have any separator so it might be
        // the unique acronym inside subject
        is_a_unique_acronym(subject, count)
    } else {
        false
    };
    let score = score_pattern(count, query.len(), same_case, true, full_world);
    if score <= 0.0 {
        return None;
    }
    let position = sum_position as f32 / count as f32;
    Some(AcronymResult::new(
        score,
        position,
        count + sep_count,
        matches,
    ))
}
pub fn score_acronyms ( query : & Query , subject : & Text ) -> Option < AcronymResult > { // single char strings are not an acronym if query . len ( ) <= 1 || subject . len ( ) <= 1 { return None ; } let mut matches = vec ! [ ] ; let mut count = 0 ; let mut sep_count = 0 ; let mut sum_position = 0 ; let mut same_case = 0 ; let query_iter = query . lowercase_iter ( ) . enumerate ( ) ; let mut subject_iter = subject . lowercase_iter ( ) . enumerate ( ) ; let mut progress = 0 ; ' query_loop : for ( qindex , query_grapheme ) in query_iter { if progress == subject . len ( ) { // The subject text has been consumed, we can stop break ' query_loop ; } ' subject_loop : for ( index , subject_grapheme ) in & mut subject_iter { progress += 1 ; if query_grapheme == subject_grapheme { if is_word_separator ( query_grapheme ) { // separators don't score points, but we keep track of them sep_count += 1 ; break ' subject_loop ; } else if is_start_of_word ( subject , index ) { // only count graphemes that are start of a word sum_position += index ; count += 1 ; // we don't need to trace back the matches // we only return the acronym score if the number of // acronym's matches equals the query length, with means // the number of matches will equal that length as well matches . push ( index ) ; if query . grapheme_at ( qindex ) == subject . grapheme_at ( index ) { same_case += 1 ; } break ' subject_loop ; } } } } if count < 2 { return None ; } let full_world = if count == query . len ( ) { // the query doesn't have any separator so it might be // the unique acronym inside subject is_a_unique_acronym ( subject , count ) } else { false } ; let score = score_pattern ( count , query . len ( ) , same_case , true , full_world ) ; if score <= 0.0 { return None ; } let position = sum_position as f32 / count as f32 ; Some ( AcronymResult :: new ( score , position , count + sep_count , matches , ) ) }
Calculate the score of the acronyms represented by the query, if any
Calculate the score of the acronyms represented by the query if any
query
&Query
subject
&Text