Skip to content

Commit

Permalink
Fix 336 (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
amallia authored Mar 13, 2020
1 parent 82420ad commit 686e574
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 79 deletions.
5 changes: 0 additions & 5 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ target_link_libraries(perftest_interpolative
pisa
)

add_executable(selective_queries selective_queries.cpp)
target_link_libraries(selective_queries
pisa
)

add_executable(scan_perftest scan_perftest.cpp)
target_link_libraries(scan_perftest
pisa
Expand Down
74 changes: 0 additions & 74 deletions benchmarks/selective_queries.cpp

This file was deleted.

7 changes: 7 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ target_link_libraries(count_postings
pisa
CLI11
)

add_executable(selective_queries selective_queries.cpp)
target_link_libraries(selective_queries
pisa
CLI11
)

63 changes: 63 additions & 0 deletions tools/selective_queries.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>

#include "mappable/mapper.hpp"
#include "mio/mmap.hpp"

#include "CLI/CLI.hpp"
#include "app.hpp"
#include "cursor/cursor.hpp"
#include "index_types.hpp"
#include "query/algorithm.hpp"
#include "query/queries.hpp"
#include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/transformed.hpp>

using namespace pisa;

template <typename IndexType>
void selective_queries(
const std::string& index_filename, std::string const& encoding, std::vector<Query> const& queries)
{
IndexType index;
spdlog::info("Loading index from {}", index_filename);
mio::mmap_source m(index_filename.c_str());
mapper::map(index, m, mapper::map_flags::warmup);

spdlog::info("Performing {} queries", encoding);

using boost::adaptors::transformed;
using boost::algorithm::join;
for (auto const& query: queries) {
size_t and_results = and_query()(make_cursors(index, query), index.num_docs()).size();
size_t or_results = or_query<false>()(make_cursors(index, query), index.num_docs());

double selectiveness = double(and_results) / double(or_results);
if (selectiveness < 0.005) {
std::cout
<< join(query.terms | transformed([](auto d) { return std::to_string(d); }), " ")
<< '\n';
}
}
}

int main(int argc, const char** argv)
{
App<arg::Index, arg::Query<arg::QueryMode::Unranked>> app{
"Filters selective queries for a given index."};
CLI11_PARSE(app, argc, argv);

if (false) {
#define LOOP_BODY(R, DATA, T) \
} \
else if (app.index_encoding() == BOOST_PP_STRINGIZE(T)) \
{ \
selective_queries<BOOST_PP_CAT(T, _index)>( \
app.index_filename(), app.index_encoding(), app.queries());
/**/

BOOST_PP_SEQ_FOR_EACH(LOOP_BODY, _, PISA_INDEX_TYPES);
#undef LOOP_BODY
} else {
spdlog::error("Unknown encoding {}", app.index_encoding());
}
}

0 comments on commit 686e574

Please sign in to comment.