File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7676 );
7777 echo "--------Create Collection------- \n" ;
7878 echo "\n" ;
79+ echo "--------Check if Collection exists------- \n" ;
80+ print_r ($ client ->collections ['books ' ]->exists ());
81+ echo "--------Check if Collection exists------- \n" ;
82+ echo "\n" ;
7983 echo "--------Retrieve Collection------- \n" ;
8084 print_r ($ client ->collections ['books ' ]->retrieve ());
8185 echo "--------Retrieve Collection------- \n" ;
Original file line number Diff line number Diff line change 1414 */
1515class Collection
1616{
17-
1817 /**
1918 * @var string
2019 */
@@ -40,10 +39,15 @@ class Collection
4039 */
4140 public Synonyms $ synonyms ;
4241
42+ /**
43+ * @var bool|null
44+ */
45+ private ?bool $ exists = null ;
46+
4347 /**
4448 * Collection constructor.
4549 *
46- * @param string $name
50+ * @param string $name
4751 * @param ApiCall $apiCall
4852 */
4953 public function __construct (string $ name , ApiCall $ apiCall )
@@ -87,6 +91,23 @@ public function getSynonyms(): Synonyms
8791 return $ this ->synonyms ;
8892 }
8993
94+ /**
95+ * @return bool|null
96+ */
97+ public function exists (): ?bool
98+ {
99+ if ($ this ->exists === null ) {
100+ try {
101+ $ this ->retrieve ();
102+ $ this ->exists = true ;
103+ } catch (TypesenseClientError | HttpClientException $ e ) {
104+ $ this ->exists = false ;
105+ }
106+ }
107+
108+ return $ this ->exists ;
109+ }
110+
90111 /**
91112 * @return array
92113 * @throws TypesenseClientError|HttpClientException
You can’t perform that action at this time.
0 commit comments