indexTests.cpp 2.4 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1 2 3 4
#include <gtest/gtest.h>
#include <string>
#include <iostream>
#include "index.h"
dengyihao's avatar
dengyihao 已提交
5
#include "indexInt.h"
dengyihao's avatar
dengyihao 已提交
6 7 8
#include "index_fst.h"
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
dengyihao's avatar
dengyihao 已提交
9

dengyihao's avatar
dengyihao 已提交
10 11 12



dengyihao's avatar
dengyihao 已提交
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
//TEST(IndexTest, index_create_test) {
//  SIndexOpts *opts = indexOptsCreate();
//  SIndex *index = indexOpen(opts, "./test");
//  if (index == NULL) {
//    std::cout << "index open failed" << std::endl; 
//  }
//
//  
//  // write   
//  for (int i = 0; i < 100000; i++) {
//    SIndexMultiTerm* terms = indexMultiTermCreate();
//    std::string val = "field";    
//
//    indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size());
//
//    val.append(std::to_string(i)); 
//    indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size());
//
//    val.insert(0, std::to_string(i));
//    indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size());
//
//    val.append("const");    
//    indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size());
//
//     
//    indexPut(index, terms, i);
//    indexMultiTermDestroy(terms);
//  } 
// 
//
//  // query
//  SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST); 
//  
//  indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX);
//  indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM);
//
//  SArray *result = (SArray *)taosArrayInit(10, sizeof(int));   
//  indexSearch(index, multiQuery, result);
//
//  std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl;
//  for (int i = 0;  i < taosArrayGetSize(result); i++) {
//    int *v = (int *)taosArrayGet(result, i);
//    std::cout << "value --->" << *v  << std::endl;
//  }
//  // add more test case 
//  indexMultiTermQueryDestroy(multiQuery);
//
//  indexOptsDestroy(opts); 
//  indexClose(index); 
//  //
//}
dengyihao's avatar
dengyihao 已提交
64

dengyihao's avatar
dengyihao 已提交
65
int main(int argc, char** argv) {
dengyihao's avatar
dengyihao 已提交
66
  std::string str("abc");
dengyihao's avatar
dengyihao 已提交
67
  FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
dengyihao's avatar
dengyihao 已提交
68
  Output   val = 1;
dengyihao's avatar
dengyihao 已提交
69

dengyihao's avatar
dengyihao 已提交
70 71 72
  //std::string str1("bcd");
  //FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size());
  //Output   val2 = 10;
dengyihao's avatar
dengyihao 已提交
73 74
  FstBuilder *b = fstBuilderCreate(NULL, 1);
  fstBuilderInsert(b, key, val); 
dengyihao's avatar
dengyihao 已提交
75
  //fstBuilderInsert(b, key1, val2); 
dengyihao's avatar
dengyihao 已提交
76 77 78 79 80
  fstBuilderFinish(b);
  fstBuilderDestroy(b);
  fstSliceDestroy(&key);
  return 1;
}
dengyihao's avatar
dengyihao 已提交
81

dengyihao's avatar
dengyihao 已提交
82 83 84
//TEST(IndexFstBuilder, IndexFstInput) {
//
//}
dengyihao's avatar
dengyihao 已提交
85 86