跳到主要内容

FindNeighborsOptions<T, U, V>

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

图邻居查询选项(基础)

Type Parameters

Type ParameterDefault type
T extends EntityTypeEntityType
UGraphWhere<T>
V extends EdgeFilterOptionsEdgeFilterOptions

Properties

direction?

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

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

查询方向

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

Default

'both'

edgeWhere?

optional edgeWhere?: V;

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

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

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:141

起始节点 ID


level?

optional level?: number;

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

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

  • 0: 不查询任何邻居(findNeighbors 返回空数组,countNeighbors 返回 0)
  • 1: 仅直接邻居(1跳)
  • 2: 1跳 + 2跳邻居
  • 3: 1跳 + 2跳 + 3跳邻居

Default

1

Minimum

0

Maximum

100

Remarks

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

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:189

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