mirror of
https://github.com/privacore/open-source-search-engine.git
synced 2025-07-16 02:46:08 -04:00
Initial commit of tool to regenerate rdb index file (for ease of testing)
This commit is contained in:
47
tools/Makefile
Normal file
47
tools/Makefile
Normal file
@ -0,0 +1,47 @@
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
TARGETS := $(sort $(patsubst %.cpp, %, $(wildcard *.cpp)))
|
||||
|
||||
BASE_DIR ?= ..
|
||||
|
||||
.PHONY: all
|
||||
all: $(TARGETS)
|
||||
|
||||
.PHONY: libgb.a
|
||||
libgb.a:
|
||||
$(MAKE) -C $(BASE_DIR) libgb.a
|
||||
|
||||
ucdata:
|
||||
ln -s $(BASE_DIR)/$@ .
|
||||
|
||||
$(BASE_DIR)/libcld2_full.so:
|
||||
$(MAKE) -C $(BASE_DIR) libcld2_full.so
|
||||
|
||||
CPPFLAGS += -g
|
||||
CPPFLAGS += -Wall -Wno-write-strings
|
||||
CPPFLAGS += -Wl,-rpath=. -Wl,-rpath=$(BASE_DIR)
|
||||
CPPFLAGS += -I$(BASE_DIR)
|
||||
CPPFLAGS += -std=c++11
|
||||
|
||||
# exported in parent make
|
||||
CPPFLAGS += $(CONFIG_CPPFLAGS)
|
||||
|
||||
LIBS += $(BASE_DIR)/libgb.a -lz -lpthread -lssl -lcrypto
|
||||
LIBS += -L$(BASE_DIR) -lcld2_full
|
||||
|
||||
%: libgb.a $(BASE_DIR)/libcld2_full.so %.cpp
|
||||
$(CXX) $(CPPFLAGS) $@.cpp $(LIBS) -o $@
|
||||
|
||||
.PHONY: check
|
||||
check: TARGET_PRE="valgrind"
|
||||
check: test
|
||||
|
||||
.PHONY: test
|
||||
test: all ucdata
|
||||
-$(TARGET_PRE) ./$(TARGET) $(TEST_ARGS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.o $(TARGETS) core.*
|
||||
rm -f *.gcda *.gcno
|
||||
|
79
tools/generate_rdbindex.cpp
Normal file
79
tools/generate_rdbindex.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include "BigFile.h"
|
||||
#include "RdbIndex.h"
|
||||
#include "Posdb.h"
|
||||
#include "Log.h"
|
||||
#include <libgen.h>
|
||||
|
||||
static void print_usage(const char *argv0) {
|
||||
fprintf(stdout, "Usage: %s [-h] FILE\n", argv0);
|
||||
fprintf(stdout, "Generate RDB index from FILE\n");
|
||||
fprintf(stdout, "\n");
|
||||
fprintf(stdout, " -h, --help display this help and exit\n");
|
||||
}
|
||||
|
||||
static bool starts_with(const char *haystack, const char *needle) {
|
||||
size_t haystackLen = strlen(haystack);
|
||||
size_t needleLen = strlen(needle);
|
||||
if (haystackLen < needleLen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (memcmp(haystack, needle, needleLen) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
print_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--h") == 0 || strcmp(argv[1], "--help") == 0 ) {
|
||||
print_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char filepath[1024];
|
||||
|
||||
char dir[1024];
|
||||
strcpy(filepath, argv[1]);
|
||||
strcpy(dir, dirname(filepath));
|
||||
|
||||
char filename[1024];
|
||||
strcpy(filepath, argv[1]);
|
||||
strcpy(filename, basename(filepath));
|
||||
|
||||
char indexFilename[1024];
|
||||
strcpy(indexFilename, filename);
|
||||
strcpy(strrchr(indexFilename, '.'), ".idx");
|
||||
|
||||
// initialize library
|
||||
g_conf.m_maxMem = 1000000000LL;
|
||||
g_mem.init();
|
||||
hashinit();
|
||||
|
||||
g_conf.init(NULL);
|
||||
|
||||
BigFile bigFile;
|
||||
bigFile.set(dir, filename);
|
||||
|
||||
g_conf.m_logTraceRdbIndex = true;
|
||||
|
||||
RdbIndex index;
|
||||
if (starts_with(filename, "posdb")) {
|
||||
index.set(dir, indexFilename, 0, true, sizeof(key144_t), RDB_POSDB);
|
||||
if (!index.generateIndex(&bigFile)) {
|
||||
fprintf(stdout, "Unable to generate index for %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!index.writeIndex()) {
|
||||
fprintf(stdout, "Unable to save index for %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stdout, "Unsupported rdb type\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user