public static void BuildIndexes()
        {
            SqlConnection connection = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=toodledo;Integrated Security=SSPI;");
            SqlCommand    cmd        = new SqlCommand();

            //SqlDataReader reader;
            cmd.CommandText = "SELECT id, title, body FROM dbo.Content";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = connection;
            connection.Open();
            var reader = cmd.ExecuteReader();

            var dir = FSDirectory.Open(new System.IO.DirectoryInfo(@"C:\lucene"));

            Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
            Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(dir, analyzer, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED);
            writer.DeleteAll();

            while (reader.Read())
            {
                var id    = reader.GetFieldValue <int>(0);
                var title = reader.GetFieldValue <string>(1);
                var body  = reader.GetFieldValue <string>(2);
                writer.AddDocument(create_doc(id, title, body));
            }
            connection.Close();

            writer.Optimize();
            writer.Commit();
        }
Beispiel #2
0
        /// <summary>
        /// Clear out all documents from the index.
        /// </summary>
        public void Clear()
        {
            if (!IsWriteMode)
            {
                throw new Exception("You can't modify the index when not in write mode.");
            }

            _writer.DeleteAll();
        }