1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
6 #define UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "ui/app_list/app_list_export.h"
13 #include "ui/gfx/range/range.h"
17 class TokenizedString
;
19 // TokenizedStringMatch takes two tokenized strings: one as the text and
20 // the other one as the query. It matches the query against the text,
21 // calculates a relevance score between [0, 1] and marks the matched portions
22 // of text. A relevance of zero means the two are completely different to each
23 // other. The higher the relevance score, the better the two strings are
24 // matched. Matched portions of text are stored as index ranges.
25 class APP_LIST_EXPORT TokenizedStringMatch
{
27 typedef std::vector
<gfx::Range
> Hits
;
29 TokenizedStringMatch();
30 ~TokenizedStringMatch();
32 // Calculates the relevance and hits. Returns true if the two strings are
33 // somewhat matched, i.e. relevance score is not zero.
34 bool Calculate(const TokenizedString
& query
, const TokenizedString
& text
);
36 // Convenience wrapper to calculate match from raw string input.
37 bool Calculate(const base::string16
& query
, const base::string16
& text
);
39 double relevance() const { return relevance_
; }
40 const Hits
& hits() const { return hits_
; }
43 // Score in range of [0,1] representing how well the query matches the text.
46 // Char index ranges in |text| of where matches are found.
49 DISALLOW_COPY_AND_ASSIGN(TokenizedStringMatch
);
52 } // namespace app_list
54 #endif // UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_