| 691 | } |
| 692 | |
| 693 | bool RemoteBCL::startComponentLibrarySearch(const std::string& searchTerm, const std::string& componentType, const std::string& filterType, |
| 694 | const unsigned page) { |
| 695 | // can't start another request until last one is done |
| 696 | if (m_httpResponse && !m_httpResponse->is_done()) { |
| 697 | return false; |
| 698 | } |
| 699 | |
| 700 | m_lastSearch.clear(); |
| 701 | |
| 702 | auto client = getClient(remoteUrl(), m_timeOutSeconds); |
| 703 | web::uri_builder builder(to_string_t("/api/search/")); |
| 704 | |
| 705 | std::string query = searchTerm.empty() ? "*" : searchTerm; |
| 706 | builder.append_path(web::uri::encode_data_string(utility::conversions::to_string_t(query + ".xml"))); |
| 707 | |
| 708 | builder.append_query(to_string_t("fq[]"), to_string_t("bundle:" + filterType)); |
| 709 | |
| 710 | if (!componentType.empty() && componentType != "*") { |
| 711 | std::string filter = (filterType == "nrel_component") ? "sm_vid_Component_Tags" : "sm_vid_Measure_Tags"; |
| 712 | filter += ":\"" + componentType + "\""; |
| 713 | builder.append_query(to_string_t("fq[]"), to_string_t(filter)); |
| 714 | } |
| 715 | |
| 716 | builder.append_query(to_string_t("api_version"), to_string_t(m_apiVersion)); |
| 717 | builder.append_query(to_string_t("show_rows"), to_string_t(openstudio::string_conversions::number(m_numResultsPerQuery))); |
| 718 | builder.append_query(to_string_t("page"), to_string_t(openstudio::string_conversions::number(page))); |
| 719 | |
| 720 | m_httpResponse = client.request(web::http::methods::GET, builder.to_string()) |
| 721 | .then([](web::http::http_response resp) { return resp.extract_utf8string(); }) |
| 722 | .then([this](const std::string& xml) { |
| 723 | auto remoteQueryResponse = processReply(xml); |
| 724 | |
| 725 | if (remoteQueryResponse) { |
| 726 | m_lastSearch = processSearchResponse(*remoteQueryResponse); |
| 727 | } |
| 728 | }); |
| 729 | |
| 730 | // LOG(Debug, m_remoteUrl << builder.to_string()); |
| 731 | |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | bool RemoteBCL::startComponentLibrarySearch(const std::string& searchTerm, const unsigned componentTypeTID, const std::string& filterType, |
| 736 | const unsigned page) { |