Project: finder, src: Finder.h


検索エンジンを動かすためのヘッダファイル
#ifndef FINDER_H_
#define FINDER_H_

#include "BPTree.h"
#include "TrMatrix.h"
#include "DocumentList.h"
#include <list>

#define MAX_DOCUMENT_LIST (10000 - 1)

class Finder {
 private:
  BPTree bptree;
  TrMatrix work;
  int analyzeCount;
  int fd;
  int docfd;
  bool bCreate;

  bool incrementDocItr(BPTree::ObjectStream &os, DocumentList &doclist, DocumentList::iterator &i);
  bool find(unsigned long long *nextId, std::list<Document> &result, Document &doc, std::vector<BPTree::ObjectStream> &objStreamArray, std::vector<DocumentList> &doclistArray, std::vector<DocumentList::iterator> &docItrArray);

 public:
  Finder(const std::string &docfile, const std::string &filename, bool bTrunc = true);
  Finder(int docfd, int fd) : bptree(fd), work(), analyzeCount(0), fd(fd), docfd(docfd), bCreate(true) {}
  ~Finder() {
    if (analyzeCount > 0) {
      flush();
    }
    if (bCreate) {
      close(docfd);
    }
  }
  void add(unsigned long long id);
  void flush();
  std::list<Document> find(const char *utf8, int len8);
  int getDocfd() const {
    return docfd;
  }
};

#endif //FINDER_H_