add lucene
This commit is contained in:
parent
8be1a251df
commit
d4cd3836f1
|
@ -16,13 +16,13 @@ option(
|
|||
option(
|
||||
BUILD_WITH_ROCKSDB
|
||||
"If build with rocksdb"
|
||||
OFF
|
||||
OF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_LUCENE
|
||||
"If build with lucene"
|
||||
OFF
|
||||
on
|
||||
)
|
||||
|
||||
option(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
|
||||
)
|
||||
|
||||
endif(${BUILD_WITH_LUCENE})
|
||||
|
||||
# ================================================================================================
|
||||
|
|
|
@ -16,10 +16,70 @@
|
|||
#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
|
||||
|
|
|
@ -5,3 +5,26 @@ target_include_directories(
|
|||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index"
|
||||
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,10 +16,29 @@
|
|||
#ifndef _TD_INDEX_INT_H_
|
||||
#define _TD_INDEX_INT_H_
|
||||
|
||||
#include "index.h"
|
||||
|
||||
#ifdef USE_LUCENE
|
||||
#include <lucene++/Lucene_c.h>
|
||||
#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
|
||||
|
|
|
@ -13,15 +13,71 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
||||
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
|
||||
defaultReadOpts.ropts = rocksdb_readoptions_create();
|
||||
defaultWriteOpts.wopts = rocksdb_writeoptions_create();
|
||||
rocksdb_writeoptions_disable_WAL(defaultWriteOpts.wopts, true);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue