dosubot[bot] commented on issue #670:
URL:
https://github.com/apache/incubator-hugegraph-toolchain/issues/670#issuecomment-2938287488
<!-- Answer -->
经过对 HugeGraph AVA 客户端 Traverser API 的 K-neighbor API 相关源码和测试用例的调研,目前
K-neighbor API 并不直接支持“顶点属性模糊匹配”或“以逗号分割进行模糊匹配”功能。K-neighbor API 支持通过 property
进行精确或谓词(如 P.gt、P.lte)过滤,但没有内置模糊匹配、正则、分词等能力,也没有相关的官方文档或案例说明如何在 K-neighbor API
请求参数中实现此类需求。
如果你的需求是“属性值为逗号分隔的字符串,模糊匹配其中某一项”,可以考虑以下思路:
1. **Gremlin 查询支持**
HugeGraph 支持在 Gremlin 查询中使用 CONTAINS 或 TEXT_CONTAINS 操作符对 SET/LIST
类型属性进行包含匹配(需为该属性建立 Search 索引)。例如:
```java
g.V().hasLabel("org").has("alias", CONTAINS, "广州软件").limit(10)
g.V().hasLabel("org").has("alias", TEXT_CONTAINS, "广州软件").limit(10)
```
或者:
```java
g.V().hasLabel('org').has('alias', ConditionP.contains('广州软件'))
```
参考:[CONTAINS/TEXT_CONTAINS
用法说明](https://github.com/apache/incubator-hugegraph/issues/2753)
2. **K-neighbor API 间接实现**
K-neighbor API 的 Steps 支持传入 properties 进行过滤,但仅支持精确值或 P.xxx 谓词,不支持模糊匹配。例如:
```java
Map<String, Object> properties = new HashMap<>();
properties.put("name", "P.eq(\"张三\")"); // 仅支持精确或范围,不支持模糊
builder.steps().direction(Direction.BOTH)
.edgeSteps(new Steps.StepEntity("knows", properties));
```
如果你希望通过 K-neighbor API 实现模糊匹配,建议先用 Gremlin 查询筛选出目标顶点,再以这些顶点作为 source 执行
K-neighbor 遍历。
3. **以逗号分割的字符串属性**
如果属性是字符串(如 "a,b,c"),HugeGraph 不支持直接用 CONTAINS 匹配子串,只有 Search 索引的
TEXT_CONTAINS 能实现部分分词匹配,但效果依赖于分词器。否则只能在业务侧先查出所有匹配的顶点,再用 K-neighbor API 遍历。
**总结**:
K-neighbor API 本身不支持模糊匹配或逗号分割的属性项匹配。推荐用 Gremlin + Search 索引先筛选,再用 K-neighbor
API 做遍历。如果有具体的属性结构和目标匹配规则,可以补充说明,便于给出更具体的实现建议。
<!-- Dosu Comment Footer -->
*To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/e3c2d716-f772-43ea-a58f-3b69a2fad8c1?feedback_type=other)</sup> [](https://go.dosu.dev/discord-bot) [!
[Share on
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/incubator-hugegraph-toolchain/issues/670)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]