+ New content manager search/filter feature (ID: 3390515)

This commit is contained in:
kelson42 2011-10-13 11:31:20 +00:00
parent e33b448380
commit a1dfb3c9fd
5 changed files with 66 additions and 3 deletions

View File

@ -436,7 +436,7 @@ namespace kiwix {
}
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();
std::vector<kiwix::Book>::iterator itr;
@ -478,6 +478,9 @@ namespace kiwix {
if (ok == true && !publisher.empty() && itr->creator != publisher)
ok = false;
if (ok == true && !search.empty() && !(matchRegex(itr->title, search) || matchRegex(itr->description, search)))
ok = false;
if (ok == true) {
this->bookIdList.push_back(itr->id);
}

View File

@ -32,6 +32,7 @@
#include <pugixml.hpp>
#include "../base64.h"
#include "../regexTools.h"
#include <kiwix/library.h>
#include <kiwix/reader.h>
@ -64,7 +65,7 @@ namespace kiwix {
bool updateBookLastOpenDateById(const string id);
void removeBookPaths();
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> getBooksPublishers();

View File

@ -22,7 +22,7 @@
#include "nsStringAPI.h"
const char *nsStringToCString(const nsAString &path);
const char *nsStringToCString(const nsAString &str);
const char *nsStringToUTF8(const nsAString &str);
#endif

30
src/common/regexTools.cpp Normal file
View File

@ -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(&regexp, regex.data(), REG_ICASE);
result = !regexec(&regexp, content.data(), 0, 0, 0);
regfree(&regexp);
return result;
}

29
src/common/regexTools.h Normal file
View File

@ -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