Skip to content

Commit

Permalink
Merge pull request #303 from n3A87/0527
Browse files Browse the repository at this point in the history
feat: shortestOptionalPath() with configurable Edge types and directions to find shortest paths by srcId and dstId
  • Loading branch information
knqiufan authored Jun 10, 2024
2 parents c991bd7 + 1a2d664 commit 5bd87a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,13 @@ public void shortestPath() {
List<NgPath<String>> ngPaths = repository.shortestPath("吴小极", "刘小洲");
System.out.println(JSON.toJSONString(ngPaths));
}

@Test
public void shortestOptionalPath() {
List<NgPath<String>> ngPaths = repository.shortestOptionalPath("吴小极", "刘小洲",
Arrays.asList("like"),"BIDIRECT");
System.out.println(JSON.toJSONString(ngPaths));
}
// endregion

@Test
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,25 @@ default List<NgPath<I>> shortestPath(@Param("srcId") I srcId, @Param("dstId") I
return (List<NgPath<I>>) MapperProxy.invoke(classModel, methodModel, srcId, dstId);
}

/**
* 查找指定起始点和目的点之间的最短路径
* @param srcId 起始点id
* @param dstId 目的点id
* @param edgeTypeList Edge type 列表
* @param direction REVERSELY表示反向,BIDIRECT表示双向
* @return 起始点和目的点之间的最短路径
*/
default List<NgPath<I>> shortestOptionalPath(@Param("srcId") I srcId,@Param("dstId") I dstId,
@Param("edgeTypeList") List<String> edgeTypeList,
@Param("direction") String direction
) {
MethodModel methodModel = getMethodModel();
methodModel.setReturnType(Collection.class);
methodModel.setResultType(NgPath.class);
ClassModel classModel = getClassModel(this.getClass());
return (List<NgPath<I>>) MapperProxy.invoke(classModel, methodModel,
srcId, dstId,edgeTypeList,direction);
}

// endregion

Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/NebulaDaoBasic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@


<delete id="deleteByIdBatch">
DELETE VERTEX ${ ng.join( p0, ", ", "ng.valueFmt" ) }
DELETE VERTEX ${ ng.join( p0, ", ", "ng.valueFmt" ) }
</delete>
<!--endregion-->

Expand Down Expand Up @@ -415,6 +415,15 @@
@var dstId = ng.valueFmt( dstId );
FIND SHORTEST PATH FROM ${ srcId } TO ${ dstId } OVER * YIELD path AS p
</select>

<select id="shortestOptionalPath" resultType="org.nebula.contrib.ngbatis.models.data.NgPath">
@var srcId = ng.valueFmt( srcId );
@var dstId = ng.valueFmt( dstId );

FIND SHORTEST PATH FROM ${ srcId } TO ${ dstId }
OVER ${ isNotEmpty(edgeTypeList) ? ng.join(edgeTypeList) : '*' } ${ isNotEmpty( direction ) ? direction : '' }
YIELD path AS p;
</select>
<!--endregion-->

</mapper>

0 comments on commit 5bd87a2

Please sign in to comment.