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


C# QueryParser.Parse方法代码示例

本文整理汇总了C#中Lucene.Net.QueryParsers.QueryParser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParser.Parse方法的具体用法?C# QueryParser.Parse怎么用?C# QueryParser.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.QueryParsers.QueryParser的用法示例。


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

示例1: ClassBridge

        public void ClassBridge()
        {
            ISession s = this.OpenSession();
            ITransaction tx = s.BeginTransaction();
            s.Save(this.getDept1());
            s.Save(this.getDept2());
            s.Save(this.getDept3());
            s.Flush();
            tx.Commit();

            tx = s.BeginTransaction();
            IFullTextSession session = Search.CreateFullTextSession(s);

            // The branchnetwork field is the concatenation of both
            // the branch field and the network field of the Department
            // class. This is in the Lucene document but not in the
            // Department entity itself.
            QueryParser parser = new QueryParser("branchnetwork", new SimpleAnalyzer());

            Query query = parser.Parse("branchnetwork:layton 2B");
            IFullTextQuery hibQuery = session.CreateFullTextQuery(query, typeof(Department));
            IList result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.AreEqual("2B", ((Department)result[0]).Network, "incorrect entity returned, wrong network");
            Assert.AreEqual("Layton", ((Department)result[0]).Branch, "incorrect entity returned, wrong branch");
            Assert.AreEqual(1, result.Count, "incorrect number of results returned");

            // Partial match.
            query = parser.Parse("branchnetwork:3c");
            hibQuery = session.CreateFullTextQuery(query, typeof(Department));
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.AreEqual("3C", ((Department)result[0]).Network, "incorrect entity returned, wrong network");
            Assert.AreEqual("West Valley", ((Department)result[0]).Branch, "incorrect entity returned, wrong branch");
            Assert.AreEqual(1, result.Count, "incorrect number of results returned");

            // No data cross-ups .
            query = parser.Parse("branchnetwork:Kent Lewin");
            hibQuery = session.CreateFullTextQuery(query, typeof(Department));
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 0, "problem with field cross-ups");

            // Non-ClassBridge field.
            parser = new QueryParser("BranchHead", new SimpleAnalyzer());
            query = parser.Parse("BranchHead:Kent Lewin");
            hibQuery = session.CreateFullTextQuery(query, typeof(Department));
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1, "incorrect entity returned, wrong branch head");
            Assert.AreEqual("Kent Lewin", ((Department)result[0]).BranchHead, "incorrect entity returned");

            // Cleanup
            foreach (object element in s.CreateQuery("from " + typeof(Department).FullName).List())
            {
                s.Delete(element);
            }
            tx.Commit();
            s.Close();
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:60,代码来源:ClassBridgeTest.cs

示例2: CustomBridges

        public void CustomBridges()
        {
            Cloud cloud = new Cloud();
            cloud.CustomFieldBridge = ("This is divided by 2");
            cloud.CustomStringBridge = ("This is div by 4");
            ISession s = OpenSession();
            ITransaction tx = s.BeginTransaction();
            s.Save(cloud);
            s.Flush();
            tx.Commit();

            tx = s.BeginTransaction();
            IFullTextSession session = Search.CreateFullTextSession(s);
            QueryParser parser = new QueryParser("id", new SimpleAnalyzer());

            Lucene.Net.Search.Query query = parser.Parse("CustomFieldBridge:This AND CustomStringBridge:This");
            IList result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "Properties not mapped");

            query = parser.Parse("CustomFieldBridge:by AND CustomStringBridge:is");
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(0, result.Count, "Custom types not taken into account");

            s.Delete(s.Get(typeof(Cloud), cloud.Id));
            tx.Commit();
            s.Close();
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:27,代码来源:BridgeTest.cs

示例3: ParseQuery

 private static Query ParseQuery(string searchQuery, QueryParser parser)
 {
     Query query;
     try
     {
         query = parser.Parse(searchQuery.Trim());
     }
     catch (ParseException)
     {
         query = parser.Parse(QueryParser.Escape(searchQuery.Trim()));
     }
     return query;
 }
开发者ID:jzuleta,项目名称:ReclamosMoviles,代码行数:13,代码来源:LuceneAction.cs

示例4: List

        public void List()
        {
            IFullTextSession s = Search.CreateFullTextSession(OpenSession());
            ITransaction tx = s.BeginTransaction();
            Clock clock = new Clock(1, "Seiko");
            s.Save(clock);
            clock = new Clock(2, "Festina");
            s.Save(clock);
            Book book =
                new Book(1, "La chute de la petite reine a travers les yeux de Festina",
                         "La chute de la petite reine a travers les yeux de Festina, blahblah");
            s.Save(book);
            book = new Book(2, "La gloire de mon père", "Les deboires de mon père en vélo");
            s.Save(book);
            tx.Commit();
            s.Clear();
            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser("title", new StopAnalyzer());

            Lucene.Net.Search.Query query = parser.Parse("Summary:noword");
            IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            IList result = hibQuery.List();
            Assert.AreEqual(0, result.Count);

            query = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            result = hibQuery.List();
            Assert.AreEqual(2, result.Count, "Query with explicit class filter");

            query = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query);
            result = hibQuery.List();
            Assert.AreEqual(2, result.Count, "Query with no class filter");
            foreach (Object element in result)
            {
                Assert.IsTrue(NHibernateUtil.IsInitialized(element));
                s.Delete(element);
            }
            s.Flush();
            tx.Commit();

            tx = s.BeginTransaction();
            query = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query);
            result = hibQuery.List();
            Assert.AreEqual(0, result.Count, "Query with delete objects");

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:51,代码来源:LuceneQueryTest.cs

示例5: TestWithQueryParser

        public void TestWithQueryParser()
        {
            QueryParser qp = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "", new GISAServer.Search.NivelDocumentalSearcher.InstancePerFieldAnalyzerWrapper().instancePerFieldAnalyzerWrapper);
            Query query = qp.Parse("content:\"manobras\"");
            Assert.AreEqual(1, searcher.Search(query, 1).TotalHits, "!!!! what?");
            
            query = qp.Parse("content:\"porto\"");
            Assert.AreEqual(1, searcher.Search(query, 1).TotalHits, "!!!! *whew*");

            query = qp.Parse("content:\"manobras porto\"");
            Assert.AreEqual(0, searcher.Search(query, 1).TotalHits, "!!!! *whew*");

            query = qp.Parse("content:\"manobras no porto\"");
            Assert.AreEqual(1, searcher.Search(query, 1).TotalHits, "!!!! *whew*");
        }
开发者ID:aureliopires,项目名称:gisa,代码行数:15,代码来源:SynonymAnalyzerTestGisaContext.cs

示例6: AiComplete

        public List<int> AiComplete(string args)
        {
            List<int> list = new List<int>();

            try
            {
                IndexReader citac = IndexReader.Open(this.folder, true);

                var seracher = new IndexSearcher(citac);

                var queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Content", new KeywordAnalyzer());

                queryParser.AllowLeadingWildcard = true;

                var query = queryParser.Parse(args+"*");
                TopDocs result = seracher.Search(query, 5);
                var lista = result.ScoreDocs;

                foreach (var hint in lista)
                {

                    var h = seracher.Doc(hint.Doc);

                    list.Add(h.Get("ArticlesID").ToInt());
                }

            }
            catch (Exception)
            {

            }
            return list;
        }
开发者ID:fitba,项目名称:km-2013-projects-team-igman,代码行数:33,代码来源:LuceneDbEngine.cs

示例7: Engine

        public Engine()
        {
            var directory = new RAMDirectory();
            var analyzer = new StandardAnalyzer(Version.LUCENE_30);

            using (var indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED))
            {
                for (int i = 0; i < 10000; i++)
                {
                    Console.Write(".");
                    var document = new Document();
                    document.Add(new Field("Id", i.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    document.Add(new Field("Name", "Name" + i.ToString(), Field.Store.YES, Field.Index.ANALYZED));
                    indexWriter.AddDocument(document);
                }
            }

            Console.ReadKey();

            var queryParser = new QueryParser(Version.LUCENE_30, "Name", analyzer);
            var query = queryParser.Parse("Name37~");

            IndexReader indexReader = IndexReader.Open(directory, true);
            var searcher = new IndexSearcher(indexReader);

            TopDocs resultDocs = searcher.Search(query, indexReader.MaxDoc);
        }
开发者ID:trulstveoy,项目名称:Sandbox,代码行数:27,代码来源:Engine.cs

示例8: btnExecuteSearch_Click

        private void btnExecuteSearch_Click(object sender, EventArgs e)
        {
            Directory indexDirectory = FSDirectory.Open(new System.IO.DirectoryInfo(tempPath));
            IndexSearcher searcher = new IndexSearcher(indexDirectory, true); // read-only=true

            // TODO: QueryParser support for Hebrew terms (most concerning issue is with acronyms - mid-word quotes)
            QueryParser qp = new QueryParser("content", analyzer);
            qp.SetDefaultOperator(QueryParser.Operator.AND);
            Query query = qp.Parse(txbSearchQuery.Text);

            ScoreDoc[] hits = searcher.Search(query, null, 1000).scoreDocs;

            // Iterate through the results:
            BindingList<SearchResult> l = new BindingList<SearchResult>();
            for (int i = 0; i < hits.Length; i++)
            {
                Document hitDoc = searcher.Doc(hits[i].doc);
                SearchResult sr = new SearchResult(hitDoc.GetField("title").StringValue(),
                    hitDoc.GetField("path").StringValue(), hits[i].score);
                l.Add(sr);
            }

            searcher.Close();
            indexDirectory.Close();

            dgvResults.DataSource = l;
        }
开发者ID:igaler,项目名称:SlovaMorph,代码行数:27,代码来源:MainForm.cs

示例9: Search

        public SearchResult[] Search(string searchString)
        {
            Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Version.LUCENE_29);

            QueryParser parser = new QueryParser(Version.LUCENE_29, "Content", analyzer);

            var query = parser.Parse(searchString);

            Searcher searcher = new IndexSearcher(Lucene.Net.Index.IndexReader.Open(directory, true));

            TopScoreDocCollector collector = TopScoreDocCollector.Create(100, true);

            searcher.Search(query, collector);
            var hits = collector.TopDocs().ScoreDocs;

            List<SearchResult> results = new List<SearchResult>();

            for (int i = 0; i < hits.Length; i++)
            {
                int docId = hits[i].Doc;
                float score = hits[i].Score;

                Lucene.Net.Documents.Document doc = searcher.Doc(docId);

                results.Add(new SearchResult
                {
                    BookId = Guid.Parse(doc.Get("BookId")),
                    Score = score
                });
            }

            return results.ToArray();
        }
开发者ID:gedgei,项目名称:BookDbSharp,代码行数:33,代码来源:BookSearchService.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: 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

示例12: Query

        public Task<List<TestDocument>> Query(string q)
        {
            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "text", Analyzer);
            Query query = parser.Parse(q);
            IndexSearcher searcher = new IndexSearcher(Index, true);
            //Do the search
            TopDocs docs = searcher.Search(query, 10);

            int results = docs.TotalHits;
            List<TestDocument> ret = new List<TestDocument>();
            for (int i = 0; i < results; i++)
            {
                ScoreDoc d = docs.ScoreDocs[i];
                float score = d.Score;
                Document idoc = searcher.Doc(d.Doc);
                ret.Add(new TestDocument()
                {
                    Id = Convert.ToInt32(idoc.GetField("id").StringValue),
                    Text = idoc.GetField("text").StringValue
                });
            }
            searcher.Dispose();

            return Task.FromResult(ret);
        }
开发者ID:adhurwit,项目名称:SearchFabric,代码行数:25,代码来源:SearchFabricIndex.cs

示例13: Execute

        public static ICollection<SearchResult> Execute(string query)
        {
            ICollection<SearchResult> searchResults = new List<SearchResult>();

            string directoryPath = AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\LuceneIndexes";
            var directory = FSDirectory.Open(directoryPath);
            var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "SearchBody", analyzer);
            Query searchQuery = parser.Parse(query + "*");

            IndexSearcher searcher = new IndexSearcher(directory);
            TopDocs hits = searcher.Search(searchQuery, 200);
            int results = hits.ScoreDocs.Length;
            for (int i = 0; i < results; i++)
            {
                Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
                var searchResult = new SearchResult();
                searchResult.EntityId = int.Parse(doc.Get("EntityId"));
                searchResult.EntityTypeName = doc.Get("EntityTypeName");
                searchResult.SearchTitle = doc.Get("SearchTitle");
                searchResult.SearchBody = doc.Get("SearchBody");
                searchResults.Add(searchResult);
            }
            searcher.Dispose();
            directory.Dispose();

            return searchResults;
        }
开发者ID:szwork2013,项目名称:BoiPlt,代码行数:29,代码来源:FullTextSearch.cs

示例14: ResultTransformToDelimString

        public void ResultTransformToDelimString()
        {
            IFullTextSession s = Search.CreateFullTextSession(this.OpenSession());
            this.PrepEmployeeIndex(s);

            s.Clear();
            ITransaction tx = s.BeginTransaction();
            QueryParser parser = new QueryParser("Dept", new StandardAnalyzer());

            Query query = parser.Parse("Dept:ITech");
            IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Employee));
            hibQuery.SetProjection(
                    "Id",
                    "Lastname",
                    "Dept",
                    ProjectionConstants.THIS,
                    ProjectionConstants.SCORE,
                    ProjectionConstants.BOOST,
                    ProjectionConstants.ID);
            hibQuery.SetResultTransformer(new ProjectionToDelimStringResultTransformer());

            IList result = hibQuery.List();
            Assert.IsTrue(((string)result[0]).StartsWith("1000, Griffin, ITech"), "incorrect transformation");
            Assert.IsTrue(((string)result[1]).StartsWith("1002, Jimenez, ITech"), "incorrect transformation");

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:30,代码来源:ProjectionQueryTest.cs

示例15: Main

        public static void Main(string[] args)
        {
            BasicConfigurator.Configure();
            //using (var reader = new MsmqLogReader(new Uri("msmq://localhost/test_queue2")))
            //{
            //    reader.Start();

            //    Console.ReadLine();
            //}

            var searcher = new IndexSearcher("messages");
            var parser = new QueryParser("", new StandardAnalyzer());
            //var query = parser.Parse("MessageId:\"b5005080-800c-43c3-a20b-16db773d7663\" AND MessageId:2307015");
            var query = parser.Parse("Timestamp:[\"2008-12-16T08:14:53.9749900\" TO \"2008-12-16T08:14:53.6343650\"]");

            var hits = searcher.Search(query);
            for (int i = 0; i < hits.Length(); i++)
            {
                var doc = hits.Doc(i);
                Console.WriteLine();
                foreach (Fieldable field in doc.GetFields())
                {
                    Console.WriteLine("{0}: {1}", field.Name(), field.StringValue());
                }
                Console.WriteLine();
            }
        }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:27,代码来源:Program.cs


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