From 34936013f5c92ff4f25ee79cd153f388d6992ac4 Mon Sep 17 00:00:00 2001 From: roy1994 Date: Sun, 28 May 2023 00:25:57 +0800 Subject: [PATCH] fix(backends): create the static domain to avoid Chrome Not Allowed to Load Local Resource --- CMakeLists.txt | 2 +- assets/config.json | 37 ++++++++++++------------ src/preprocessing/src/LibraryBuilder.cpp | 2 +- src/query/src/Queryer.cpp | 10 +++++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3236fa8..a6a5e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) project(OurSearchEngine) -set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_BUILD_TYPE Release) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/assets/config.json b/assets/config.json index 5b413b7..bd52c63 100644 --- a/assets/config.json +++ b/assets/config.json @@ -6,22 +6,23 @@ "https": false } ], - "threads_num": 4, - "document_root": "/home/roy1994/Code/Project/OurSearchEngine/assets/material", - "file_types": [ - "gif", - "png", - "jpg", - "js", - "css", - "html", - "ico", - "swf", - "xap", - "apk", - "cur", - "xml", - "htm", - "txt" - ] + "app": { + "document_root": "../assets/material", + "file_types": [ + "gif", + "png", + "jpg", + "js", + "css", + "html", + "ico", + "swf", + "xap", + "apk", + "cur", + "xml", + "htm", + "txt" + ] + } } \ No newline at end of file diff --git a/src/preprocessing/src/LibraryBuilder.cpp b/src/preprocessing/src/LibraryBuilder.cpp index f2df812..57eaaaa 100644 --- a/src/preprocessing/src/LibraryBuilder.cpp +++ b/src/preprocessing/src/LibraryBuilder.cpp @@ -42,7 +42,7 @@ void LibraryBuilder::scan_directory() { for (const auto &entry : fs::directory_iterator(current_path)) { bar.tick(); if (fs::is_regular_file(entry) && entry.path().extension() == ".txt") { - file_path_list.push_back(std::filesystem::canonical(entry.path()).string()); + file_path_list.push_back(entry.path().string()); } else if (fs::is_directory(entry)) { path_stack.push(entry.path()); } diff --git a/src/query/src/Queryer.cpp b/src/query/src/Queryer.cpp index 871a0a9..27f230e 100644 --- a/src/query/src/Queryer.cpp +++ b/src/query/src/Queryer.cpp @@ -5,7 +5,7 @@ #include #include #include - +#include #include "XMLParser.hpp" #include "Datatype.h" #include "SearchResultBuilder.h" @@ -109,8 +109,12 @@ std::pair>, uint64_t> Queryer::cre info.title = xmlParser.parser("Title"); info.text = xmlParser.parser("Content"); info.desc = info.text.substr(0, std::min(static_cast(info.text.size()), 256ul)); //描述暂时用标题替代 - std::map correlation; //相关性暂时设为空 - std::unique_ptr item = std::make_unique(scores[i].second, "file://" + xmlParser.parser("Url"), info, correlation, 0); + std::map correlation; + //相关性暂时设为空 + auto url = std::filesystem::relative(xmlParser.parser("Url"), "../assets/material"); + + std::unique_ptr + item = std::make_unique(scores[i].second, "http://localhost:7777/" + url.string(), info, correlation, 0); ret.push_back(std::move(item)); }