dosubot[bot] commented on issue #2780: URL: https://github.com/apache/incubator-hugegraph/issues/2780#issuecomment-2921297349
<!-- Answer --> HugeGraph 对谓词 P.gt、P.lt、P.eq、P.neq、P.between、P.within 的支持,核心代码在 `TraversalUtil.java` 文件中实现,具体在 `parsePredicate` 方法里会将如 `P.gt(18)` 这样的字符串解析为 Gremlin 的谓词对象(P.eq, P.neq, P.lt, P.lte, P.gt, P.gte, P.between, P.within 等),并用于属性过滤。你可以在源码中看到如下实现: [TraversalUtil.java 相关代码片段](https://github.com/apache/incubator-hugegraph/blob/337dc86567834acd717a2240a79fef2815d4bb6f/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java): ```java switch (method) { case "eq": return P.eq(predicateNumber(value)); case "neq": return P.neq(predicateNumber(value)); case "lt": return P.lt(predicateNumber(value)); case "lte": return P.lte(predicateNumber(value)); case "gt": return P.gt(predicateNumber(value)); case "gte": return P.gte(predicateNumber(value)); case "between": Number[] params = predicateNumbers(value, 2); return P.between(params[0], params[1]); case "within": return P.within(predicateArgs(value)); // ... } ``` 这些谓词在 RESTful API 和 Java Client 里都支持。例如,RESTful 查询可以这样写: - `properties={"age":"P.gt(28)"}` - `properties={"score":"P.between(60,90)"}` - `properties={"role":"P.within('admin','user')"}` 详细用法和所有支持的谓词列表可参考官方文档:[Vertex API](https://github.com/apache/incubator-hugegraph-doc/blob/f8b8bddd6123c2cf809ab69bba8c267ed02a7d67/content/en/docs/clients/restful-api/vertex.md) 和 [Edge API](https://github.com/apache/incubator-hugegraph-doc/blob/f8b8bddd6123c2cf809ab69bba8c267ed02a7d67/content/en/docs/clients/restful-api/edge.md)。 如果你需要 Java Client 侧的用法,可以参考 [HugeGraph Java Client 文档](https://github.com/apache/incubator-hugegraph-doc/blob/f8b8bddd6123c2cf809ab69bba8c267ed02a7d67/content/en/docs/clients/hugegraph-client.md)。 如需进一步查看谓词如何转为底层 Condition,可以继续阅读 `TraversalUtil.java` 里的 `convCompare2UserpropRelation` 和 `convIn2Relation` 方法实现。 <!-- 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/40d918a9-3f5a-4a2d-9228-0f5532c24af5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/40d918a9-3f5a-4a2d-9228-0f5532c24af5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/40d918a9-3f5a-4a2d-9228-0f5532c24af5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/40d918a9-3f5a-4a2d-9228-0f5532c24af5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/40d918a9-3f5a-4a2d-9228-0f5532c24af5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/40d918a9-3f5a-4a2d-9228-0f5532c24af5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/40d918a9-3f5a-4a2d-9228-0f5532c24af5?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/issues/2780) -- 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]
