Switch to unified view

a/src/rcldb/searchdata.h b/src/rcldb/searchdata.h
...
...
68
    {SCLT_PHRASE, [this is a phrase]} or as {SCLT_XXX, ["this is a phrase"]}
68
    {SCLT_PHRASE, [this is a phrase]} or as {SCLT_XXX, ["this is a phrase"]}
69
69
70
*/
70
*/
71
class SearchData {
71
class SearchData {
72
public:
72
public:
73
    SearchData(SClType tp) 
73
    SearchData(SClType tp, const string& stemlang) 
74
    : m_tp(tp), m_haveDates(false), m_maxSize(size_t(-1)),
74
    : m_tp(tp), m_haveDates(false), m_maxSize(size_t(-1)),
75
      m_minSize(size_t(-1)), m_haveWildCards(false) 
75
      m_minSize(size_t(-1)), m_haveWildCards(false), m_stemlang(stemlang)
76
    {
76
    {
77
    if (m_tp != SCLT_OR && m_tp != SCLT_AND) 
77
    if (m_tp != SCLT_OR && m_tp != SCLT_AND) 
78
        m_tp = SCLT_OR;
78
        m_tp = SCLT_OR;
79
    }
79
    }
80
    ~SearchData() {erase();}
80
    ~SearchData() {erase();}
...
...
88
    /** Do we have wildcards anywhere apart from filename searches ? */
88
    /** Do we have wildcards anywhere apart from filename searches ? */
89
    bool haveWildCards() {return m_haveWildCards;}
89
    bool haveWildCards() {return m_haveWildCards;}
90
90
91
    /** Translate to Xapian query. rcldb knows about the void*  */
91
    /** Translate to Xapian query. rcldb knows about the void*  */
92
    bool toNativeQuery(Rcl::Db &db, void *);
92
    bool toNativeQuery(Rcl::Db &db, void *);
93
93
94
94
    /** We become the owner of cl and will delete it */
95
    /** We become the owner of cl and will delete it */
95
    bool addClause(SearchDataClause *cl);
96
    bool addClause(SearchDataClause *cl);
96
97
97
    /** If this is a simple query (one field only, no distance clauses),
98
    /** If this is a simple query (one field only, no distance clauses),
...
...
107
    void addDirSpec(const std::string& t, bool excl = false, float w = 1.0) 
108
    void addDirSpec(const std::string& t, bool excl = false, float w = 1.0) 
108
    {
109
    {
109
    m_dirspecs.push_back(DirSpec(t, excl, w));
110
    m_dirspecs.push_back(DirSpec(t, excl, w));
110
    }
111
    }
111
112
113
    const std::string& getStemLang() {return m_stemlang;}
114
112
    void setMinSize(size_t size) {m_minSize = size;}
115
    void setMinSize(size_t size) {m_minSize = size;}
113
    void setMaxSize(size_t size) {m_maxSize = size;}
116
    void setMaxSize(size_t size) {m_maxSize = size;}
114
117
115
    /** Set date span for filtering results */
118
    /** Set date span for filtering results */
116
    void setDateSpan(DateInterval *dip) {m_dates = *dip; m_haveDates = true;}
119
    void setDateSpan(DateInterval *dip) {m_dates = *dip; m_haveDates = true;}
117
120
118
    /** Add file type for filtering results */
121
    /** Add file type for filtering results */
119
    void addFiletype(const std::string& ft) {m_filetypes.push_back(ft);}
122
    void addFiletype(const std::string& ft) {m_filetypes.push_back(ft);}
120
    /** Add file type to not wanted list */
123
    /** Add file type to not wanted list */
121
    void remFiletype(const std::string& ft) {m_nfiletypes.push_back(ft);}
124
    void remFiletype(const std::string& ft) {m_nfiletypes.push_back(ft);}
122
123
    void setStemlang(const std::string& lang = "english") {m_stemlang = lang;}
124
125
125
    /** Retrieve error description */
126
    /** Retrieve error description */
126
    std::string getReason() {return m_reason;}
127
    std::string getReason() {return m_reason;}
127
128
128
    /** Return term expansion data. Mostly used by caller for highlighting
129
    /** Return term expansion data. Mostly used by caller for highlighting
...
...
168
    // from rcldb after the Xapian::setQuery() call
169
    // from rcldb after the Xapian::setQuery() call
169
    std::string m_description; 
170
    std::string m_description; 
170
    std::string m_reason;
171
    std::string m_reason;
171
    bool   m_haveWildCards;
172
    bool   m_haveWildCards;
172
    std::string m_stemlang;
173
    std::string m_stemlang;
174
173
    bool expandFileTypes(RclConfig *cfg, std::vector<std::string>& exptps);
175
    bool expandFileTypes(RclConfig *cfg, std::vector<std::string>& exptps);
176
    bool clausesToQuery(Rcl::Db &db, SClType tp,     
177
          std::vector<SearchDataClause*>& query,
178
          string& reason, void *d);
179
174
    /* Copyconst and assignment private and forbidden */
180
    /* Copyconst and assignment private and forbidden */
175
    SearchData(const SearchData &) {}
181
    SearchData(const SearchData &) {}
176
    SearchData& operator=(const SearchData&) {return *this;};
182
    SearchData& operator=(const SearchData&) {return *this;};
177
};
183
};
178
184
...
...
184
    SearchDataClause(SClType tp) 
190
    SearchDataClause(SClType tp) 
185
    : m_tp(tp), m_parentSearch(0), m_haveWildCards(0), 
191
    : m_tp(tp), m_parentSearch(0), m_haveWildCards(0), 
186
      m_modifiers(SDCM_NONE), m_weight(1.0)
192
      m_modifiers(SDCM_NONE), m_weight(1.0)
187
    {}
193
    {}
188
    virtual ~SearchDataClause() {}
194
    virtual ~SearchDataClause() {}
189
    virtual bool toNativeQuery(Rcl::Db &db, void *, const std::string&) = 0;
195
    virtual bool toNativeQuery(Rcl::Db &db, void *) = 0;
190
    bool isFileName() const {return m_tp == SCLT_FILENAME ? true: false;}
196
    bool isFileName() const {return m_tp == SCLT_FILENAME ? true: false;}
191
    virtual std::string getReason() const {return m_reason;}
197
    virtual std::string getReason() const {return m_reason;}
192
    virtual void getTerms(HighlightData & hldata) const = 0;
198
    virtual void getTerms(HighlightData & hldata) const = 0;
193
199
194
    SClType getTp() 
200
    SClType getTp() 
...
...
196
    return m_tp;
202
    return m_tp;
197
    }
203
    }
198
    void setParent(SearchData *p) 
204
    void setParent(SearchData *p) 
199
    {
205
    {
200
    m_parentSearch = p;
206
    m_parentSearch = p;
207
    }
208
    string getStemLang() 
209
    {
210
  return (m_modifiers & SDCM_NOSTEMMING) || m_parentSearch == 0 ? 
211
      cstr_null : m_parentSearch->getStemLang();
201
    }
212
    }
202
    virtual void setModifiers(Modifier mod) 
213
    virtual void setModifiers(Modifier mod) 
203
    {
214
    {
204
    m_modifiers = mod;
215
    m_modifiers = mod;
205
    }
216
    }
...
...
253
    virtual ~SearchDataClauseSimple() 
264
    virtual ~SearchDataClauseSimple() 
254
    {
265
    {
255
    }
266
    }
256
267
257
    /** Translate to Xapian query */
268
    /** Translate to Xapian query */
258
    virtual bool toNativeQuery(Rcl::Db &, void *, const std::string& stemlang);
269
    virtual bool toNativeQuery(Rcl::Db &, void *);
259
270
260
    virtual void getTerms(HighlightData& hldata) const
271
    virtual void getTerms(HighlightData& hldata) const
261
    {
272
    {
262
    hldata.append(m_hldata);
273
    hldata.append(m_hldata);
263
    }
274
    }
...
...
294
305
295
    virtual ~SearchDataClauseFilename() 
306
    virtual ~SearchDataClauseFilename() 
296
    {
307
    {
297
    }
308
    }
298
309
299
    virtual bool toNativeQuery(Rcl::Db &, void *, const std::string& stemlang);
310
    virtual bool toNativeQuery(Rcl::Db &, void *);
300
};
311
};
301
312
302
/** 
313
/** 
303
 * A clause coming from a NEAR or PHRASE entry field. There is only one 
314
 * A clause coming from a NEAR or PHRASE entry field. There is only one 
304
 * std::string group, and a specified distance, which applies to it.
315
 * std::string group, and a specified distance, which applies to it.
...
...
313
324
314
    virtual ~SearchDataClauseDist() 
325
    virtual ~SearchDataClauseDist() 
315
    {
326
    {
316
    }
327
    }
317
328
318
    virtual bool toNativeQuery(Rcl::Db &, void *, const std::string& stemlang);
329
    virtual bool toNativeQuery(Rcl::Db &, void *);
319
private:
330
private:
320
    int m_slack;
331
    int m_slack;
321
};
332
};
322
333
323
/** Subquery */
334
/** Subquery */
324
class SearchDataClauseSub : public SearchDataClause {
335
class SearchDataClauseSub : public SearchDataClause {
325
public:
336
public:
326
    // We take charge of the SearchData * and will delete it.
327
    SearchDataClauseSub(SClType tp, RefCntr<SearchData> sub) 
337
    SearchDataClauseSub(SClType tp, RefCntr<SearchData> sub) 
328
    : SearchDataClause(tp), m_sub(sub) 
338
    : SearchDataClause(tp), m_sub(sub) 
329
    {
339
    {
330
    }
340
    }
331
332
    virtual ~SearchDataClauseSub() 
333
    {
334
    }
335
336
    virtual bool toNativeQuery(Rcl::Db &db, void *p, const std::string&)
341
    virtual bool toNativeQuery(Rcl::Db &db, void *p)
337
    {
342
    {
338
    return m_sub->toNativeQuery(db, p);
343
    return m_sub->toNativeQuery(db, p);
339
    }
344
    }
340
345
341
    virtual void getTerms(HighlightData& hldata) const
346
    virtual void getTerms(HighlightData& hldata) const