Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
551cfd5c
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
551cfd5c
编写于
10月 23, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add index test example
上级
9e74ea9e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
20 deletion
+55
-20
include/libs/index/index.h
include/libs/index/index.h
+5
-6
source/libs/index/src/index.c
source/libs/index/src/index.c
+30
-9
source/libs/index/test/indexTests.cpp
source/libs/index/test/indexTests.cpp
+20
-5
未找到文件。
include/libs/index/index.h
浏览文件 @
551cfd5c
...
...
@@ -27,12 +27,9 @@ 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
enum
{
QUERY_TERM
=
0
,
QUERY_PREFIX
=
1
,
QUERY_SUFFIX
=
2
,
QUERY_REGEX
=
3
}
EIndexQueryType
;
/*
* @param: oper
*
...
...
@@ -40,7 +37,6 @@ typedef enum { QUERY_POINT = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2,QUERY_REGEX
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:
...
...
@@ -51,7 +47,10 @@ 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
);
/*
* @param
* @param
*/
SIndexMultiTerm
*
indexMultiTermCreate
();
int
indexMultiTermAdd
(
SIndexMultiTerm
*
terms
,
const
char
*
field
,
int32_t
nFields
,
const
char
*
value
,
int32_t
nValue
);
void
indexMultiTermDestroy
(
SIndexMultiTerm
*
terms
);
...
...
source/libs/index/src/index.c
浏览文件 @
551cfd5c
...
...
@@ -68,18 +68,39 @@ int indexPut(SIndex *index, SArray* field_vals, int uid) {
}
int
indexSearch
(
SIndex
*
index
,
SIndexMultiTermQuery
*
multiQuerys
,
SArray
*
result
)
{
#ifdef USE_LUCENE
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
multiQuerys
->
query
);
i
++
)
{
EIndexOperatorType
opera
=
multiQuerys
->
opera
;
int
nQuery
=
taosArrayGetSize
(
multiQuerys
->
query
);
char
**
fields
=
malloc
(
sizeof
(
char
*
)
*
nQuery
);
char
**
keys
=
malloc
(
sizeof
(
char
*
)
*
nQuery
);
int
*
types
=
malloc
(
sizeof
(
int
)
*
nQuery
);
for
(
int
i
=
0
;
i
<
nQuery
;
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
]));
}
fields
[
i
]
=
calloc
(
1
,
term
->
nKey
+
1
);
keys
[
i
]
=
calloc
(
1
,
term
->
nVal
+
1
);
memcpy
(
fields
[
i
],
term
->
key
,
term
->
nKey
);
memcpy
(
keys
[
i
],
term
->
val
,
term
->
nVal
);
types
[
i
]
=
(
int
)(
p
->
type
);
}
int
*
tResult
=
NULL
;
int
tsz
=
0
;
index_multi_search
(
index
->
index
,
(
const
char
**
)
fields
,
(
const
char
**
)
keys
,
types
,
nQuery
,
opera
,
&
tResult
,
&
tsz
);
for
(
int
i
=
0
;
i
<
tsz
;
i
++
)
{
taosArrayPush
(
result
,
&
tResult
[
i
]);
}
for
(
int
i
=
0
;
i
<
nQuery
;
i
++
)
{
free
(
fields
[
i
]);
free
(
keys
[
i
]);
}
free
(
fields
);
free
(
keys
);
free
(
types
);
#endif
return
1
;
}
...
...
source/libs/index/test/indexTests.cpp
浏览文件 @
551cfd5c
...
...
@@ -15,17 +15,32 @@ TEST(IndexTest, index_create_test) {
}
SArray
*
terms
=
indexMultiTermCreate
();
indexMultiTermAdd
(
terms
,
"tag1"
,
strlen
(
"tag1"
),
"field"
,
strlen
(
"field"
));
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
indexPut
(
index
,
terms
,
i
);
// 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
);
}
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
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录