当前位置: 首页>>代码示例>>C#>>正文


C# Store.RAMDirectory类代码示例

本文整理汇总了C#中Lucene.Net.Store.RAMDirectory的典型用法代码示例。如果您正苦于以下问题:C# RAMDirectory类的具体用法?C# RAMDirectory怎么用?C# RAMDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RAMDirectory类属于Lucene.Net.Store命名空间,在下文中一共展示了RAMDirectory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Ensure_Children_Are_Sorted

        public void Ensure_Children_Are_Sorted()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();

                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.TotalItemCount);

                var searchItem = result.First();
                var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
                var children = backedMedia.ChildrenAsList.Value;

                var currSort = 0;
                for (var i = 0; i < children.Count(); i++)
                {
                    Assert.GreaterOrEqual(children[i].SortOrder, currSort);
                    currSort = children[i].SortOrder;
                }
            }

        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:25,代码来源:LegacyExamineBackedMediaTests.cs

示例2: AddIndexbtn_Click

    protected void AddIndexbtn_Click(object sender, EventArgs e)
    {
        Lucene.Net.Store.Directory ramdir = new Lucene.Net.Store.RAMDirectory();

        Console.WriteLine("Indexing...");
        DateTime start = DateTime.Now;

        string path4 = Server.MapPath("./") + @"1.4\\";
        if (System.IO.Directory.Exists(path4))//是否存在目录
        {
            Indexer.IntranetIndexer indexer4 = new Indexer.IntranetIndexer(Server.MapPath("index\\1.4\\"));
            indexer4.AddDirectory(new System.IO.DirectoryInfo(path4), "*.*");
            indexer4.Close();
        }
        //IntranetIndexer indexer = new IntranetIndexer(ramdir);//把索引写进内存

        string path5 = Server.MapPath("./") + @"1.5\\";
        if (System.IO.Directory.Exists(path5))
        {
             Indexer.IntranetIndexer indexer5 = new Indexer.IntranetIndexer(Server.MapPath("index\\1.5\\"));
             indexer5.AddDirectory(new System.IO.DirectoryInfo(path5), "*.*");
             indexer5.Close();

        }

        Console.WriteLine("Done. Took " + (DateTime.Now - start));
        Response.Write("<script type='text/javascript'>window.alert(' 创建索引成功,并已经优化!!! ');</script>");
    }
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:28,代码来源:AddIndex.aspx.cs

示例3: TestReadersWriters

        public void TestReadersWriters()
        {
            Directory dir;
            
            using(dir = new RAMDirectory())
            {
                Document doc;
                IndexWriter writer;
                IndexReader reader;

                using (writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    Field field = new Field("name", "value", Field.Store.YES,Field.Index.ANALYZED);
                    doc = new Document();
                    doc.Add(field);
                    writer.AddDocument(doc);
                    writer.Commit();

                    using (reader = writer.GetReader())
                    {
                        IndexReader r1 = reader.Reopen();
                    }

                    Assert.Throws<AlreadyClosedException>(() => reader.Reopen(), "IndexReader shouldn't be open here");
                }
                
                Assert.Throws<AlreadyClosedException>(() => writer.AddDocument(doc), "IndexWriter shouldn't be open here");

                Assert.IsTrue(dir.isOpen_ForNUnit, "RAMDirectory");
            }
            Assert.IsFalse(dir.isOpen_ForNUnit, "RAMDirectory");
        }
开发者ID:hanabi1224,项目名称:lucene.net,代码行数:32,代码来源:TestIDisposable.cs

示例4: Main

        public static void Main()
        {
            var directory = new RAMDirectory();

            var provider = new LuceneDataProvider(directory, Version.LUCENE_30);

            // add some documents
            using (var session = provider.OpenSession<Article>())
            {
                session.Add(new Article { Author = "John Doe", BodyText = "some body text", PublishDate = DateTimeOffset.UtcNow });
            }

            var articles = provider.AsQueryable<Article>();

            var threshold = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(30));

            var articlesByJohn = from a in articles
                          where a.Author == "John Smith" && a.PublishDate > threshold
                          orderby a.Title
                          select a;

            var searchResults = from a in articles
                                 where a.SearchText == "some search query"
                                 select a;

        }
开发者ID:chriseldredge,项目名称:Lucene.Net.Linq,代码行数:26,代码来源:SampleProgram.cs

示例5: GetDirectory

        protected virtual Directory GetDirectory()
        {
            if(this._directory == null)
                this._directory = new RAMDirectory();

            return this._directory;
        }
开发者ID:tucaz,项目名称:LuceneIndexManager,代码行数:7,代码来源:AbstractIndexDefinition.cs

示例6: TestRAMDirectoryNoLocking

		public virtual void  TestRAMDirectoryNoLocking()
		{
			Directory dir = new RAMDirectory();
			dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
			
			Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(dir.GetLockFactory()), "RAMDirectory.setLockFactory did not take");
			
			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			
			// Create a 2nd IndexWriter.  This is normally not allowed but it should run through since we're not
			// using any locks:
			IndexWriter writer2 = null;
			try
			{
				writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
			}
			catch (System.Exception e)
			{
				System.Console.Out.WriteLine(e.StackTrace);
				Assert.Fail("Should not have hit an IOException with no locking");
			}
			
			writer.Close();
			if (writer2 != null)
			{
				writer2.Close();
			}
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:28,代码来源:TestLockFactory.cs

示例7: MissingTerms_Test

        public void MissingTerms_Test()
        {
            string fieldName = "field1";
            RAMDirectory rd = new RAMDirectory();
            IndexWriter w = new IndexWriter(rd, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
            for (int i = 0; i < 100; i++)
            {
                Document doc = new Document();
                int term = i * 10; //terms are units of 10;
                doc.Add(new Field(fieldName, "" + term, Field.Store.YES, Field.Index.NOT_ANALYZED));
                w.AddDocument(doc);
            }
            w.Close();
            IndexReader reader = IndexReader.Open(rd, true);

            TermsFilter tf = new TermsFilter();
            tf.AddTerm(new Term(fieldName, "19"));
            OpenBitSet bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(0, bits.Cardinality(), "Must match nothing");

            tf.AddTerm(new Term(fieldName, "20"));
            bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(1, bits.Cardinality(), "Must match 1");

            tf.AddTerm(new Term(fieldName, "10"));
            bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(2, bits.Cardinality(), "Must match 2");

            tf.AddTerm(new Term(fieldName, "00"));
            bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(2, bits.Cardinality(), "Must match 2");
        }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:32,代码来源:TermsFilterTest.cs

示例8: Main

		private static void Main(string[] args)
		{
		    var ramDirectory = new RAMDirectory();
		    var spellChecker = new SpellChecker.Net.Search.Spell.SpellChecker(ramDirectory);
		    var ms = new MemoryStream();
		    var sw = new StreamWriter(ms);
            sw.WriteLine("Book");
            sw.WriteLine("Bath");
            sw.WriteLine("Bed");
            sw.WriteLine("Make");
            sw.WriteLine("Model");
            sw.WriteLine("Vacum");
            sw.WriteLine("Wending machine");
            sw.Flush();
		    ms.Position = 0;
            spellChecker.setStringDistance(new JaroWinklerDistance());
            spellChecker.SetAccuracy(0.3f);
            spellChecker.IndexDictionary(new PlainTextDictionary(ms), CancellationToken.None);

		    var indexReader = IndexReader.Open(ramDirectory, true);
		    var termEnum = indexReader.Terms();
		    while (termEnum.Next())
		    {
		        Console.WriteLine(termEnum.Term);
		    }

		    var suggestSimilar = spellChecker.SuggestSimilar("both", 10);
		    foreach (var s in suggestSimilar)
		    {
		        Console.WriteLine(s);
		    }
		}
开发者ID:JohannesRudolph,项目名称:ravendb,代码行数:32,代码来源:Program.cs

示例9: Ensure_Children_Sorted_With_Examine

        public void Ensure_Children_Sorted_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx = GetUmbracoContext("/test", 1234);
                var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(1111);
                var rootChildren = publishedMedia.Children().ToArray();
                var currSort = 0;
                for (var i = 0; i < rootChildren.Count(); i++)
                {
                    Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                    currSort = rootChildren[i].SortOrder;
                }
            }

            



        }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:26,代码来源:PublishedMediaTests.cs

示例10: HelloWorldTest

        public void HelloWorldTest()
        {
            Directory directory = new RAMDirectory();
            Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
            IndexWriter writer = new IndexWriter(directory,
                analyzer,
                IndexWriter.MaxFieldLength.UNLIMITED);

            Document doc = new Document();
            doc.Add(new Field("id", "1", Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("postBody", "sample test", Field.Store.YES, Field.Index.ANALYZED));
            writer.AddDocument(doc);
            writer.Optimize();
            writer.Commit();
            writer.Close();

            QueryParser parser = new QueryParser(Version.LUCENE_29, "postBody", analyzer);
            Query query = parser.Parse("sample test");

            //Setup searcher
            IndexSearcher searcher = new IndexSearcher(directory, true);
            //Do the search
            var hits = searcher.Search(query, null, 10);

            for (int i = 0; i < hits.TotalHits; i++)
            {
                var doc1 = hits.ScoreDocs[i];
            }

            searcher.Close();
            directory.Close();
        }
开发者ID:oleksii-mdr,项目名称:nTextNetwork,代码行数:32,代码来源:HelloWorldLuceneTest.cs

示例11: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            Directory index = new RAMDirectory();
            StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);

            IndexWriter w = new IndexWriter(index, analyzer);

            addDoc(w, "Lucene in Action");
            addDoc(w, "Lucene for Dummies");
            addDoc(w, "Managing Gigabytes");
            addDoc(w, "The Art of Computer Science");
            w.Close();

            String querystr = "Lucene in Action";

            Query q =  new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "title", analyzer).Parse(querystr);
            //q.Parse();

            int hitsPerPage = 10;
            IndexReader reader = IndexReader.Open(index,true);
            IndexSearcher searcher = new IndexSearcher(reader);
            TopScoreDocCollector collector = TopScoreDocCollector.Create(hitsPerPage, true);
            searcher.Search(q, collector);
            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;

            System.Console.WriteLine("Found {0} Hits", hits.Length);

            foreach (var item in hits)
            {
                int docId = item.Doc;
                Document d = searcher.Doc(docId);
                System.Console.WriteLine(d.Get("title") + " " + item.Score);
            }
        }
开发者ID:samfisher83,项目名称:lucene,代码行数:34,代码来源:Form1.cs

示例12: TestSimpleSearch

        public void TestSimpleSearch()
        {
            var bookGuid = Guid.Parse("11111111-1111-1111-1111-111111111111");

            const string dataToIndex = @"some test string
            some other line
            next line";

            var bookGuid2 = Guid.Parse("11111111-1111-1111-1111-111111111112");

            const string dataToIndex2 = @"some test2 string
            some other line
            next line";

            //TODO: abstract references to lucene
            using (var directory = new RAMDirectory())
            {
                /*var indexer = new BookDataIndexer(directory);

                indexer.IndexContent(bookGuid, new StringReader(dataToIndex));
                indexer.IndexContent(bookGuid2, new StringReader(dataToIndex2));

                var searcher = new BookSearchService(directory);

                IEnumerable<SearchResult> searchResults = searcher.Search("test");
                Assert.That(searchResults.Single().BookId, Is.EqualTo(bookGuid));

                searchResults = searcher.Search("test2");
                Assert.That(searchResults.Single().BookId, Is.EqualTo(bookGuid2));*/
            }
        }
开发者ID:gedgei,项目名称:BookDbSharp,代码行数:31,代码来源:SearchTests.cs

示例13: MrsJones

		public void MrsJones()
		{
			var dir = new RAMDirectory();
			var analyzer = new WhitespaceAnalyzer();
			var writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
			var document = new Lucene.Net.Documents.Document();
			document.Add(new Field("Name", "MRS. SHABA", Field.Store.NO, Field.Index.ANALYZED_NO_NORMS));
			writer.AddDocument(document);

			writer.Close(true);

			

			var searcher = new IndexSearcher(dir, true);

			var termEnum = searcher.GetIndexReader().Terms();
			while (termEnum.Next())
			{
				var buffer = termEnum.Term().Text();
				Console.WriteLine(buffer);
			} 

			var queryParser = new QueryParser(Version.LUCENE_29, "", analyzer);
			queryParser.SetLowercaseExpandedTerms(false);
			var query = queryParser.Parse("Name:MRS.*");
			Console.WriteLine(query);
			var result = searcher.Search(query, 10);

			Assert.NotEqual(0,result.totalHits);
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:30,代码来源:LuceneIndexing.cs

示例14: Ensure_Result_Has_All_Values

        public void Ensure_Result_Has_All_Values()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();

                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.TotalItemCount);

                var searchItem = result.First();
                var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);

                Assert.AreEqual(searchItem.Id, backedMedia.Id);
                Assert.AreEqual(searchItem.Fields["sortOrder"], backedMedia.SortOrder.ToString());
                Assert.AreEqual(searchItem.Fields["urlName"], backedMedia.UrlName);
                Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["createDate"]), backedMedia.CreateDate);
                Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["updateDate"]), backedMedia.UpdateDate);
                Assert.AreEqual(Guid.Parse(searchItem.Fields["version"]), backedMedia.Version);
                Assert.AreEqual(searchItem.Fields["level"], backedMedia.Level.ToString());
                Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.WriterID.ToString());
                Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.CreatorID.ToString()); //there's only writerId in the xml
                Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.CreatorName);
                Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.WriterName); //tehre's only writer name in the xml
            }

        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:29,代码来源:LegacyExamineBackedMediaTests.cs

示例15: Init

        public void Init()
        {
            facetHandlers = new List<IFacetHandler>();

            directory = new RAMDirectory();
            analyzer = new WhitespaceAnalyzer();
            selectionProperties = new Dictionary<string, string>();
            IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);

            writer.AddDocument(Doc("prop1=val1", "prop2=val1", "prop5=val1"));
            writer.AddDocument(Doc("prop1=val2", "prop3=val1", "prop7=val7"));
            writer.AddDocument(Doc("prop1=val2", "prop3=val2", "prop3=val3"));
            writer.AddDocument(Doc("prop1=val1", "prop2=val1"));
            writer.AddDocument(Doc("prop1=val1", "prop2=val1"));
            writer.AddDocument(Doc("prop1=val1", "prop2=val1", "prop4=val2", "prop4=val3"));
            writer.Commit();

            attributesFacetHandler = new AttributesFacetHandler(AttributeHandlerName, AttributeHandlerName, null, null,
                new Dictionary<string, string>());
            facetHandlers.Add(attributesFacetHandler);
            IndexReader reader = IndexReader.Open(directory, true);
            boboReader = BoboIndexReader.GetInstance(reader, facetHandlers);
            attributesFacetHandler.LoadFacetData(boboReader);
            browser = new BoboBrowser(boboReader);
        }
开发者ID:yao-yi,项目名称:BoboBrowse.Net,代码行数:25,代码来源:AttributesFacetHandlerTest.cs


注:本文中的Lucene.Net.Store.RAMDirectory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。