Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9e74ea9e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9e74ea9e
编写于
10月 22, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add lucene test
上级
d4cd3836
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
158 addition
and
43 deletion
+158
-43
include/libs/index/index.h
include/libs/index/index.h
+15
-33
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+21
-0
source/libs/index/src/index.c
source/libs/index/src/index.c
+93
-9
source/libs/index/test/indexTests.cpp
source/libs/index/test/indexTests.cpp
+29
-1
未找到文件。
include/libs/index/index.h
浏览文件 @
9e74ea9e
...
...
@@ -25,54 +25,36 @@ extern "C" {
typedef
struct
SIndex
SIndex
;
typedef
struct
SIndexOpts
SIndexOpts
;
typedef
struct
SIndexMultiTermQuery
SIndexMultiTermQuery
;
typedef
struct
SArray
SIndexMultiTerm
;
//typedef struct SIndexMultiTerm SIndexMultiTerm;
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
);
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
oper
);
void
indexMultiTermQueryDestroy
(
SIndexMultiTermQuery
*
pQuery
);
int
indexMultiTermQueryAdd
(
SIndexMultiTermQuery
*
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
);
void
indexClose
(
SIndex
*
index
);
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
terms
,
int
uid
);
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
);
int
indexSearch
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
,
SArray
*
result
);
int
indexRebuild
(
SIndex
*
index
,
SIndexOpts
*
opt
);
SIndexMultiTerm
*
indexMultiTermCreate
();
int
indexMultiTermAdd
(
SIndexMultiTerm
*
terms
,
const
char
*
field
,
int32_t
nFields
,
const
char
*
value
,
int32_t
nValue
);
void
indexMultiTermDestroy
(
SIndexMultiTerm
*
terms
);
/*
* @param:
* @param:
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
9e74ea9e
...
...
@@ -39,6 +39,27 @@ struct SIndexOpts {
#endif
};
struct
SIndexMultiTermQuery
{
EIndexOperatorType
opera
;
SArray
*
query
;
};
// field and key;
typedef
struct
SIndexTerm
{
char
*
key
;
int32_t
nKey
;
char
*
val
;
int32_t
nVal
;
}
SIndexTerm
;
typedef
struct
SIndexTermQuery
{
SIndexTerm
*
field_value
;
EIndexQueryType
type
;
}
SIndexTermQuery
;
SIndexTerm
*
indexTermCreate
(
const
char
*
key
,
int32_t
nKey
,
const
char
*
val
,
int32_t
nVal
);
void
indexTermDestroy
(
SIndexTerm
*
p
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/index/src/index.c
浏览文件 @
9e74ea9e
...
...
@@ -38,46 +38,130 @@ SIndex *indexOpen(SIndexOpts *opts, const char *path) {
void
indexClose
(
SIndex
*
index
)
{
#ifdef USE_LUCENE
index_close
(
index
->
index
);
index
->
index
=
NULL
;
#endif
free
(
index
);
return
;
}
#ifdef USE_LUCENE
#endif
int
indexPut
(
SIndex
*
index
,
SArray
*
field_vals
,
int
uid
)
{
#ifdef USE_LUCENE
index_document_t
*
doc
=
index_document_create
();
char
buf
[
16
]
=
{
0
};
sprintf
(
buf
,
"%d"
,
uid
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
field_vals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
field_vals
,
i
);
index_document_add
(
doc
,
(
const
char
*
)(
p
->
key
),
p
->
nKey
,
(
const
char
*
)(
p
->
val
),
p
->
nVal
,
1
);
}
index_document_add
(
doc
,
NULL
,
0
,
buf
,
strlen
(
buf
),
0
);
index_put
(
index
->
index
,
doc
);
index_document_destroy
(
doc
);
#endif
return
1
;
}
int
indexSearch
(
SIndex
*
index
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
int
indexSearch
(
SIndex
*
index
,
SIndexMultiTermQuery
*
multiQuerys
,
SArray
*
result
)
{
#ifdef USE_LUCENE
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
multiQuerys
->
query
);
i
++
)
{
SIndexTermQuery
*
p
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SIndexTerm
*
term
=
p
->
field_value
;
EIndexQueryType
qType
=
p
->
type
;
int
*
tResult
=
NULL
;
int32_t
tsz
=
0
;
index_search
(
index
->
index
,
term
->
key
,
term
->
nKey
,
term
->
val
,
term
->
nVal
,
qType
,
&
tResult
,
&
tsz
);
for
(
int
i
=
0
;
i
<
tsz
;
i
++
)
{
taosArrayPush
(
result
,
&
(
tResult
[
i
]));
}
}
#endif
return
1
;
}
int
indexDelete
(
SIndex
*
index
,
SIndexTermQuery
*
query
)
{
int
indexDelete
(
SIndex
*
index
,
SIndex
Multi
TermQuery
*
query
)
{
return
1
;
}
int
indexRebuild
(
SIndex
*
index
,
SIndexOpts
*
opts
);
SIndexOpts
*
indexOptsCreate
()
{
return
NULL
;
#ifdef USE_LUCENE
#endif
return
NULL
;
}
void
indexOptsDestroy
(
SIndexOpts
*
opts
)
{
#ifdef USE_LUCENE
#endif
}
/*
* @param: oper
*
*/
SIndexTermQuery
*
indexTermQueryCreate
(
EIndexOperatorType
oper
)
{
return
NULL
;
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
opera
)
{
SIndexMultiTermQuery
*
p
=
(
SIndexMultiTermQuery
*
)
malloc
(
sizeof
(
SIndexMultiTermQuery
));
if
(
p
==
NULL
)
{
return
NULL
;
}
p
->
opera
=
opera
;
p
->
query
=
taosArrayInit
(
1
,
sizeof
(
SIndexTermQuery
));
return
p
;
}
void
indexMultiTermQueryDestroy
(
SIndexMultiTermQuery
*
pQuery
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pQuery
->
query
);
i
++
)
{
SIndexTermQuery
*
p
=
(
SIndexTermQuery
*
)
taosArrayGet
(
pQuery
->
query
,
i
);
indexTermDestroy
(
p
->
field_value
);
}
taosArrayDestroy
(
pQuery
->
query
);
free
(
pQuery
);
};
int
indexMultiTermQueryAdd
(
SIndexMultiTermQuery
*
pQuery
,
const
char
*
field
,
int32_t
nFields
,
const
char
*
value
,
int32_t
nValue
,
EIndexQueryType
type
){
SIndexTerm
*
t
=
indexTermCreate
(
field
,
nFields
,
value
,
nValue
);
if
(
t
==
NULL
)
{
return
-
1
;}
SIndexTermQuery
q
=
{.
type
=
type
,
.
field_value
=
t
};
taosArrayPush
(
pQuery
->
query
,
&
q
);
return
0
;
}
void
indexTermQueryDestroy
(
SIndexTermQuery
*
pQuery
)
{
SIndexTerm
*
indexTermCreate
(
const
char
*
key
,
int32_t
nKey
,
const
char
*
val
,
int32_t
nVal
)
{
SIndexTerm
*
t
=
(
SIndexTerm
*
)
malloc
(
sizeof
(
SIndexTerm
));
t
->
key
=
(
char
*
)
calloc
(
nKey
+
1
,
1
);
memcpy
(
t
->
key
,
key
,
nKey
);
t
->
nKey
=
nKey
;
t
->
val
=
(
char
*
)
calloc
(
nVal
+
1
,
1
);
memcpy
(
t
->
val
,
val
,
nVal
);
t
->
nVal
=
nVal
;
return
t
;
}
int
indexTermQueryAdd
(
SIndexTermQuery
*
pQuery
,
const
char
*
field
,
int32_t
nFields
,
const
char
*
value
,
int32_t
nValue
,
EIndexQueryType
type
){
return
1
;
void
indexTermDestroy
(
SIndexTerm
*
p
)
{
free
(
p
->
key
);
free
(
p
->
val
);
free
(
p
);
}
SArray
*
indexMultiTermCreate
()
{
return
taosArrayInit
(
4
,
sizeof
(
SIndexTerm
*
));
}
int
indexMultiTermAdd
(
SArray
*
array
,
const
char
*
field
,
int32_t
nField
,
const
char
*
val
,
int32_t
nVal
)
{
SIndexTerm
*
term
=
indexTermCreate
(
field
,
nField
,
val
,
nVal
);
if
(
term
==
NULL
)
{
return
-
1
;
}
taosArrayPush
(
array
,
&
term
);
return
0
;
}
void
indexMultiTermDestroy
(
SArray
*
array
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
array
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
array
,
i
);
indexTermDestroy
(
p
);
}
taosArrayDestroy
(
array
);
}
void
indexInit
()
{
//do nothing
}
source/libs/index/test/indexTests.cpp
浏览文件 @
9e74ea9e
...
...
@@ -2,14 +2,42 @@
#include <string>
#include <iostream>
#include "index.h"
#include "indexInt.h"
TEST
(
IndexTest
,
index_create_test
)
{
SIndexOpts
*
opts
=
indexOptsCreate
();
SIndex
*
index
=
indexOpen
(
opts
,
"./"
);
SIndex
*
index
=
indexOpen
(
opts
,
"./
test
"
);
if
(
index
==
NULL
)
{
std
::
cout
<<
"index open failed"
<<
std
::
endl
;
}
SArray
*
terms
=
indexMultiTermCreate
();
indexMultiTermAdd
(
terms
,
"tag1"
,
strlen
(
"tag1"
),
"field"
,
strlen
(
"field"
));
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
indexPut
(
index
,
terms
,
i
);
}
indexMultiTermDestroy
(
terms
);
// query
SIndexMultiTermQuery
*
multiQuery
=
indexMultiTermQueryCreate
(
MUST
);
indexMultiTermQueryAdd
(
multiQuery
,
"tag1"
,
strlen
(
"tag1"
),
"field"
,
strlen
(
"field"
),
QUERY_PREFIX
);
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
;
}
indexMultiTermQueryDestroy
(
multiQuery
);
indexOptsDestroy
(
opts
);
indexClose
(
index
);
//
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录