Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shortestOptionalPath() with configurable Edge types and directions to find shortest paths by srcId and dstId #303

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,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 @@ -519,6 +519,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 @@ -287,7 +287,7 @@


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

Expand Down Expand Up @@ -385,6 +385,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>
Loading