You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
6.7 KiB

  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. // NewPhraseQuery creates a new Query for finding
  125. // exact term phrases in the index.
  126. // The provided terms must exist in the correct
  127. // order, at the correct index offsets, in the
  128. // specified field. Queried field must have been indexed with
  129. // IncludeTermVectors set to true.
  130. func NewPhraseQuery(terms []string, field string) *query.PhraseQuery {
  131. return query.NewPhraseQuery(terms, field)
  132. }
  133. // NewPrefixQuery creates a new Query which finds
  134. // documents containing terms that start with the
  135. // specified prefix.
  136. func NewPrefixQuery(prefix string) *query.PrefixQuery {
  137. return query.NewPrefixQuery(prefix)
  138. }
  139. // NewRegexpQuery creates a new Query which finds
  140. // documents containing terms that match the
  141. // specified regular expression.
  142. func NewRegexpQuery(regexp string) *query.RegexpQuery {
  143. return query.NewRegexpQuery(regexp)
  144. }
  145. // NewQueryStringQuery creates a new Query used for
  146. // finding documents that satisfy a query string. The
  147. // query string is a small query language for humans.
  148. func NewQueryStringQuery(q string) *query.QueryStringQuery {
  149. return query.NewQueryStringQuery(q)
  150. }
  151. // NewTermQuery creates a new Query for finding an
  152. // exact term match in the index.
  153. func NewTermQuery(term string) *query.TermQuery {
  154. return query.NewTermQuery(term)
  155. }
  156. // NewWildcardQuery creates a new Query which finds
  157. // documents containing terms that match the
  158. // specified wildcard. In the wildcard pattern '*'
  159. // will match any sequence of 0 or more characters,
  160. // and '?' will match any single character.
  161. func NewWildcardQuery(wildcard string) *query.WildcardQuery {
  162. return query.NewWildcardQuery(wildcard)
  163. }