Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / search / tokenized_string_match.h
blob99b84daf180d4f801e7939400a55e5b7cf0a112f
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 CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "ui/gfx/range/range.h"
14 namespace app_list {
16 class TokenizedString;
18 // TokenizedStringMatch takes two tokenized strings: one as the text and
19 // the other one as the query. It matches the query against the text,
20 // calculates a relevance score between [0, 1] and marks the matched portions
21 // of text. A relevance of zero means the two are completely different to each
22 // other. The higher the relevance score, the better the two strings are
23 // matched. Matched portions of text are stored as index ranges.
24 class TokenizedStringMatch {
25 public:
26 typedef std::vector<gfx::Range> Hits;
28 TokenizedStringMatch();
29 ~TokenizedStringMatch();
31 // Calculates the relevance and hits. Returns true if the two strings are
32 // somewhat matched, i.e. relevance score is not zero.
33 bool Calculate(const TokenizedString& query, const TokenizedString& text);
35 // Convenience wrapper to calculate match from raw string input.
36 bool Calculate(const base::string16& query, const base::string16& text);
38 double relevance() const { return relevance_; }
39 const Hits& hits() const { return hits_; }
41 private:
42 double relevance_;
43 Hits hits_;
45 DISALLOW_COPY_AND_ASSIGN(TokenizedStringMatch);
48 } // namespace app_list
50 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_