add lucene
This commit is contained in:
parent
8be1a251df
commit
d4cd3836f1
|
@ -16,17 +16,17 @@ option(
|
||||||
option(
|
option(
|
||||||
BUILD_WITH_ROCKSDB
|
BUILD_WITH_ROCKSDB
|
||||||
"If build with rocksdb"
|
"If build with rocksdb"
|
||||||
OFF
|
OF
|
||||||
)
|
)
|
||||||
|
|
||||||
option(
|
option(
|
||||||
BUILD_WITH_LUCENE
|
BUILD_WITH_LUCENE
|
||||||
"If build with lucene"
|
"If build with lucene"
|
||||||
OFF
|
on
|
||||||
)
|
)
|
||||||
|
|
||||||
option(
|
option(
|
||||||
BUILD_DEPENDENCY_TESTS
|
BUILD_DEPENDENCY_TESTS
|
||||||
"If build dependency tests"
|
"If build dependency tests"
|
||||||
OFF
|
OFF
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
# lucene
|
# lucene
|
||||||
ExternalProject_Add(lucene
|
ExternalProject_Add(lucene
|
||||||
GIT_REPOSITORY https://github.com/taosdata-contrib/LucenePlusPlus.git
|
GIT_REPOSITORY https://github.com/yihaoDeng/LucenePlusPlus.git
|
||||||
GIT_TAG rel_3.0.8
|
|
||||||
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/lucene"
|
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/lucene"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
@ -10,4 +9,4 @@ ExternalProject_Add(lucene
|
||||||
BUILD_COMMAND ""
|
BUILD_COMMAND ""
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
TEST_COMMAND ""
|
TEST_COMMAND ""
|
||||||
)
|
)
|
||||||
|
|
|
@ -65,6 +65,11 @@ endif(${BUILD_WITH_ROCKSDB})
|
||||||
if(${BUILD_WITH_LUCENE})
|
if(${BUILD_WITH_LUCENE})
|
||||||
option(ENABLE_TEST "Enable the tests" OFF)
|
option(ENABLE_TEST "Enable the tests" OFF)
|
||||||
add_subdirectory(lucene)
|
add_subdirectory(lucene)
|
||||||
|
target_include_directories(
|
||||||
|
lucene++
|
||||||
|
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
|
||||||
|
)
|
||||||
|
|
||||||
endif(${BUILD_WITH_LUCENE})
|
endif(${BUILD_WITH_LUCENE})
|
||||||
|
|
||||||
# ================================================================================================
|
# ================================================================================================
|
||||||
|
|
|
@ -16,12 +16,72 @@
|
||||||
#ifndef _TD_INDEX_H_
|
#ifndef _TD_INDEX_H_
|
||||||
#define _TD_INDEX_H_
|
#define _TD_INDEX_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "tarray.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_INDEX_H_*/
|
#endif /*_TD_INDEX_H_*/
|
||||||
|
|
|
@ -4,4 +4,27 @@ target_include_directories(
|
||||||
index
|
index
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
|
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})
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,31 @@
|
||||||
#ifndef _TD_INDEX_INT_H_
|
#ifndef _TD_INDEX_INT_H_
|
||||||
#define _TD_INDEX_INT_H_
|
#define _TD_INDEX_INT_H_
|
||||||
|
|
||||||
|
#include "index.h"
|
||||||
|
|
||||||
|
#ifdef USE_LUCENE
|
||||||
|
#include <lucene++/Lucene_c.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct SIndex {
|
||||||
|
#ifdef USE_LUCENE
|
||||||
|
index_t *index;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SIndexOpts {
|
||||||
|
#ifdef USE_LUCENE
|
||||||
|
void *opts;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_INDEX_INT_H_*/
|
#endif /*_TD_INDEX_INT_H_*/
|
||||||
|
|
|
@ -13,15 +13,71 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_INDEX_H_
|
#include "index.h"
|
||||||
#define _TD_INDEX_H_
|
#include "indexInt.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef USE_LUCENE
|
||||||
extern "C" {
|
#include "lucene++/Lucene_c.h"
|
||||||
#endif
|
#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_*/
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -158,6 +158,8 @@ static void tkvInit() {
|
||||||
#ifdef USE_ROCKSDB
|
#ifdef USE_ROCKSDB
|
||||||
defaultReadOpts.ropts = rocksdb_readoptions_create();
|
defaultReadOpts.ropts = rocksdb_readoptions_create();
|
||||||
defaultWriteOpts.wopts = rocksdb_writeoptions_create();
|
defaultWriteOpts.wopts = rocksdb_writeoptions_create();
|
||||||
|
rocksdb_writeoptions_disable_WAL(defaultWriteOpts.wopts, true);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,4 +168,4 @@ static void tkvClear() {
|
||||||
rocksdb_readoptions_destroy(defaultReadOpts.ropts);
|
rocksdb_readoptions_destroy(defaultReadOpts.ropts);
|
||||||
rocksdb_writeoptions_destroy(defaultWriteOpts.wopts);
|
rocksdb_writeoptions_destroy(defaultWriteOpts.wopts);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue