| 315 | } |
| 316 | |
| 317 | DatasetPtr |
| 318 | Pyramid::search_impl(const DatasetPtr& query, |
| 319 | const SearchFunc& search_func, |
| 320 | InnerSearchParam& search_param) const { |
| 321 | SearchStatistics stats; |
| 322 | QueryContext ctx{.stats = &stats}; |
| 323 | |
| 324 | const auto* query_path = query->GetPaths(); |
| 325 | CHECK_ARGUMENT( // NOLINT |
| 326 | query_path != nullptr || root_->status_ != IndexNode::Status::NO_INDEX, |
| 327 | "query_path is required when level0 is not built"); |
| 328 | CHECK_ARGUMENT(query->GetFloat32Vectors() != nullptr, "query vectors is required"); |
| 329 | |
| 330 | DistHeapPtr search_result = std::make_shared<StandardHeap<true, false>>(allocator_, -1); |
| 331 | |
| 332 | std::shared_lock<std::shared_mutex> lock(resize_mutex_); |
| 333 | auto vl = pool_->TakeOne(); |
| 334 | if (query_path != nullptr) { |
| 335 | std::vector<std::future<void>> futures; |
| 336 | const std::string& current_path = query_path[0]; |
| 337 | auto parsed_path = parse_path(current_path); |
| 338 | Vector<DistHeapPtr> search_result_lists(parsed_path.size(), allocator_); |
| 339 | for (uint32_t i = 0; i < parsed_path.size(); ++i) { |
| 340 | const auto& one_path = parsed_path[i]; |
| 341 | search_result_lists[i] = std::make_shared<StandardHeap<true, false>>(allocator_, -1); |
| 342 | std::shared_ptr<IndexNode> node = root_; |
| 343 | bool valid = true; |
| 344 | for (const auto& item : one_path) { |
| 345 | node = node->GetChild(item, false); |
| 346 | if (node == nullptr) { |
| 347 | valid = false; |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | if (valid) { |
| 352 | if (thread_pool_ != nullptr && search_param.parallel_search_thread_count > 1) { |
| 353 | futures.push_back(thread_pool_->GeneralEnqueue([&, node, i]() -> void { |
| 354 | node->Search(search_func, vl, search_result_lists[i], search_param.ef); |
| 355 | })); |
| 356 | } else { |
| 357 | node->Search(search_func, vl, search_result_lists[i], search_param.ef); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | for (auto& future : futures) { |
| 363 | future.get(); |
| 364 | } |
| 365 | |
| 366 | for (uint32_t i = 0; i < search_result_lists.size(); ++i) { |
| 367 | if (i != 0) { |
| 368 | search_result->Merge(*search_result_lists[i]); |
| 369 | } else { |
| 370 | search_result = search_result_lists[i]; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | } else { |
no test coverage detected