22
33namespace Ensi \LaravelElasticQuery \Suggesting \Request ;
44
5+ use Ensi \LaravelElasticQuery \Suggesting \Request \Concerns \WithSize ;
56use Webmozart \Assert \Assert ;
67
78class PhraseSuggester implements Suggester
89{
10+ use WithSize;
11+
912 // basic phrase suggest api parameters
1013 protected ?string $ text = null ;
1114 protected ?int $ gramSize = null ;
1215 protected ?float $ realWordErrorLikelihood = null ;
1316 protected ?float $ confidence = null ;
1417 protected ?float $ maxErrors = null ;
1518 protected ?string $ separator = null ;
16- protected ?int $ size = null ;
1719 protected ?string $ analyzer = null ;
1820 protected ?int $ shardSize = null ;
1921 protected ?string $ highlightPreTag = null ;
2022 protected ?string $ highlightPostTag = null ;
23+ protected array $ directGenerators = [];
2124
2225 public function __construct (protected string $ name , protected string $ field )
2326 {
@@ -44,9 +47,9 @@ public function toDSL(): array
4447 "pre_tag " => $ this ->highlightPreTag ,
4548 "post_tag " => $ this ->highlightPostTag ,
4649 ]) ?: null ,
50+ "direct_generator " => array_map (fn (DirectGenerator $ g ) => $ g ->toDSL (), $ this ->directGenerators ),
4751 // todo collate
4852 // todo smoothing models
49- // todo direct_generator
5053 ]),
5154 ];
5255 }
@@ -56,7 +59,7 @@ public function name(): string
5659 return $ this ->name ;
5760 }
5861
59- public function text (string $ text ): self
62+ public function text (string $ text ): static
6063 {
6164 Assert::stringNotEmpty (trim ($ text ));
6265
@@ -65,66 +68,66 @@ public function text(string $text): self
6568 return $ this ;
6669 }
6770
68- public function gramSize (int $ gramSize ): self
71+ public function gramSize (int $ gramSize ): static
6972 {
7073 $ this ->gramSize = $ gramSize ;
7174
7275 return $ this ;
7376 }
7477
75- public function realWordErrorLikelihood (float $ realWordErrorLikelihood ): self
78+ public function realWordErrorLikelihood (float $ realWordErrorLikelihood ): static
7679 {
7780 $ this ->realWordErrorLikelihood = $ realWordErrorLikelihood ;
7881
7982 return $ this ;
8083 }
8184
82- public function confidence (float $ confidence ): self
85+ public function confidence (float $ confidence ): static
8386 {
8487 $ this ->confidence = $ confidence ;
8588
8689 return $ this ;
8790 }
8891
89- public function maxErrors (float $ maxErrors ): self
92+ public function maxErrors (float $ maxErrors ): static
9093 {
9194 $ this ->maxErrors = $ maxErrors ;
9295
9396 return $ this ;
9497 }
9598
96- public function separator (string $ separator ): self
99+ public function separator (string $ separator ): static
97100 {
98101 $ this ->separator = $ separator ;
99102
100103 return $ this ;
101104 }
102105
103- public function size ( int $ size ): self
106+ public function analyzer ( string $ analyzer ): static
104107 {
105- $ this ->size = $ size ;
108+ $ this ->analyzer = $ analyzer ;
106109
107110 return $ this ;
108111 }
109112
110- public function analyzer ( string $ analyzer ): self
113+ public function shardSize ( int $ shardSize ): static
111114 {
112- $ this ->analyzer = $ analyzer ;
115+ $ this ->shardSize = $ shardSize ;
113116
114117 return $ this ;
115118 }
116119
117- public function shardSize ( int $ shardSize ): self
120+ public function highlight ( string $ highlightPreTag , string $ highlightPostTag ): static
118121 {
119- $ this ->shardSize = $ shardSize ;
122+ $ this ->highlightPreTag = $ highlightPreTag ;
123+ $ this ->highlightPostTag = $ highlightPostTag ;
120124
121125 return $ this ;
122126 }
123127
124- public function highlight ( string $ highlightPreTag , string $ highlightPostTag ): self
128+ public function addDirectGenerator ( DirectGenerator $ directGenerator ): static
125129 {
126- $ this ->highlightPreTag = $ highlightPreTag ;
127- $ this ->highlightPostTag = $ highlightPostTag ;
130+ $ this ->directGenerators [] = $ directGenerator ;
128131
129132 return $ this ;
130133 }
0 commit comments