Example #1
0
        /// <summary>
        /// This method will create a full-text index on a table with an associated stoplist
        /// </summary>
        public static void CreateFullTextIndex()
        {
            Console.WriteLine("Running CreateFullTextIndex Sample...");

            try
            {
                Server server = new Server(".");
                server.ConnectionContext.Connect();

                Console.WriteLine("Connected to '{0}' server", server.Name);

                Database db = new Database(server, "iFTSSampleDB2");
                db.Create();

                Console.WriteLine("Database '{0}' created", db.Name);

                // Create a default full-text catalog for the database
                FullTextCatalog ftcat = new FullTextCatalog(db, "ftcatalog");
                ftcat.IsDefault = true;
                ftcat.Create();

                Console.WriteLine("FullTextCatalog '{0}' created", ftcat.Name);

                // Add 2 columns to the table
                Table tab = new Table(db, "tab");
                tab.Columns.Add(new Column(tab, "col_fti", DataType.NVarChar(1000)));
                Column col = new Column(tab, "col_unique", DataType.Int);
                col.Nullable = false;
                tab.Columns.Add(col);

                // Create a table with a unique index on it
                Index idxUnique = new Index(tab, "tab_unique_idx");
                idxUnique.IndexKeyType = IndexKeyType.DriUniqueKey;
                idxUnique.IndexedColumns.Add(new IndexedColumn(idxUnique, col.Name));
                tab.Indexes.Add(idxUnique);
                tab.Create();

                Console.WriteLine("Table '{0}' created", tab.Name);

                // Add a column to the full-text index and associate it with a unique index
                FullTextIndex fti = new FullTextIndex(tab);
                fti.IndexedColumns.Add(new FullTextIndexColumn(fti, "col_fti"));
                fti.UniqueIndexName = idxUnique.Name;

                string stopword = "goodbye";
                string language = "English";

                // Create an empty full-text stoplist
                FullTextStopList stoplist = new FullTextStopList(db, "sampleStoplist");
                stoplist.Create();

                Console.WriteLine("FullTextStoplist '{0}' created", stoplist.Name);

                // Add a stopword to the full-text stoplist
                stoplist.AddStopWord(stopword, language);
                Console.WriteLine("Stopword '{0}' added to Stoplist '{1}'", stopword, stoplist.Name);

                fti.StopListName = "sampleStoplist";

                // Create the full-text index and associate the full-text stoplist with it
                fti.Create();

                Console.WriteLine("FullTextIndex on Table '{0}' created", tab.Name);

                fti.Drop();
                Console.WriteLine("FullTextIndex on Table '{0}' dropped", tab.Name);

                ftcat.Drop();
                Console.WriteLine("FullTextCatalog '{0}' dropped", ftcat.Name);

                tab.Drop();
                Console.WriteLine("Table '{0}' created", tab.Name);

                db.Drop();
                Console.WriteLine("Database '{0}' dropped", db.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine();
            }
        }
Example #2
0
        /// <summary>
        /// This method will create a full-text index on a table with an associated stoplist
        /// </summary>
        public static void CreateFullTextIndex()
        {
            Console.WriteLine("Running CreateFullTextIndex Sample..."); 

            try
            {
                Server server = new Server(".");
                server.ConnectionContext.Connect();

                Console.WriteLine("Connected to '{0}' server", server.Name);

                Database db = new Database(server, "iFTSSampleDB2");
                db.Create();

                Console.WriteLine("Database '{0}' created", db.Name);

                // Create a default full-text catalog for the database
                FullTextCatalog ftcat = new FullTextCatalog(db, "ftcatalog");
                ftcat.IsDefault = true;
                ftcat.Create();

                Console.WriteLine("FullTextCatalog '{0}' created", ftcat.Name);

                // Add 2 columns to the table
                Table tab = new Table(db, "tab");
                tab.Columns.Add(new Column(tab, "col_fti", DataType.NVarChar(1000)));
                Column col = new Column(tab, "col_unique", DataType.Int);
                col.Nullable = false;
                tab.Columns.Add(col);

                // Create a table with a unique index on it
                Index idxUnique = new Index(tab, "tab_unique_idx");
                idxUnique.IndexKeyType = IndexKeyType.DriUniqueKey;
                idxUnique.IndexedColumns.Add(new IndexedColumn(idxUnique, col.Name));
                tab.Indexes.Add(idxUnique);
                tab.Create();

                Console.WriteLine("Table '{0}' created", tab.Name);

                // Add a column to the full-text index and associate it with a unique index
                FullTextIndex fti = new FullTextIndex(tab);
                fti.IndexedColumns.Add(new FullTextIndexColumn(fti, "col_fti"));
                fti.UniqueIndexName = idxUnique.Name;

                string stopword = "goodbye";
                string language = "English";

                // Create an empty full-text stoplist
                FullTextStopList stoplist = new FullTextStopList(db, "sampleStoplist");
                stoplist.Create();

                Console.WriteLine("FullTextStoplist '{0}' created", stoplist.Name);

                // Add a stopword to the full-text stoplist
                stoplist.AddStopWord(stopword, language);
                Console.WriteLine("Stopword '{0}' added to Stoplist '{1}'", stopword, stoplist.Name);

                fti.StopListName = "sampleStoplist";

                // Create the full-text index and associate the full-text stoplist with it
                fti.Create();

                Console.WriteLine("FullTextIndex on Table '{0}' created", tab.Name);

                fti.Drop();
                Console.WriteLine("FullTextIndex on Table '{0}' dropped", tab.Name);
                 
                ftcat.Drop();
                Console.WriteLine("FullTextCatalog '{0}' dropped", ftcat.Name);

                tab.Drop();
                Console.WriteLine("Table '{0}' created", tab.Name);

                db.Drop();
                Console.WriteLine("Database '{0}' dropped", db.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine();
            }
        }