@@ -11,6 +11,7 @@ use crate::datavalue::DataValue;
11
11
use crate :: error:: StamError ;
12
12
use crate :: json:: ToJson ;
13
13
use crate :: substore:: { AnnotationSubStore , AnnotationSubStoreHandle } ;
14
+ use crate :: text:: Text ;
14
15
use crate :: textselection:: TextSelectionOperator ;
15
16
use crate :: Offset ;
16
17
use crate :: { api:: * , Configurable } ;
@@ -1866,7 +1867,24 @@ pub enum QueryResultItem<'store> {
1866
1867
AnnotationSubStore ( ResultItem < ' store , AnnotationSubStore > ) ,
1867
1868
}
1868
1869
1869
- impl QueryResultItem < ' _ > {
1870
+ impl < ' store > QueryResultItem < ' store > {
1871
+ pub fn text ( & self , delimiter : Option < & str > ) -> Result < Cow < ' store , str > , StamError > {
1872
+ match self {
1873
+ Self :: Annotation ( annotation) => {
1874
+ if let Some ( text) = annotation. text_simple ( ) {
1875
+ Ok ( Cow :: Borrowed ( text) )
1876
+ } else if let Some ( delimiter) = delimiter {
1877
+ Ok ( Cow :: Owned ( annotation. text_join ( delimiter) ) )
1878
+ } else {
1879
+ Err ( StamError :: NoText ( "No singular text for this annotation" ) )
1880
+ }
1881
+ }
1882
+ Self :: TextResource ( resource) => Ok ( Cow :: Borrowed ( resource. text ( ) ) ) ,
1883
+ Self :: TextSelection ( textselection) => Ok ( Cow :: Borrowed ( textselection. text ( ) ) ) ,
1884
+ _ => Err ( StamError :: NoText ( "No text for this item" ) ) ,
1885
+ }
1886
+ }
1887
+
1870
1888
pub fn to_json_string ( & self ) -> Result < String , StamError > {
1871
1889
match self {
1872
1890
Self :: Annotation ( annotation) => annotation. as_ref ( ) . to_json_string ( annotation. store ( ) ) ,
0 commit comments