searcher.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #pragma once
  19. #include "filter.h"
  20. #include "index_config.h"
  21. #include "post_scorer.h"
  22. #include "query.h"
  23. #include "search_status.h"
  24. #include "sorter.h"
  25. #include "tracer.h"
  26. namespace wwsearch {
  27. /* Notice : Query interface for user.
  28. * input : Query, filters, sorters
  29. * output : doc list
  30. * 1. Build Scorer by Query, involve Weight(read/iterator
  31. * inverted table data from db).
  32. * 2. Build Collector to collect all doc id.
  33. * 3. Filter doc id list.
  34. * 4. Sort doc id list.
  35. * 5. Ouput.
  36. */
  37. class Searcher {
  38. private:
  39. IndexConfig *config_;
  40. public:
  41. Searcher(IndexConfig *config) : config_(config) {}
  42. virtual ~Searcher() {}
  43. // If min_match_filter_num = 0,all filter must be match.
  44. SearchStatus DoQuery(
  45. const TableID &table, Query &query, size_t offset, size_t limit,
  46. std::vector<Filter *> *filter, std::vector<SortCondition *> *sorter,
  47. std::list<DocumentID> &docs,
  48. std::vector<std::shared_ptr<ScoreStrategy>> *score_strategy_list =
  49. nullptr,
  50. size_t max_score_doc_num = SIZE_MAX, uint32_t min_match_filter_num = 0,
  51. wwsearch::SearchTracer *tracer = nullptr,
  52. uint32_t *get_match_total_cnt = nullptr);
  53. // GetDocument
  54. // If success,status is ok,and document will fill with content.
  55. SearchStatus GetStoredFields(const TableID &table,
  56. std::vector<Document *> &docs,
  57. std::vector<SearchStatus> &status,
  58. SearchContext *context);
  59. // GetDocValue
  60. SearchStatus GetDocValue(const TableID &table, std::vector<Document *> &docs,
  61. std::vector<SearchStatus> &status,
  62. SearchContext *context);
  63. // Support post filter?
  64. SearchStatus DoPostFilter() { return SearchStatus(); }
  65. // Support sort
  66. // Support aggeration
  67. SearchStatus DoAggregation() { return SearchStatus(); }
  68. // use for get all entity
  69. // only get kDB kPaxosDataMetaColumn column
  70. // key format must like businesstype+partition_set
  71. // WTF OF certain
  72. // if empty if start_partition_set = 0;
  73. SearchStatus ScanBusinessType(uint8_t business_type,
  74. uint64_t &start_partition_set, size_t max_len,
  75. std::vector<uint64_t> &sets,
  76. VirtualDBSnapshot *snapshot = nullptr);
  77. // only used for certain recover!
  78. // Note: return status is ok and start_key is empty,data reach end.
  79. // max_len must > 1
  80. SearchStatus ScanTableData(const TableID &table,
  81. wwsearch::StorageColumnType column,
  82. std::string &start_key, size_t max_len,
  83. std::string &write_batch,
  84. VirtualDBSnapshot *snapshot = nullptr,
  85. size_t max_buffer_size = 18 * 1024 *
  86. 1024 /*18MB*/);
  87. private:
  88. // 0->stored field
  89. // 1->doc value
  90. SearchStatus InnerGetFields(int mode, const TableID &table,
  91. std::vector<Document *> &docs,
  92. std::vector<SearchStatus> &status,
  93. SearchContext *context);
  94. }; // namespace wwsearch
  95. } // namespace wwsearch