xapian-core  2.0.0
queryparser_internal.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005-2025 Olly Betts
5  * Copyright (C) 2010 Adam Sjøgren
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H
23 #define XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H
24 
25 #include "xapian/intrusive_ptr.h"
26 #include <xapian/database.h>
27 #include <xapian/query.h>
28 #include <xapian/queryparser.h>
29 #include <xapian/stem.h>
30 
31 #include <list>
32 #include <map>
33 
34 class State;
35 
37 
39 struct FieldInfo {
42 
43  std::string grouping;
44 
46  std::vector<std::string> prefixes;
47 
50 
51  explicit
53  : type(type_)
54  {
55  }
56 
57  FieldInfo(filter_type type_, std::string_view grouping_)
58  : type(type_), grouping(grouping_)
59  {
60  }
61 
63  std::string_view grouping_ = {})
64  : type(type_), grouping(grouping_), proc(proc_)
65  {
66  }
67 
68  FieldInfo& append(std::string_view prefix)
69  {
70  prefixes.emplace_back(prefix);
71  return *this;
72  }
73 };
74 
75 namespace Xapian {
76 
77 class Utf8Iterator;
78 
79 struct RangeProc {
81  std::string grouping;
83 
84  RangeProc(RangeProcessor * range_proc, const std::string* grouping_)
85  : proc(range_proc),
86  grouping(grouping_ ? *grouping_ : std::string()),
87  default_grouping(grouping_ == NULL) { }
88 };
89 
91  friend class QueryParser;
92  friend class ::State;
98  const char* errmsg = nullptr;
100  std::list<std::string> stoplist;
101  std::multimap<std::string, std::string, std::less<>> unstem;
102 
103  // Map "from" -> "A" ; "subject" -> "C" ; "newsgroups" -> "G" ;
104  // "foobar" -> "XFOO". FIXME: it does more than this now!
105  std::map<std::string, FieldInfo, std::less<>> field_map;
106 
107  std::list<RangeProc> rangeprocs;
108 
109  std::string corrected_query;
110 
112 
114 
116 
118 
120 
122 
124 
126 
127  void add_prefix(std::string_view field, std::string_view prefix);
128 
129  void add_prefix(std::string_view field, Xapian::FieldProcessor* proc);
130 
131  void add_boolean_prefix(std::string_view field,
132  std::string_view prefix,
133  const std::string* grouping);
134 
135  void add_boolean_prefix(std::string_view field,
137  const std::string* grouping);
138 
139  std::string parse_term(Utf8Iterator& it, const Utf8Iterator& end,
140  bool try_word_break, unsigned flags,
141  bool& needs_word_break, bool& was_acronym,
142  size_t& first_wildcard,
143  size_t& char_count,
144  unsigned& edit_distance);
145 
146  public:
147  Internal() { }
148 
149  Query parse_query(std::string_view query_string,
150  unsigned int flags,
151  std::string_view default_prefix);
152 };
153 
154 }
155 
156 #endif // XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H
Parser State shared between the lexer and the parser.
An indexed database of documents.
Definition: database.h:75
Base class for field processors.
Definition: queryparser.h:468
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:50
Xapian::Internal::opt_intrusive_ptr< const Stopper > stopper
std::list< std::string > stoplist
std::multimap< std::string, std::string, std::less<> > unstem
void add_boolean_prefix(std::string_view field, std::string_view prefix, const std::string *grouping)
Query parse_query(std::string_view query_string, unsigned int flags, std::string_view default_prefix)
std::string parse_term(Utf8Iterator &it, const Utf8Iterator &end, bool try_word_break, unsigned flags, bool &needs_word_break, bool &was_acronym, size_t &first_wildcard, size_t &char_count, unsigned &edit_distance)
std::list< RangeProc > rangeprocs
std::map< std::string, FieldInfo, std::less<> > field_map
void add_prefix(std::string_view field, std::string_view prefix)
Build a Xapian::Query object from a user query string.
Definition: queryparser.h:516
stop_strategy
Stopper strategies, for use with set_stopper_strategy().
Definition: queryparser.h:796
stem_strategy
Stemming strategies, for use with set_stemming_strategy().
Definition: queryparser.h:788
Class representing a query.
Definition: query.h:45
op
Query operators.
Definition: query.h:78
@ OP_OR
Match documents which at least one subquery matches.
Definition: query.h:92
@ WILDCARD_LIMIT_ERROR
Throw an error if OP_WILDCARD exceeds its expansion limit.
Definition: query.h:305
@ WILDCARD_LIMIT_MOST_FREQUENT
Limit OP_WILDCARD expansion to the most frequent terms.
Definition: query.h:321
Base class for range processors.
Definition: queryparser.h:140
Class representing a stemming algorithm.
Definition: stem.h:74
An iterator which returns Unicode character values from a UTF-8 encoded string.
Definition: unicode.h:39
An indexed database of documents.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
Xapian::Query API class.
parsing a user query string to build a Xapian::Query object
@ NON_BOOLEAN
@ BOOLEAN_EXCLUSIVE
stemming algorithms
Information about how to handle a field prefix in the query string.
FieldInfo(filter_type type_, std::string_view grouping_)
FieldInfo(filter_type type_)
std::string grouping
std::vector< std::string > prefixes
Field prefix strings.
FieldInfo(filter_type type_, Xapian::FieldProcessor *proc_, std::string_view grouping_={})
FieldInfo & append(std::string_view prefix)
filter_type type
The type of this field.
Xapian::Internal::opt_intrusive_ptr< Xapian::FieldProcessor > proc
Field processor. Currently only one is supported.
Xapian::Internal::opt_intrusive_ptr< RangeProcessor > proc
RangeProc(RangeProcessor *range_proc, const std::string *grouping_)