source: trunk/gsdl/src/mgpp/text/MGQuery.h@ 1300

Last change on this file since 1300 was 1300, checked in by kjm18, 24 years ago

added full text browsing functionality

  • 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 * $Id: MGQuery.h 1300 2000-07-24 02:46:11Z kjm18 $
21 *
22 **************************************************************************/
23
24#ifndef MGQUERY_H
25#define MGQUERY_H
26
27#include "IndexData.h"
28#include <limits.h>
29#include "Terms.h"
30
31
32
33// forms base for defining and calculating the boolean
34// part of a query
35class QueryNode {
36public:
37 QueryNode ();
38 virtual ~QueryNode ();
39
40 virtual void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
41 QueryResult &result) const;
42 virtual void Free ();
43 virtual void Print (ostream &s, int indent=0) const;
44};
45
46
47
48void PrintIndent (ostream &s, int indent);
49void PrintIndentText (ostream &s, char *text, int indent);
50void PrintNode (ostream &s, QueryNode *node, int indent=0);
51
52
53
54// basic boolean nodes
55
56class AndQueryNode : public QueryNode {
57public:
58 QueryNode *leftNode;
59 QueryNode *rightNode;
60
61 AndQueryNode ();
62 ~AndQueryNode ();
63
64 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
65 QueryResult &result) const;
66 void Free ();
67 void Print (ostream &s, int indent=0) const;
68};
69
70class OrQueryNode : public QueryNode {
71public:
72 QueryNode *leftNode;
73 QueryNode *rightNode;
74
75 OrQueryNode ();
76 ~OrQueryNode ();
77
78 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
79 QueryResult &result) const;
80 void Free ();
81 void Print (ostream &s, int indent=0) const;
82};
83
84class NotQueryNode : public QueryNode {
85public:
86 QueryNode *queryNode;
87 QueryNode *notNode;
88
89 NotQueryNode ();
90 ~NotQueryNode ();
91
92 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
93 QueryResult &result) const;
94 void Free ();
95 void Print (ostream &s, int indent=0) const;
96};
97
98
99
100class TagNode {
101public:
102 UCArray tagName;
103
104 void Clear ();
105 TagNode () { Clear (); }
106
107 void Calculate (IndexData &indexData, FragRangeArray &fragRange) const;
108 void Free ();
109 void Print (ostream &s, int indent=0) const;
110};
111
112
113#define NO_TERM_RANGE_START (LONG_MIN/2)
114#define NO_TERM_RANGE_END (LONG_MAX/2)
115
116/* NOTE: range stuff - the range values are for the previous term relative
117to the current term. So if searching for the phrase "the cat", 'the' doesn't
118need range limits, but 'cat' has a range of -2 to -1. ie, if have found 'cat'
119then 'the' has to be at position between -2 and -1 relative to 'cat'.
120"the cat" could also be searched for by 'cat' with no range limits, then 'the' with range 0 to 1.
121range values are relative to the gaps between words:
122 x y z X a b c
123 -3 -2 -1 0 1 2 3
124
125 */
126class TermNode {
127public:
128 UCArray term;
129 unsigned long termWeight;
130 unsigned long stemMethod;
131 signed long startRange; // range relative to last term
132 signed long endRange;
133
134 void Clear ();
135 TermNode ();
136
137 // fragLimits can be NULL if not neede
138 void Calculate (IndexData &indexData,
139 bool needFragFreqs,
140 FragRangeArray *fragLimits,
141 FragData &fragData) const;
142 void Free ();
143 void Print (ostream &s, int indent=0) const;
144};
145
146typedef vector<TermNode> TermNodeArray;
147
148
149class ProxMatchQueryNode : public QueryNode {
150public:
151 TagNode *tagNodePtr; // optional field
152 TermNodeArray terms;
153
154 ProxMatchQueryNode ();
155 ~ProxMatchQueryNode ();
156
157 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
158 QueryResult &result) const;
159 void Free ();
160 void Print (ostream &s, int indent=0) const;
161};
162
163class BrowseQueryNode :public QueryNode {
164 public:
165 UCArray term;
166 signed long startPosition;
167 unsigned long numTerms;
168
169 void Clear();
170 BrowseQueryNode () { Clear(); }
171 // ~BrowseQueryNode ();
172
173 void Calculate (IndexData &indexData, BrowseQueryResult &result) const;
174 void Free ();
175 void Print (ostream &s, int indent=0) const;
176
177
178
179
180};
181
182void MGQuery (IndexData &indexData,
183 const QueryInfo &queryInfo,
184 const QueryNode *queryTree,
185 QueryResult &result);
186
187// this function for retrieving results with both section doc nums
188// and Document docnums
189void MGQuery (IndexData &indexData,
190 const QueryInfo &queryInfo,
191 const QueryNode *queryTree,
192 ExtQueryResult &result, UCArray &level);
193
194
195// new function for full text browsing,
196void MGBrowseQuery (IndexData &indexData, UCArray &level,
197 const BrowseQueryNode &node,
198 BrowseQueryResult &result);
199
200#endif
201
202
203
204
205
206
207
208
209
210
Note: See TracBrowser for help on using the repository browser.