예제 #1
0
        public virtual void TestMultiTermDocs()
        {
            SqlServerDirectory.ProvisionDatabase(Connection, "test1", true);
            SqlServerDirectory.ProvisionDatabase(Connection, "test2", true);
            SqlServerDirectory.ProvisionDatabase(Connection, "test3", true);

            var ramDir1 = new SqlServerDirectory(Connection, new Options()
            {
                SchemaName = "test1"
            });

            AddDoc(ramDir1, "test foo", true);
            var ramDir2 = new SqlServerDirectory(Connection, new Options()
            {
                SchemaName = "test2"
            });

            AddDoc(ramDir2, "test blah", true);
            var ramDir3 = new SqlServerDirectory(Connection, new Options()
            {
                SchemaName = "test3"
            });

            AddDoc(ramDir3, "test wow", true);

            IndexReader[] readers1 = new[] { IndexReader.Open(ramDir1, false), IndexReader.Open(ramDir3, false) };
            IndexReader[] readers2 = new[] { IndexReader.Open(ramDir1, false), IndexReader.Open(ramDir2, false), IndexReader.Open(ramDir3, false) };
            MultiReader   mr2      = new MultiReader(readers1);
            MultiReader   mr3      = new MultiReader(readers2);

            // test mixing up TermDocs and TermEnums from different readers.
            TermDocs td2 = mr2.TermDocs();
            TermEnum te3 = mr3.Terms(new Term("body", "wow"));

            td2.Seek(te3);
            int ret = 0;

            // This should blow up if we forget to check that the TermEnum is from the same
            // reader as the TermDocs.
            while (td2.Next())
            {
                ret += td2.Doc;
            }
            td2.Close();
            te3.Close();

            // really a dummy assert to ensure that we got some docs and to ensure that
            // nothing is optimized out.
            Assert.IsTrue(ret > 0);
        }
예제 #2
0
        public static void AddSearchIndex(List <FullTextSearchModelcs> Adding)
        {
            using (var connection = new SqlConnection(@"Server=DESKTOP-S0G3F8R\SQLEXPRESS;Database=KraudFan2_0;Trusted_Connection=True;MultipleActiveResultSets=true"))
            {
                connection.Open();
                var directory = new SqlServerDirectory(connection, new Options()
                {
                    SchemaName = "[search]"
                });

                var exists = IndexReader.IndexExists(directory);
                if (exists == false)
                {
                    SqlServerDirectory.ProvisionDatabase(connection, schemaName: "[search]", dropExisting: true);
                }
                var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), exists, new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));

                foreach (var item in Adding)
                {
                    var doc = new Document();
                    doc.Add(new NumericField("Id", Field.Store.YES, true).SetIntValue(item.ProjectId));
                    if (item.Content == null)
                    {
                        doc.Add(new Field("Title", "Govnina", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
                    }
                    else
                    {
                        doc.Add(new Field("Title", item.Content, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
                    }
                    indexWriter.AddDocument(doc);
                }

                indexWriter.Flush(true, true, true);

                indexWriter.Dispose();
            }
        }
예제 #3
0
        public IActionResult IndexAllData()
        {
            using (var connection = new SqlConnection(@"Data Source=SQL6003.SmarterASP.NET;Initial Catalog=DB_A296DE_shchepko;User Id=DB_A296DE_shchepko_admin;Password=15879569pg;MultipleActiveResultSets=True"))
            {
                connection.Open();
                SqlServerDirectory.ProvisionDatabase(connection, schemaName: "[search]", dropExisting: true);
                var directory = new SqlServerDirectory(connection, new Options()
                {
                    SchemaName = "[search]"
                });

                var exists      = !IndexReader.IndexExists(directory);
                var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), exists, new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));
                var coll        = TransformAll();

                foreach (var item in coll)
                {
                    var doc = new Document();
                    doc.Add(new NumericField("Id", Field.Store.YES, true).SetIntValue(item.ProjectId));
                    if (item.Content == null)
                    {
                        doc.Add(new Field("Title", "Govnina", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
                    }
                    else
                    {
                        doc.Add(new Field("Title", item.Content, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
                    }
                    indexWriter.AddDocument(doc);
                }
                // indexWriter.Optimize();
                indexWriter.Flush(true, true, true);
                indexWriter.Commit();
                indexWriter.Dispose();
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #4
0
 public virtual void TestInitialize()
 {
     Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["databaseForTests"].ConnectionString);
     Connection.Open();
     SqlServerDirectory.ProvisionDatabase(Connection, schemaName: new Options().SchemaName, dropExisting: true);
 }