libosmscout  1.1.1
TextSearchIndex.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_TEXTSEARCHINDEX_H
2 #define OSMSCOUT_TEXTSEARCHINDEX_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2013 Preet Desai
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
23 #include <unordered_map>
24 
25 #include <osmscout/ObjectRef.h>
26 
28 
29 #include <marisa.h>
30 
31 namespace osmscout
32 {
39  {
40  public:
41  static const char* const TEXT_POI_DAT;
42  static const char* const TEXT_LOC_DAT;
43  static const char* const TEXT_REGION_DAT;
44  static const char* const TEXT_OTHER_DAT;
45 
46  private:
47  struct TrieInfo
48  {
49  marisa::Trie *trie;
50  std::string file;
51  bool isAvail;
52 
53  TrieInfo() :
54  trie(nullptr),
55  isAvail(false)
56  {
57  // no code
58  }
59  };
60 
61  public:
62  using ResultsMap = std::unordered_map<std::string, std::vector<ObjectFileRef> >;
63 
64  TextSearchIndex() = default;
65 
66  ~TextSearchIndex();
67 
68  bool Load(const std::string &path);
69 
70  bool Search(const std::string& query,
71  bool searchPOIs,
72  bool searchLocations,
73  bool searchRegions,
74  bool searchOther,
75  ResultsMap& results) const;
76 
77  private:
78  void splitSearchResult(const std::string& result,
79  std::string& text,
80  ObjectFileRef& ref) const;
81 
82 
83  uint8_t offsetSizeBytes;
84  std::vector<TrieInfo> tries;
85  };
86 }
87 
88 
89 #endif // OSMSCOUT_TEXTSEARCHINDEX_H
static const char *const TEXT_REGION_DAT
Definition: TextSearchIndex.h:43
static const char *const TEXT_POI_DAT
Definition: TextSearchIndex.h:41
std::unordered_map< std::string, std::vector< ObjectFileRef > > ResultsMap
Definition: TextSearchIndex.h:62
Definition: Area.h:38
static const char *const TEXT_OTHER_DAT
Definition: TextSearchIndex.h:44
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: TextSearchIndex.h:38
static const char *const TEXT_LOC_DAT
Definition: TextSearchIndex.h:42