22
33namespace ScoutElastic ;
44
5+ use Illuminate \Database \Eloquent \SoftDeletes ;
56use Laravel \Scout \Searchable as ScoutSearchable ;
67use ScoutElastic \Builders \FilterBuilder ;
78use ScoutElastic \Builders \SearchBuilder ;
@@ -47,7 +48,13 @@ public function getIndexConfigurator()
4748
4849 public function getMapping ()
4950 {
50- return isset ($ this ->mapping ) ? $ this ->mapping : [];
51+ $ mapping = $ this ->mapping ?? [];
52+
53+ if ($ this ->usesSoftDelete () && config ('scout.soft_delete ' , false )) {
54+ array_set ($ mapping , 'properties.__soft_deleted ' , ['type ' => 'integer ' ]);
55+ }
56+
57+ return $ mapping ;
5158 }
5259
5360 public function getSearchRules ()
@@ -57,10 +64,12 @@ public function getSearchRules()
5764
5865 public static function search ($ query , $ callback = null )
5966 {
67+ $ softDelete = config ('scout.soft_delete ' , false );
68+
6069 if ($ query == '* ' ) {
61- return new FilterBuilder (new static , $ callback );
70+ return new FilterBuilder (new static , $ callback, $ softDelete );
6271 } else {
63- return new SearchBuilder (new static , $ query , $ callback );
72+ return new SearchBuilder (new static , $ query , $ callback, $ softDelete );
6473 }
6574 }
6675
@@ -71,4 +80,12 @@ public static function searchRaw($query)
7180 return $ model ->searchableUsing ()
7281 ->searchRaw ($ model , $ query );
7382 }
83+
84+ /**
85+ * @return bool
86+ */
87+ public function usesSoftDelete ()
88+ {
89+ return in_array (SoftDeletes::class, class_uses_recursive ($ this ));
90+ }
7491}
0 commit comments