indexTests.cpp 2.6 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
  FstBuilder *b = fstBuilderCreate(NULL, 0);
dengyihao's avatar
dengyihao 已提交
67
  {
dengyihao's avatar
dengyihao 已提交
68
    std::string str("aaa");
dengyihao's avatar
dengyihao 已提交
69 70 71 72
    FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
    Output   val = 1;
    fstBuilderInsert(b, key, val); 
  }
dengyihao's avatar
dengyihao 已提交
73

dengyihao's avatar
dengyihao 已提交
74 75 76
  //std::string str1("bcd");
  //FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size());
  //Output   val2 = 10;
dengyihao's avatar
dengyihao 已提交
77 78
  //
   
dengyihao's avatar
dengyihao 已提交
79
  {
dengyihao's avatar
dengyihao 已提交
80 81 82 83 84 85 86 87 88
     
    for (size_t i = 1; i < 26; i++) {
      std::string str("aaa");
      str[2] = 'a' + i ;
      FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
      Output   val = 2;
      fstBuilderInsert(b, key, val); 
    }
    
dengyihao's avatar
dengyihao 已提交
89
  } 
dengyihao's avatar
dengyihao 已提交
90
  //fstBuilderInsert(b, key1, val2); 
dengyihao's avatar
dengyihao 已提交
91 92 93 94
  fstBuilderFinish(b);
  fstBuilderDestroy(b);
  return 1;
}
dengyihao's avatar
dengyihao 已提交
95

dengyihao's avatar
dengyihao 已提交
96 97 98
//TEST(IndexFstBuilder, IndexFstInput) {
//
//}
dengyihao's avatar
dengyihao 已提交
99 100