コード例 #1
0
        private void CreateIndexButton_Click(object sender, EventArgs e)
        {
            java.nio.file.Path idxPath = FileSystems.getDefault().getPath(IndexDir);
            FSDirectory        dir     = FSDirectory.Open(idxPath);

            JapaneseAnalyzer  analyzer = new JapaneseAnalyzer();
            IndexWriterConfig config   = new IndexWriterConfig(analyzer);
            IndexWriter       writer   = new IndexWriter(dir, config);

            string[] files = System.IO.Directory.GetFiles(this.TargetDirText.Text, "*.htm*", System.IO.SearchOption.AllDirectories);

            try {
                foreach (string file in files)
                {
                    string title, content, f;
                    title   = "";
                    content = "";
                    f       = file;
                    HTMLParse(ref title, ref content, ref f);

                    Field fldTitle   = new StringField("title", title, FieldStore.YES);
                    Field fldPlace   = new StringField("place", f, FieldStore.YES);
                    Field fldContent = new TextField("content", content, FieldStore.YES);

                    Document doc = new Document();
                    doc.Add(fldTitle);
                    doc.Add(fldPlace);
                    doc.Add(fldContent);
                    writer.AddDocument(doc);
                }
            } catch (System.IO.IOException ex) {
                System.Console.WriteLine(ex.ToString());
            }
            writer.Close();
        }
コード例 #2
0
        public static void CreateIndex()
        {
            try {
                java.nio.file.Path idxPath = FileSystems.getDefault().getPath(IndexDir);
                _dir        = FSDirectory.Open(idxPath);
                indexWriter = new IndexWriter(_dir, config);

                string[] files = System.IO.Directory.GetFiles(@"C:\Workspace\MyToolBox\Tool\FullTextSearchCCC\kitei", "*.htm*", System.IO.SearchOption.AllDirectories);

                try {
                    foreach (string file in files)
                    {
                        string title, content, f;
                        title   = "";
                        content = "";
                        f       = file;
                        HTMLParse(ref title, ref content, ref f);

                        Field fldTitle   = new StringField("title", title, FieldStore.YES);
                        Field fldPlace   = new StringField("place", f, FieldStore.YES);
                        Field fldContent = new TextField("content", content, FieldStore.YES);

                        Document doc = new Document();
                        doc.Add(fldTitle);
                        doc.Add(fldPlace);
                        doc.Add(fldContent);
                        indexWriter.AddDocument(doc);
                    }
                } catch (System.IO.IOException ex) {
                    System.Console.WriteLine(ex.ToString());
                }
                indexWriter.Close();
            } catch (java.io.IOException ex) {
                System.Console.WriteLine("Exception : " + ex.getLocalizedMessage());
            }
        }