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

Last change on this file since 1836 was 1836, checked in by kjm18, 23 years ago

added support for equiv terms for highlighting. THe QueryResult.TermFreqData
has UCArrayVector equivTerms now.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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 1836 2001-01-14 23:56:57Z 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,
142 UCArrayVector &equivTerms) const;
143 void Free ();
144 void Print (ostream &s, int indent=0) const;
145};
146
147typedef vector<TermNode> TermNodeArray;
148
149
150class ProxMatchQueryNode : public QueryNode {
151public:
152 TagNode *tagNodePtr; // optional field
153 TermNodeArray terms;
154
155 ProxMatchQueryNode ();
156 ~ProxMatchQueryNode ();
157
158 void Calculate (IndexData &indexData, const QueryInfo &queryInfo,
159 QueryResult &result) const;
160 void Free ();
161 void Print (ostream &s, int indent=0) const;
162};
163
164class BrowseQueryNode :public QueryNode {
165 public:
166 UCArray term;
167 signed long startPosition;
168 unsigned long numTerms;
169
170 void Clear();
171 BrowseQueryNode () { Clear(); }
172 // ~BrowseQueryNode ();
173
174 void Calculate (IndexData &indexData, BrowseQueryResult &result) const;
175 void Free ();
176 void Print (ostream &s, int indent=0) const;
177
178
179
180
181};
182
183void MGQuery (IndexData &indexData,
184 const QueryInfo &queryInfo,
185 const QueryNode *queryTree,
186 QueryResult &result);
187
188// this function for retrieving results with both section doc nums
189// and Document docnums
190void MGQuery (IndexData &indexData,
191 const QueryInfo &queryInfo,
192 const QueryNode *queryTree,
193 ExtQueryResult &result, UCArray &level);
194
195
196// new function for full text browsing,
197void MGBrowseQuery (IndexData &indexData, UCArray &level,
198 const BrowseQueryNode &node,
199 BrowseQueryResult &result);
200
201#endif
202
203
204
205
206
207
208
209
210
211
Note: See TracBrowser for help on using the repository browser.