-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphinxsearch.h
219 lines (185 loc) · 5.68 KB
/
sphinxsearch.h
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// $Id$
//
//
// Copyright (c) 2001-2015, Andrew Aksyonoff
// Copyright (c) 2008-2015, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#ifndef _sphinxsearch_
#define _sphinxsearch_
#include "sphinx.h"
#include "sphinxquery.h"
#include "sphinxint.h"
//////////////////////////////////////////////////////////////////////////
/// term modifiers
enum TermPosFilter_e
{
TERM_POS_NONE = 0,
TERM_POS_FIELD_LIMIT = 1,
TERM_POS_FIELD_START = 2,
TERM_POS_FIELD_END = 3,
TERM_POS_FIELD_STARTEND = 4,
TERM_POS_ZONES = 5,
};
/// decoder state saved at a certain offset
struct SkiplistEntry_t
{
SphDocID_t m_iBaseDocid; ///< delta decoder docid base (aka docid infinum)
int64_t m_iOffset; ///< offset in the doclist file (relative to the doclist start)
int64_t m_iBaseHitlistPos; ///< delta decoder hitlist offset base
};
/// term, searcher view
class ISphQword
{
public:
// setup by query parser
CSphString m_sWord; ///< my copy of word
CSphString m_sDictWord; ///< word after being processed by dict (eg. stemmed)
SphWordID_t m_uWordID; ///< word ID, from dictionary
TermPosFilter_e m_iTermPos;
int m_iAtomPos; ///< word position, from query
float m_fBoost; ///< IDF keyword boost (multiplier)
bool m_bExpanded; ///< added by prefix expansion
bool m_bExcluded; ///< excluded by the query (rval to operator NOT)
// setup by QwordSetup()
int m_iDocs; ///< document count, from wordlist
int m_iHits; ///< hit count, from wordlist
bool m_bHasHitlist; ///< hitlist presence flag
CSphVector<SkiplistEntry_t> m_dSkiplist; ///< skiplist for quicker document list seeks
// iterator state
FieldMask_t m_dQwordFields; ///< current match fields
DWORD m_uMatchHits; ///< current match hits count
SphOffset_t m_iHitlistPos; ///< current position in hitlist, from doclist
protected:
bool m_bAllFieldsKnown; ///< whether the all match fields is known, or only low 32.
public:
ISphQword ()
: m_uWordID ( 0 )
, m_iTermPos ( TERM_POS_NONE )
, m_iAtomPos ( 0 )
, m_fBoost ( 1.0f )
, m_bExpanded ( false )
, m_bExcluded ( false )
, m_iDocs ( 0 )
, m_iHits ( 0 )
, m_bHasHitlist ( true )
, m_uMatchHits ( 0 )
, m_iHitlistPos ( 0 )
, m_bAllFieldsKnown ( false )
{
m_dQwordFields.UnsetAll();
}
virtual ~ISphQword () {}
virtual void HintDocid ( SphDocID_t ) {}
virtual const CSphMatch & GetNextDoc ( DWORD * pInlineDocinfo ) = 0;
virtual void SeekHitlist ( SphOffset_t uOff ) = 0;
virtual Hitpos_t GetNextHit () = 0;
virtual void CollectHitMask ();
virtual void Reset ()
{
m_iDocs = 0;
m_iHits = 0;
m_dQwordFields.UnsetAll();
m_bAllFieldsKnown = false;
m_uMatchHits = 0;
m_iHitlistPos = 0;
}
};
/// term setup, searcher view
class CSphQueryNodeCache;
class ISphZoneCheck;
struct CSphQueryStats;
class ISphQwordSetup : ISphNoncopyable
{
public:
CSphDict * m_pDict;
const CSphIndex * m_pIndex;
ESphDocinfo m_eDocinfo;
const CSphRowitem * m_pMinRow;
SphDocID_t m_uMinDocid;
int m_iInlineRowitems; ///< inline rowitems count
int m_iDynamicRowitems; ///< dynamic rowitems counts (including (!) inline)
int64_t m_iMaxTimer;
CSphString * m_pWarning;
CSphQueryContext * m_pCtx;
CSphQueryNodeCache * m_pNodeCache;
mutable ISphZoneCheck * m_pZoneChecker;
CSphQueryStats * m_pStats;
mutable bool m_bSetQposMask;
ISphQwordSetup ()
: m_pDict ( NULL )
, m_pIndex ( NULL )
, m_eDocinfo ( SPH_DOCINFO_NONE )
, m_pMinRow ( NULL )
, m_uMinDocid ( 0 )
, m_iInlineRowitems ( 0 )
, m_iDynamicRowitems ( 0 )
, m_iMaxTimer ( 0 )
, m_pWarning ( NULL )
, m_pCtx ( NULL )
, m_pNodeCache ( NULL )
, m_pZoneChecker ( NULL )
, m_pStats ( NULL )
, m_bSetQposMask ( false )
{}
virtual ~ISphQwordSetup () {}
virtual ISphQword * QwordSpawn ( const XQKeyword_t & tWord ) const = 0;
virtual bool QwordSetup ( ISphQword * pQword ) const = 0;
};
/// generic ranker interface
class ISphRanker : public ISphExtra
{
public:
virtual ~ISphRanker () {}
virtual CSphMatch * GetMatchesBuffer() = 0;
virtual int GetMatches () = 0;
virtual void Reset ( const ISphQwordSetup & tSetup ) = 0;
};
/// factory
ISphRanker * sphCreateRanker ( const XQQuery_t & tXQ, const CSphQuery * pQuery, CSphQueryResult * pResult, const ISphQwordSetup & tTermSetup, const CSphQueryContext & tCtx );
//////////////////////////////////////////////////////////////////////////
/// hit mark, used for snippets generation
struct SphHitMark_t
{
DWORD m_uPosition;
DWORD m_uSpan;
bool operator == ( const SphHitMark_t & rhs ) const
{
return m_uPosition==rhs.m_uPosition && m_uSpan==rhs.m_uSpan;
}
};
/// hit marker, used for snippets generation
class CSphHitMarker
{
public:
class ExtNode_i * m_pRoot;
public:
CSphHitMarker() : m_pRoot ( NULL ) {}
~CSphHitMarker();
void Mark ( CSphVector<SphHitMark_t> & );
static CSphHitMarker * Create ( const XQNode_t * pRoot, const ISphQwordSetup & tSetup );
};
//////////////////////////////////////////////////////////////////////////
/// intra-batch node cache
class CSphQueryNodeCache
{
friend class NodeCacheContainer_t;
protected:
class NodeCacheContainer_t * m_pPool;
int m_iMaxCachedDocs;
int m_iMaxCachedHits;
public:
CSphQueryNodeCache ( int iCells, int MaxCachedDocs, int MaxCachedHits );
~CSphQueryNodeCache ();
ExtNode_i * CreateProxy ( ExtNode_i * pChild, const XQNode_t * pRawChild, const ISphQwordSetup & tSetup );
};
#endif // _sphinxsearch_
//
// $Id$
//