source: trunk/indexers/mgpp/text/MGQuery.h@ 3365

Last change on this file since 3365 was 3365, checked in by kjdon, 22 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/**************************************************************************
2 *
3 * MGQuery.h -- Query related functions
4 * Copyright (C) 1999 Rodger McNab
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 **************************************************************************/
21
22#ifndef MGQUERY_H
23#define MGQUERY_H
24
25#include "IndexData.h"
26#include <limits.h>
27#include "Terms.h"
28
29// forms base for defining and calculating the boolean
30// part of a query
31class QueryNode {
32public:
33 QueryNode ();
34 virtual ~QueryNode ();
35
36 virtual void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
37 QueryResult &result) const;
38 virtual void Free ();
39 virtual void Print (ostream &s, int indent=0) const;
40};
41
42
43
44void PrintIndent (ostream &s, int indent);
45void PrintIndentText (ostream &s, char *text, int indent);
46void PrintNode (ostream &s, QueryNode *node, int indent=0);
47
48
49
50// basic boolean nodes
51
52class AndQueryNode : public QueryNode {
53public:
54 QueryNode *leftNode;
55 QueryNode *rightNode;
56
57 AndQueryNode ();
58 ~AndQueryNode ();
59
60 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
61 QueryResult &result) const;
62 void Free ();
63 void Print (ostream &s, int indent=0) const;
64};
65
66class OrQueryNode : public QueryNode {
67public:
68 QueryNode *leftNode;
69 QueryNode *rightNode;
70
71 OrQueryNode ();
72 ~OrQueryNode ();
73
74 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
75 QueryResult &result) const;
76 void Free ();
77 void Print (ostream &s, int indent=0) const;
78};
79
80class NotQueryNode : public QueryNode {
81public:
82 QueryNode *queryNode;
83 QueryNode *notNode;
84
85 NotQueryNode ();
86 ~NotQueryNode ();
87
88 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
89 QueryResult &result) const;
90 void Free ();
91 void Print (ostream &s, int indent=0) const;
92};
93
94
95
96class TagNode {
97public:
98 UCArray tagName;
99
100 void Clear ();
101 TagNode () { Clear (); }
102
103 void Calculate (IndexData &indexData, FragRangeArray &fragRange) const;
104 void Free ();
105 void Print (ostream &s, int indent=0) const;
106};
107
108
109#define NO_TERM_RANGE_START (LONG_MIN/2)
110#define NO_TERM_RANGE_END (LONG_MAX/2)
111
112/* NOTE: range stuff - the range values are for the previous term relative
113to the current term. So if searching for the phrase "the cat", 'the' doesn't
114need range limits, but 'cat' has a range of -2 to -1. ie, if have found 'cat'
115then 'the' has to be at position between -2 and -1 relative to 'cat'.
116"the cat" could also be searched for by 'cat' with no range limits, then 'the' with range 0 to 1.
117range values are relative to the gaps between words:
118 x y z X a b c
119 -3 -2 -1 0 1 2 3
120
121 */
122class TermNode {
123public:
124 UCArray term;
125 unsigned long termWeight;
126 unsigned long stemMethod;
127 signed long startRange; // range relative to last term
128 signed long endRange;
129
130 void Clear ();
131 TermNode ();
132
133 // fragLimits can be NULL if not neede
134 void Calculate (IndexData &indexData,
135 bool needFragFreqs,
136 FragRangeArray *fragLimits,
137 FragData &fragData,
138 UCArrayVector &equivTerms) const;
139 void Free ();
140 void Print (ostream &s, int indent=0) const;
141};
142
143typedef vector<TermNode> TermNodeArray;
144
145
146class ProxMatchQueryNode : public QueryNode {
147public:
148 TagNode *tagNodePtr; // optional field
149 TermNodeArray terms;
150
151 ProxMatchQueryNode ();
152 ~ProxMatchQueryNode ();
153
154 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
155 QueryResult &result) const;
156 void Free ();
157 void Print (ostream &s, int indent=0) const;
158};
159
160class BrowseQueryNode :public QueryNode {
161 public:
162 UCArray term;
163 signed long startPosition;
164 unsigned long numTerms;
165
166 void Clear();
167 BrowseQueryNode () { Clear(); }
168 // ~BrowseQueryNode ();
169
170 void Calculate (IndexData &indexData, BrowseQueryResult &result) const;
171 void Free ();
172 void Print (ostream &s, int indent=0) const;
173
174
175
176
177};
178
179void MGQuery (IndexData &indexData,
180 const QueryInfo &queryInfo,
181 const QueryNode *queryTree,
182 QueryResult &result);
183
184// this function for retrieving results with both section doc nums
185// and Document docnums
186void MGQuery (IndexData &indexData,
187 const QueryInfo &queryInfo,
188 const QueryNode *queryTree,
189 ExtQueryResult &result, UCArray &level);
190
191
192// new function for full text browsing,
193void MGBrowseQuery (IndexData &indexData, UCArray &level,
194 const BrowseQueryNode &node,
195 BrowseQueryResult &result);
196
197#endif
Note: See TracBrowser for help on using the repository browser.