diff --git a/cmake/cmake.options b/cmake/cmake.options index 74b0d9fdbb..bbecf614d1 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -16,17 +16,17 @@ option( option( BUILD_WITH_ROCKSDB "If build with rocksdb" - OFF + OF ) option( BUILD_WITH_LUCENE "If build with lucene" - OFF + on ) option( BUILD_DEPENDENCY_TESTS "If build dependency tests" OFF -) \ No newline at end of file +) diff --git a/cmake/lucene_CMakeLists.txt.in b/cmake/lucene_CMakeLists.txt.in index 91e144dced..436ac64475 100644 --- a/cmake/lucene_CMakeLists.txt.in +++ b/cmake/lucene_CMakeLists.txt.in @@ -1,8 +1,7 @@ # lucene ExternalProject_Add(lucene - GIT_REPOSITORY https://github.com/taosdata-contrib/LucenePlusPlus.git - GIT_TAG rel_3.0.8 + GIT_REPOSITORY https://github.com/yihaoDeng/LucenePlusPlus.git SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/lucene" BINARY_DIR "" #BUILD_IN_SOURCE TRUE @@ -10,4 +9,4 @@ ExternalProject_Add(lucene BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" -) \ No newline at end of file +) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index e35417b4c5..7392763d03 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -65,6 +65,11 @@ endif(${BUILD_WITH_ROCKSDB}) if(${BUILD_WITH_LUCENE}) option(ENABLE_TEST "Enable the tests" OFF) add_subdirectory(lucene) + target_include_directories( + lucene++ + PUBLIC $ + ) + endif(${BUILD_WITH_LUCENE}) # ================================================================================================ diff --git a/include/libs/index/index.h b/include/libs/index/index.h index f821b437af..bdd0905234 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -16,12 +16,72 @@ #ifndef _TD_INDEX_H_ #define _TD_INDEX_H_ +#include "os.h" +#include "tarray.h" + #ifdef __cplusplus extern "C" { #endif +typedef struct SIndex SIndex; +typedef struct SIndexOpts SIndexOpts; + +typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType; +typedef enum { QUERY_POINT = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2,QUERY_REGEX = 3} EIndexQueryType; + + + +typedef struct SIndexTermQuery { + EIndexQueryType opera; + SArray *querys; +} SIndexTermQuery; + +// tag and tag val; +typedef struct SIndexPair { + char *key; + char *val; +} SIndexPair; + +// +typedef struct SIndexTerm { + SIndexPair* field_value; + EIndexQueryType type; +} SIndexTerm; + + + +/* + * @param: oper + * +*/ + +SIndexTermQuery *indexTermQueryCreate(EIndexOperatorType oper); +void indexTermQueryDestroy(SIndexTermQuery *pQuery); +int indexTermQueryAdd(SIndexTermQuery *pQuery, const char *field, int32_t nFields, const char *value, int32_t nValue, EIndexQueryType type); + + + +/* + * @param: + * @param: + */ +SIndex* indexOpen(SIndexOpts *opt, const char *path); + +void indexClose(SIndex *index); +int indexPut(SIndex *index, SArray *pairs, int uid); +int indexDelete(SIndex *index, SIndexTermQuery *query); +int indexSearch(SIndex *index, SIndexTermQuery *query, SArray *result); +int indexRebuild(SIndex *index, SIndexOpts *opt); + +/* + * @param: + * @param: + */ +SIndexOpts *indexOptsCreate(); +void indexOptsDestroy(SIndexOpts *opts); + #ifdef __cplusplus } #endif -#endif /*_TD_INDEX_H_*/ \ No newline at end of file +#endif /*_TD_INDEX_H_*/ diff --git a/source/libs/index/CMakeLists.txt b/source/libs/index/CMakeLists.txt index 638d3f64cd..3da2c93b39 100644 --- a/source/libs/index/CMakeLists.txt +++ b/source/libs/index/CMakeLists.txt @@ -4,4 +4,27 @@ target_include_directories( index PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) \ No newline at end of file +) +target_link_libraries( + index + PUBLIC os + PUBLIC util +) + +if (${BUILD_WITH_LUCENE}) + target_include_directories( + index + PUBLIC "${CMAKE_SOURCE_DIR}/deps/lucene/include" + ) + LINK_DIRECTORIES("${CMAKE_SOURCE_DIR}/deps/lucene/debug/src/core") + target_link_libraries( + index + PUBLIC lucene++ + ) + +endif(${BUILD_WITH_LUCENE}) + +if (${BUILD_TEST}) + add_subdirectory(test) +endif(${BUILD_TEST}) + diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index 81eba4ec91..8d8c950075 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -16,12 +16,31 @@ #ifndef _TD_INDEX_INT_H_ #define _TD_INDEX_INT_H_ +#include "index.h" + +#ifdef USE_LUCENE +#include +#endif + + #ifdef __cplusplus extern "C" { #endif +struct SIndex { +#ifdef USE_LUCENE + index_t *index; +#endif +}; + +struct SIndexOpts { +#ifdef USE_LUCENE + void *opts; +#endif +}; + #ifdef __cplusplus } #endif -#endif /*_TD_INDEX_INT_H_*/ \ No newline at end of file +#endif /*_TD_INDEX_INT_H_*/ diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index f821b437af..46039249c5 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -13,15 +13,71 @@ * along with this program. If not, see . */ -#ifndef _TD_INDEX_H_ -#define _TD_INDEX_H_ +#include "index.h" +#include "indexInt.h" -#ifdef __cplusplus -extern "C" { +#ifdef USE_LUCENE +#include "lucene++/Lucene_c.h" #endif -#ifdef __cplusplus +static pthread_once_t isInit = PTHREAD_ONCE_INIT; + +static void indexInit(); + +SIndex *indexOpen(SIndexOpts *opts, const char *path) { + pthread_once(&isInit, indexInit); +#ifdef USE_LUCENE + index_t *index = index_open(path); + SIndex *p = malloc(sizeof(SIndex)); + p->index = index; + return p; +#endif + return NULL; } -#endif -#endif /*_TD_INDEX_H_*/ \ No newline at end of file +void indexClose(SIndex *index) { +#ifdef USE_LUCENE + index_close(index->index); +#endif + free(index); + return; + +} +int indexPut(SIndex *index, SArray* field_vals, int uid) { + return 1; + +} +int indexSearch(SIndex *index, SIndexTermQuery *query, SArray *result) { + return 1; +} + +int indexDelete(SIndex *index, SIndexTermQuery *query) { + return 1; +} +int indexRebuild(SIndex *index, SIndexOpts *opts); + + +SIndexOpts *indexOptsCreate() { + return NULL; +} +void indexOptsDestroy(SIndexOpts *opts) { + +} +/* + * @param: oper + * +*/ + +SIndexTermQuery *indexTermQueryCreate(EIndexOperatorType oper) { + return NULL; +} +void indexTermQueryDestroy(SIndexTermQuery *pQuery) { + +} +int indexTermQueryAdd(SIndexTermQuery *pQuery, const char *field, int32_t nFields, const char *value, int32_t nValue, EIndexQueryType type){ + return 1; +} + +void indexInit() { + //do nothing +} diff --git a/source/libs/index/test/indexTests.cpp b/source/libs/index/test/indexTests.cpp index e69de29bb2..047491838f 100644 --- a/source/libs/index/test/indexTests.cpp +++ b/source/libs/index/test/indexTests.cpp @@ -0,0 +1,15 @@ +#include +#include +#include +#include "index.h" + + + +TEST(IndexTest, index_create_test) { + SIndexOpts *opts = indexOptsCreate(); + SIndex *index = indexOpen(opts, "./"); + if (index == NULL) { + std::cout << "index open failed" << std::endl; + } + indexOptsDestroy(opts); +} diff --git a/source/libs/tkv/src/tkv.c b/source/libs/tkv/src/tkv.c index 5319f6b9da..0c6f896d56 100644 --- a/source/libs/tkv/src/tkv.c +++ b/source/libs/tkv/src/tkv.c @@ -158,6 +158,8 @@ static void tkvInit() { #ifdef USE_ROCKSDB defaultReadOpts.ropts = rocksdb_readoptions_create(); defaultWriteOpts.wopts = rocksdb_writeoptions_create(); + rocksdb_writeoptions_disable_WAL(defaultWriteOpts.wopts, true); + #endif } @@ -166,4 +168,4 @@ static void tkvClear() { rocksdb_readoptions_destroy(defaultReadOpts.ropts); rocksdb_writeoptions_destroy(defaultWriteOpts.wopts); #endif -} \ No newline at end of file +}