weight.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "header.h"
  20. #include "scorer.h"
  21. #include "search_context.h"
  22. #include "storage_type.h"
  23. namespace wwsearch {
  24. class Query;
  25. class Scorer;
  26. class BulkScorer;
  27. /* Notice : Really get doc id list from inverted table stored in db.
  28. * BoolWeight : calling MultiGet method of db
  29. * PrefixWeight : calling Iterator method of db
  30. * AndWeight&OrWeight : wrapper for BoolWeigth / PrefixWeight
  31. * Attention : inverted table key[term] => value[doc_id_list]
  32. * Terms are passed by user's Query.
  33. */
  34. class Weight {
  35. private:
  36. Query* parent_query_;
  37. std::string weight_name_;
  38. public:
  39. Weight(Query* query, const std::string& weight_name)
  40. : parent_query_(query), weight_name_(weight_name) {}
  41. virtual ~Weight() {}
  42. virtual Scorer* GetScorer(SearchContext* context) = 0;
  43. inline const std::string& Name() const { return weight_name_; }
  44. virtual BulkScorer* GetBulkScorer(SearchContext* context) = 0;
  45. inline Query* GetQuery() { return this->parent_query_; }
  46. private:
  47. };
  48. } // namespace wwsearch