mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Enable searching by glob in locate command.
This commit is contained in:
parent
253af1a3ad
commit
fde1355653
3 changed files with 11 additions and 19 deletions
|
@ -9,12 +9,14 @@ add_executable(${PROJECT_NAME}
|
|||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/lib/glob2regex/include
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${bare_name}-if
|
||||
PRIVATE ${bare_name}-common
|
||||
PRIVATE ${bare_name}-machinery
|
||||
PRIVATE glob2regex
|
||||
)
|
||||
|
||||
string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}")
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "dindexer-common/settings.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "hash.hpp"
|
||||
#include "glob2regex/glob2regex.hpp"
|
||||
#include <iostream>
|
||||
#include <ciso646>
|
||||
#include <iterator>
|
||||
|
@ -81,7 +82,8 @@ int main (int parArgc, char* parArgv[]) {
|
|||
results = din::locate_in_db(settings.db, hash);
|
||||
}
|
||||
else {
|
||||
results = din::locate_in_db(settings.db, vm["substring"].as<std::string>(), not not vm.count("case-insensitive"));
|
||||
const auto search_regex = g2r::convert(vm["substring"].as<std::string>());
|
||||
results = din::locate_in_db(settings.db, search_regex, not not vm.count("case-insensitive"));
|
||||
}
|
||||
std::copy(results.begin(), results.end(), std::ostream_iterator<din::LocatedItem>(std::cout, "\n"));
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include "pq/connection.hpp"
|
||||
#include "dindexer-machinery/tiger.hpp"
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
|
@ -73,27 +71,17 @@ namespace din {
|
|||
} //unnamed namespace
|
||||
|
||||
std::vector<LocatedItem> locate_in_db (const dinlib::SettingsDB& parDB, const std::string& parSearch, bool parCaseInsensitive) {
|
||||
using boost::string_ref;
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
auto conn = make_pq_conn(parDB);
|
||||
|
||||
const auto clean_string_with_quotes = conn.escaped_literal(parSearch);
|
||||
const auto clean_string = string_ref(clean_string_with_quotes).substr(1, clean_string_with_quotes.size() - 2);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "SELECT \"path\",\"id\",\"group_id\" FROM \"files\" WHERE ";
|
||||
if (parCaseInsensitive) {
|
||||
std::string lower(clean_string);
|
||||
ba::to_lower(lower);
|
||||
oss << "LOWER(\"path\") LIKE '%" << lower << "%' ";
|
||||
}
|
||||
else {
|
||||
oss << "\"path\" LIKE '%" << clean_string << "%' ";
|
||||
}
|
||||
oss << "LIMIT " << g_max_results << ';';
|
||||
const std::string search_regex = (parCaseInsensitive ? "(?i)" : "") + parSearch;
|
||||
const std::string query =
|
||||
std::string("SELECT \"path\",\"id\",\"group_id\" FROM \"files\" WHERE \"path\" ~ $1 LIMIT ") +
|
||||
boost::lexical_cast<std::string>(g_max_results) +
|
||||
";";
|
||||
|
||||
auto result = conn.query(oss.str());
|
||||
auto result = conn.query(query, search_regex);
|
||||
return file_result_to_vec(std::move(result));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue