@@ -82,6 +82,8 @@ function BuildDatabase($DBDataSources, $schema, $do_force) {
8282 $ this ->sqlrun (dirname (__FILE__ )."/full-text-indexes.sql " , false , false );
8383 $ this ->sqlrun (dirname (__FILE__ )."/search-queries.sql " );
8484
85+ $ this ->waitForFullTextIndexing ();
86+
8587 // Run scripts for all views automatically
8688 $ scripts = glob (__DIR__ . '/v_*.sql ' );
8789 foreach ($ scripts as $ script ) {
@@ -107,6 +109,41 @@ function BuildDatabase($DBDataSources, $schema, $do_force) {
107109 return true ;
108110 }
109111
112+ private function waitForFullTextIndexing () {
113+ $ dci = new DatabaseConnectionInfo ();
114+
115+ try {
116+ $ mssql = new PDO (
117+ $ dci ->getConnectionString (),
118+ $ this ->schema ,
119+ $ dci ->getPassword (),
120+ [ "CharacterSet " => "UTF-8 " ]);
121+ $ mssql ->setAttribute ( PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
122+ $ mssql ->setAttribute ( PDO ::SQLSRV_ATTR_DIRECT_QUERY , true );
123+ $ mssql ->setAttribute ( PDO ::SQLSRV_ATTR_ENCODING , PDO ::SQLSRV_ENCODING_UTF8 );
124+ }
125+ catch ( PDOException $ e ) {
126+ die ( "Error connecting to SQL Server: " . $ e ->getMessage () );
127+ }
128+
129+ $ stmt = $ mssql ->prepare ("select * from sys.fulltext_indexes where has_crawl_completed=0 " );
130+ if (!$ stmt ->execute ()) {
131+ die ( "Error checking Full Text Indexing status " );
132+ }
133+ $ data = $ stmt ->fetchAll ();
134+
135+ while (count ($ data ) > 0 ) {
136+ echo "Full Text Indexing not complete, waiting 3 seconds \n" ;
137+ sleep (3 );
138+ if (!$ stmt ->execute ()) {
139+ die ( "Error checking Full Text Indexing status " );
140+ }
141+ $ data = $ stmt ->fetchAll ();
142+ }
143+
144+ echo "Full Text Indexing is now complete \n" ;
145+ }
146+
110147 function buildDBDataSources ($ data_path , DBDataSources $ DBDataSources ) {
111148 $ sql = '' ;
112149
0 commit comments