@@ -170,6 +170,32 @@ fn eq_pred(field: &str, value: &str) -> Predicate {
170170 } )
171171}
172172
173+ fn is_wikidata_entity_like_id ( value : & str ) -> bool {
174+ let mut chars = value. chars ( ) ;
175+ matches ! ( chars. next( ) , Some ( 'Q' | 'P' ) ) && chars. all ( |c| c. is_ascii_digit ( ) ) && value. len ( ) > 1
176+ }
177+
178+ fn path_endpoint ( schema : & str , value : & str ) -> PathEndpoint {
179+ if is_wikidata_entity_like_id ( value) {
180+ PathEndpoint {
181+ schema : schema. to_string ( ) ,
182+ match_clause : Some ( eq_pred ( "id" , value) ) ,
183+ search : None ,
184+ }
185+ } else {
186+ PathEndpoint {
187+ schema : schema. to_string ( ) ,
188+ match_clause : None ,
189+ search : Some ( SearchClause {
190+ field : "label" . to_string ( ) ,
191+ text : value. to_string ( ) ,
192+ top_k : Some ( 1 ) ,
193+ mode : Some ( morpheus:: dsl:: query:: json:: SearchMode :: Fulltext ) ,
194+ } ) ,
195+ }
196+ }
197+ }
198+
173199fn column_value < ' a > (
174200 row : & ' a morpheus:: dsl:: query:: json:: QueryDslRow ,
175201 name : & str ,
@@ -611,16 +637,8 @@ async fn run_query_command(
611637 } => {
612638 let req = ShortestPathRequest {
613639 database : None ,
614- from : PathEndpoint {
615- schema : "wikidata_entity" . to_string ( ) ,
616- match_clause : Some ( eq_pred ( "id" , & from_id) ) ,
617- search : None ,
618- } ,
619- to : PathEndpoint {
620- schema : "wikidata_entity" . to_string ( ) ,
621- match_clause : Some ( eq_pred ( "id" , & to_id) ) ,
622- search : None ,
623- } ,
640+ from : path_endpoint ( "wikidata_entity" , & from_id) ,
641+ to : path_endpoint ( "wikidata_entity" , & to_id) ,
624642 via : PathViaClause {
625643 edges : vec ! [ "wikidata_link" . to_string( ) ] ,
626644 direction : Some ( TraverseDirection :: Undirected ) ,
@@ -654,16 +672,8 @@ async fn run_query_command(
654672 } => {
655673 let req = PathsRequest {
656674 database : None ,
657- from : PathEndpoint {
658- schema : "wikidata_entity" . to_string ( ) ,
659- match_clause : Some ( eq_pred ( "id" , & from_id) ) ,
660- search : None ,
661- } ,
662- to : PathEndpoint {
663- schema : "wikidata_entity" . to_string ( ) ,
664- match_clause : Some ( eq_pred ( "id" , & to_id) ) ,
665- search : None ,
666- } ,
675+ from : path_endpoint ( "wikidata_entity" , & from_id) ,
676+ to : path_endpoint ( "wikidata_entity" , & to_id) ,
667677 via : morpheus:: dsl:: graph:: json:: PathsViaClause {
668678 edges : vec ! [ "wikidata_link" . to_string( ) ] ,
669679 direction : Some ( TraverseDirection :: Undirected ) ,
0 commit comments