1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#ifndef LPC_INDEX_H1105549284_INCLUDE_GUARD_
#define LPC_INDEX_H1105549284_INCLUDE_GUARD_
/* This file is part of indexlib.
* Copyright (C) 2005 Luís Pedro Coelho <[email protected]>
*
* Indexlib is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation and available as file
* GPL_V2 which is distributed along with indexlib.
*
* Indexlib is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of this program with any edition of
* the TQt library by Trolltech AS, Norway (or with modified versions
* of TQt that use the same license as TQt), and distribute linked
* combinations including the two. You must obey the GNU General
* Public License in all respects for all of the code used other than
* TQt. If you modify this file, you may extend this exception to
* your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from
* your version.
*/
#include <vector>
#include <string>
#include <memory>
namespace indexlib {
/**
* Represents a result set
*
* The reason we do not return directly the answer set is twofold ( though connected )
*
* - We may decide to partially compute the set in the result list() method
* - The possibility of implementing result_type::search to more efficiently handle repeated searches
*/
struct result {
public:
virtual ~result() { }
/**
* The answer set
*/
virtual std::vector<unsigned> list() const = 0;
/**
* A new search.
*
* The reason for this function is that if the user is typing and we do repeated searches for
* "s", "st", "str", "stri" ... "string" we may (depending on the particular implementation)
* reuse the previous results for a speedup.
*
* @return null if the type does not support this or the particular search string makes it impossible to
* fulfill the search request.
*/
virtual std::unique_ptr<result> search( const char* ) = 0;
};
struct index {
public:
virtual ~index() { }
/**
* Adds the document \param str under the name \param docname
*/
virtual void add( const char* str, const char* docname ) = 0;
/**
* \see add( const char*, const char* );
*/
virtual void add( std::string s, std::string d ) { add( s.c_str(), d.c_str() ); }
/**
* Removes the doc known as docname.
*
* In most implementations of index, this will probably be implemented by marking
* the document as deleted in some way and maintenance() will need to be called later.
*/
virtual void remove_doc( const char* doc ) = 0;
void remove_doc( std::string doc ) { remove_doc( doc.c_str() ); }
/**
* Perform any maintenance tasks necessary.
*
* Should be called every so often, but it can take some time to perform these operations,
* so call them when the app is idle.
*/
virtual void maintenance() { }
/**
* Returns all documents matching \param pattern.
*/
virtual std::unique_ptr<result> search( const char* pattern ) const = 0;
/**
* Returns the number of docs indexed.
*/
virtual unsigned ndocs() const = 0;
/**
* Since docs are returned by index, there names need to be looked up.
*/
virtual std::string lookup_docname( unsigned ) const = 0;
private:
};
}
#endif /* LPC_INDEX_H1105549284_INCLUDE_GUARD_ */
|