本站源代码
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

219 rindas
8.1KB

  1. // Copyright (c) 2014 Couchbase, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package bleve
  15. import (
  16. "time"
  17. "github.com/blevesearch/bleve/search/query"
  18. )
  19. // NewBoolFieldQuery creates a new Query for boolean fields
  20. func NewBoolFieldQuery(val bool) *query.BoolFieldQuery {
  21. return query.NewBoolFieldQuery(val)
  22. }
  23. // NewBooleanQuery creates a compound Query composed
  24. // of several other Query objects.
  25. // These other query objects are added using the
  26. // AddMust() AddShould() and AddMustNot() methods.
  27. // Result documents must satisfy ALL of the
  28. // must Queries.
  29. // Result documents must satisfy NONE of the must not
  30. // Queries.
  31. // Result documents that ALSO satisfy any of the should
  32. // Queries will score higher.
  33. func NewBooleanQuery() *query.BooleanQuery {
  34. return query.NewBooleanQuery(nil, nil, nil)
  35. }
  36. // NewConjunctionQuery creates a new compound Query.
  37. // Result documents must satisfy all of the queries.
  38. func NewConjunctionQuery(conjuncts ...query.Query) *query.ConjunctionQuery {
  39. return query.NewConjunctionQuery(conjuncts)
  40. }
  41. // NewDateRangeQuery creates a new Query for ranges
  42. // of date values.
  43. // Date strings are parsed using the DateTimeParser configured in the
  44. // top-level config.QueryDateTimeParser
  45. // Either, but not both endpoints can be nil.
  46. func NewDateRangeQuery(start, end time.Time) *query.DateRangeQuery {
  47. return query.NewDateRangeQuery(start, end)
  48. }
  49. // NewDateRangeInclusiveQuery creates a new Query for ranges
  50. // of date values.
  51. // Date strings are parsed using the DateTimeParser configured in the
  52. // top-level config.QueryDateTimeParser
  53. // Either, but not both endpoints can be nil.
  54. // startInclusive and endInclusive control inclusion of the endpoints.
  55. func NewDateRangeInclusiveQuery(start, end time.Time, startInclusive, endInclusive *bool) *query.DateRangeQuery {
  56. return query.NewDateRangeInclusiveQuery(start, end, startInclusive, endInclusive)
  57. }
  58. // NewDisjunctionQuery creates a new compound Query.
  59. // Result documents satisfy at least one Query.
  60. func NewDisjunctionQuery(disjuncts ...query.Query) *query.DisjunctionQuery {
  61. return query.NewDisjunctionQuery(disjuncts)
  62. }
  63. // NewDocIDQuery creates a new Query object returning indexed documents among
  64. // the specified set. Combine it with ConjunctionQuery to restrict the scope of
  65. // other queries output.
  66. func NewDocIDQuery(ids []string) *query.DocIDQuery {
  67. return query.NewDocIDQuery(ids)
  68. }
  69. // NewFuzzyQuery creates a new Query which finds
  70. // documents containing terms within a specific
  71. // fuzziness of the specified term.
  72. // The default fuzziness is 1.
  73. //
  74. // The current implementation uses Levenshtein edit
  75. // distance as the fuzziness metric.
  76. func NewFuzzyQuery(term string) *query.FuzzyQuery {
  77. return query.NewFuzzyQuery(term)
  78. }
  79. // NewMatchAllQuery creates a Query which will
  80. // match all documents in the index.
  81. func NewMatchAllQuery() *query.MatchAllQuery {
  82. return query.NewMatchAllQuery()
  83. }
  84. // NewMatchNoneQuery creates a Query which will not
  85. // match any documents in the index.
  86. func NewMatchNoneQuery() *query.MatchNoneQuery {
  87. return query.NewMatchNoneQuery()
  88. }
  89. // NewMatchPhraseQuery creates a new Query object
  90. // for matching phrases in the index.
  91. // An Analyzer is chosen based on the field.
  92. // Input text is analyzed using this analyzer.
  93. // Token terms resulting from this analysis are
  94. // used to build a search phrase. Result documents
  95. // must match this phrase. Queried field must have been indexed with
  96. // IncludeTermVectors set to true.
  97. func NewMatchPhraseQuery(matchPhrase string) *query.MatchPhraseQuery {
  98. return query.NewMatchPhraseQuery(matchPhrase)
  99. }
  100. // NewMatchQuery creates a Query for matching text.
  101. // An Analyzer is chosen based on the field.
  102. // Input text is analyzed using this analyzer.
  103. // Token terms resulting from this analysis are
  104. // used to perform term searches. Result documents
  105. // must satisfy at least one of these term searches.
  106. func NewMatchQuery(match string) *query.MatchQuery {
  107. return query.NewMatchQuery(match)
  108. }
  109. // NewNumericRangeQuery creates a new Query for ranges
  110. // of numeric values.
  111. // Either, but not both endpoints can be nil.
  112. // The minimum value is inclusive.
  113. // The maximum value is exclusive.
  114. func NewNumericRangeQuery(min, max *float64) *query.NumericRangeQuery {
  115. return query.NewNumericRangeQuery(min, max)
  116. }
  117. // NewNumericRangeInclusiveQuery creates a new Query for ranges
  118. // of numeric values.
  119. // Either, but not both endpoints can be nil.
  120. // Control endpoint inclusion with inclusiveMin, inclusiveMax.
  121. func NewNumericRangeInclusiveQuery(min, max *float64, minInclusive, maxInclusive *bool) *query.NumericRangeQuery {
  122. return query.NewNumericRangeInclusiveQuery(min, max, minInclusive, maxInclusive)
  123. }
  124. // NewTermRangeQuery creates a new Query for ranges
  125. // of text terms.
  126. // Either, but not both endpoints can be "".
  127. // The minimum value is inclusive.
  128. // The maximum value is exclusive.
  129. func NewTermRangeQuery(min, max string) *query.TermRangeQuery {
  130. return query.NewTermRangeQuery(min, max)
  131. }
  132. // NewTermRangeInclusiveQuery creates a new Query for ranges
  133. // of text terms.
  134. // Either, but not both endpoints can be "".
  135. // Control endpoint inclusion with inclusiveMin, inclusiveMax.
  136. func NewTermRangeInclusiveQuery(min, max string, minInclusive, maxInclusive *bool) *query.TermRangeQuery {
  137. return query.NewTermRangeInclusiveQuery(min, max, minInclusive, maxInclusive)
  138. }
  139. // NewPhraseQuery creates a new Query for finding
  140. // exact term phrases in the index.
  141. // The provided terms must exist in the correct
  142. // order, at the correct index offsets, in the
  143. // specified field. Queried field must have been indexed with
  144. // IncludeTermVectors set to true.
  145. func NewPhraseQuery(terms []string, field string) *query.PhraseQuery {
  146. return query.NewPhraseQuery(terms, field)
  147. }
  148. // NewPrefixQuery creates a new Query which finds
  149. // documents containing terms that start with the
  150. // specified prefix.
  151. func NewPrefixQuery(prefix string) *query.PrefixQuery {
  152. return query.NewPrefixQuery(prefix)
  153. }
  154. // NewRegexpQuery creates a new Query which finds
  155. // documents containing terms that match the
  156. // specified regular expression.
  157. func NewRegexpQuery(regexp string) *query.RegexpQuery {
  158. return query.NewRegexpQuery(regexp)
  159. }
  160. // NewQueryStringQuery creates a new Query used for
  161. // finding documents that satisfy a query string. The
  162. // query string is a small query language for humans.
  163. func NewQueryStringQuery(q string) *query.QueryStringQuery {
  164. return query.NewQueryStringQuery(q)
  165. }
  166. // NewTermQuery creates a new Query for finding an
  167. // exact term match in the index.
  168. func NewTermQuery(term string) *query.TermQuery {
  169. return query.NewTermQuery(term)
  170. }
  171. // NewWildcardQuery creates a new Query which finds
  172. // documents containing terms that match the
  173. // specified wildcard. In the wildcard pattern '*'
  174. // will match any sequence of 0 or more characters,
  175. // and '?' will match any single character.
  176. func NewWildcardQuery(wildcard string) *query.WildcardQuery {
  177. return query.NewWildcardQuery(wildcard)
  178. }
  179. // NewGeoBoundingBoxQuery creates a new Query for performing geo bounding
  180. // box searches. The arguments describe the position of the box and documents
  181. // which have an indexed geo point inside the box will be returned.
  182. func NewGeoBoundingBoxQuery(topLeftLon, topLeftLat, bottomRightLon, bottomRightLat float64) *query.GeoBoundingBoxQuery {
  183. return query.NewGeoBoundingBoxQuery(topLeftLon, topLeftLat, bottomRightLon, bottomRightLat)
  184. }
  185. // NewGeoDistanceQuery creates a new Query for performing geo distance
  186. // searches. The arguments describe a position and a distance. Documents
  187. // which have an indexed geo point which is less than or equal to the provided
  188. // distance from the given position will be returned.
  189. func NewGeoDistanceQuery(lon, lat float64, distance string) *query.GeoDistanceQuery {
  190. return query.NewGeoDistanceQuery(lon, lat, distance)
  191. }
上海开阖软件有限公司 沪ICP备12045867号-1