跳到主要内容

FindNeighborsOptions<T, U, V>

Defined in: rxdb-plugin-graph/src/graph-repository.interface.ts:105

图邻居查询选项(基础)

Type Parameters

Type ParameterDefault type
T extends EntityTypeany
URuleGroup<InstanceType<T>>
VEdgeFilterOptions

Properties

direction?

optional direction: "in" | "out" | "both";

Defined in: rxdb-plugin-graph/src/graph-repository.interface.ts:122

查询方向

  • 'in': 入边邻居(指向当前节点的节点)
  • 'out': 出边邻居(从当前节点指出的节点)
  • 'both': 双向邻居(默认)

Default

'both'

edgeWhere?

optional edgeWhere: V;

Defined in: rxdb-plugin-graph/src/graph-repository.interface.ts:175

边过滤条件 应用于连接边的属性(权重、自定义属性等)

Example

// 只查询高权重的邻居(需要启用 weight)
edgeWhere: { weight: { min: 5 } }

// 只查询特定类别的关系
edgeWhere: { properties: { category: 'business' } }

entityId

entityId: EntityStaticType<T, "idType">;

Defined in: rxdb-plugin-graph/src/graph-repository.interface.ts:113

起始节点 ID


level?

optional level: number;

Defined in: rxdb-plugin-graph/src/graph-repository.interface.ts:154

最大跳数(不包含起始节点)

  • 1: 仅直接邻居(1跳)
  • 2: 1跳 + 2跳邻居
  • 3: 1跳 + 2跳 + 3跳邻居

Default

1

Minimum

1

Maximum

10

Remarks

  • 返回结果不包含起始节点本身
  • 当 level < 1 时,会被规范化为 1
  • 当 level > 10 时,会被限制为 10(防止性能问题)
  • 结果自动去重(同一节点通过不同路径到达时只返回最短路径)

Example

// 查询直接好友(1跳)
findNeighbors({ entityId: 'user1', level: 1 })
// 返回: [{ node: friend1, edge: {...}, level: 1 }, ...]

// 查询好友的好友(2度人脉,1跳+2跳)
findNeighbors({ entityId: 'user1', level: 2 })
// 返回: [
// { node: friend1, edge: {...}, level: 1 }, // 1跳
// { node: friendOfFriend, edge: {...}, level: 2 } // 2跳
// ]

where?

optional where: U;

Defined in: rxdb-plugin-graph/src/graph-repository.interface.ts:160

节点过滤条件 应用于邻居节点的属性