1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// *****************************************************************************
/*!
  \file      src/db.hpp
  \copyright 2022-2025 J. Bakosi,
             All rights reserved. See the LICENSE file for details.
  \brief     Piac database functionality
*/
// *****************************************************************************

#pragma once

#include <vector>
#include <unordered_set>

#if defined(__clang__)
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-W#warnings"
#endif

#include "xapian.h"

#if defined(__clang__)
  #pragma clang diagnostic pop
#endif

#include "document.hpp"

namespace piac {

//! Get number of documents in Xapian database
Xapian::doccount get_doccount( const std::string db_name );

//! Add document to Xapian database
std::string
add_document( const std::string& author,
              Xapian::TermGenerator& indexer,
              Xapian::WritableDatabase& db,
              Document& ndoc );

//! Index Xapian database
std::string
index_db( const std::string& author,
          const std::string& db_name,
          const std::string& input_filename,
          const std::unordered_set< std::string >& my_hashes = {} );

//! Query Xapian database
[[nodiscard]] std::string
db_query( const std::string& db_name, std::string&& cmd );

//! Get documents from Xapian database
[[nodiscard]] std::vector< std::string >
db_get_docs( const std::string& db_name,
             const std::vector< std::string >& hashes );

//! Put documents to Xapian database
std::size_t
db_put_docs( const std::string& db_name,
             const std::vector< std::string >& docs );

//! Remove documents from Xapian database
std::string
db_rm_docs( const std::string& author,
            const std::string& db_name,
            const std::unordered_set< std::string >& hashes_to_delete,
            const std::unordered_set< std::string >& my_hashes = {} );

//! List hashes from Xapian database
[[nodiscard]] std::vector< std::string >
db_list_hash( const std::string& db_name, bool inhex );

//! List documents from Xapian database
[[nodiscard]] std::vector< std::string >
db_list_doc( const std::string& db_name );

//! List number of unique users in Xapian database
[[nodiscard]] std::size_t
db_list_numuser( const std::string& db_name );

//! Add documents to Xapian database
std::string
db_add( const std::string& author,
        const std::string& db_name,
        std::string&& cmd,
        const std::unordered_set< std::string >& my_hashes = {} );

//! Remove documents from Xapian database
std::string
db_rm( const std::string& author,
       const std::string& db_name,
       std::string&& cmd,
       const std::unordered_set< std::string >& my_hashes );

//! List Xapian database
std::string db_list( const std::string& db_name, std::string&& cmd );

} // piac::