mirror of https://github.com/kiwix/libkiwix.git
+ New content manager search/filter feature (ID: 3390515)
This commit is contained in:
parent
e33b448380
commit
a1dfb3c9fd
|
@ -436,7 +436,7 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
||||||
const string language, const string publisher) {
|
const string language, const string publisher, const string search) {
|
||||||
this->bookIdList.clear();
|
this->bookIdList.clear();
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
|
||||||
|
@ -478,6 +478,9 @@ namespace kiwix {
|
||||||
if (ok == true && !publisher.empty() && itr->creator != publisher)
|
if (ok == true && !publisher.empty() && itr->creator != publisher)
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
|
if (ok == true && !search.empty() && !(matchRegex(itr->title, search) || matchRegex(itr->description, search)))
|
||||||
|
ok = false;
|
||||||
|
|
||||||
if (ok == true) {
|
if (ok == true) {
|
||||||
this->bookIdList.push_back(itr->id);
|
this->bookIdList.push_back(itr->id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
|
|
||||||
#include "../base64.h"
|
#include "../base64.h"
|
||||||
|
#include "../regexTools.h"
|
||||||
#include <kiwix/library.h>
|
#include <kiwix/library.h>
|
||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ namespace kiwix {
|
||||||
bool updateBookLastOpenDateById(const string id);
|
bool updateBookLastOpenDateById(const string id);
|
||||||
void removeBookPaths();
|
void removeBookPaths();
|
||||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
||||||
const string language, const string publisher);
|
const string language, const string publisher, const string search);
|
||||||
vector<string> getBooksLanguages();
|
vector<string> getBooksLanguages();
|
||||||
vector<string> getBooksPublishers();
|
vector<string> getBooksPublishers();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "nsStringAPI.h"
|
#include "nsStringAPI.h"
|
||||||
|
|
||||||
const char *nsStringToCString(const nsAString &path);
|
const char *nsStringToCString(const nsAString &str);
|
||||||
const char *nsStringToUTF8(const nsAString &str);
|
const char *nsStringToUTF8(const nsAString &str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "regexTools.h"
|
||||||
|
|
||||||
|
bool matchRegex(const std::string &content, const std::string regex) {
|
||||||
|
regex_t regexp;
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
regcomp(®exp, regex.data(), REG_ICASE);
|
||||||
|
result = !regexec(®exp, content.data(), 0, 0, 0);
|
||||||
|
regfree(®exp);
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KIWIX_REGEXTOOLS_H
|
||||||
|
#define KIWIX_REGEXTOOLS_H
|
||||||
|
|
||||||
|
#include <regex.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
bool matchRegex(const std::string &content, const std::string regex);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue