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


C# QueryParsers.QueryParser类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: PerformAmountSearch

 public void PerformAmountSearch(string strQuery, out string[] datesArray, out int[] amountsArray)
 {
     List<Document> tweets = new List<Document>();
     List<string> dates = new List<string>();
     List<int> amounts = new List<int>();
     int amount = 0;
     Query query = new QueryParser("text", an).Parse(strQuery);
     Hits results = searcher.Search(query,Sort.INDEXORDER);
     for (int i = 0; i < results.Length(); i++)
     {
         Document doc = results.Doc(i);
         string date = DateTime.Parse(doc.Get("created")).Date.ToString();
         if (!dates.Contains(date))
         {
             if (dates.Count > 0)
             {
                 amounts.Add(amount);
             }
             amount = 0;
             dates.Add(date);
         }
         amount++;
     }
     amounts.Add(amount);
     datesArray = dates.ToArray();
     amountsArray = amounts.ToArray();
 }
开发者ID:peac3maker,项目名称:TwitterSentimentAnalysis,代码行数:27,代码来源:TwitterFeedSearch.cs

示例6: SearchBIMXchange

        public static LuceneResult SearchBIMXchange(string field, string key, int pageSize, int pageNumber)
        {
            const string luceneIndexPath = "C:\\LuceneIndex";

            var directory = FSDirectory.Open(new DirectoryInfo(luceneIndexPath));

            var analyzer = new StandardAnalyzer(Version.LUCENE_29);

            var parser = new QueryParser(Version.LUCENE_29, field, analyzer);
            var query = parser.Parse(String.Format("{0}*", key));

            var searcher = new IndexSearcher(directory, true);

            var topDocs = searcher.Search(query, 1000000);

            var docs = new List<Document>();
            var start = (pageNumber-1)*pageSize;
            for (var i = start; i < start + pageSize && i < topDocs.TotalHits; i++)
            {
                var scoreDoc = topDocs.ScoreDocs[i];
                var docId = scoreDoc.doc;
                var doc = searcher.Doc(docId);
                docs.Add(doc);
            }

            searcher.Close();
            directory.Close();
            var result = new LuceneResult {Results = docs, TotalCount = topDocs.TotalHits};
            return result;
        }
开发者ID:joelkarr,项目名称:ENGworks,代码行数:30,代码来源:Search.cs

示例7: 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

示例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: 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

示例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: LuceneSearchDeps

 internal LuceneSearchDeps(SearcherManager searcherManager, QueryParser parser, IMetaDataResolver resolver, IQueue queue)
 {
     this.SearcherManager = searcherManager;
     this.Parser = parser;
     this.Resolver = resolver;
     this.Queue = queue;
 }
开发者ID:daszat,项目名称:zetbox,代码行数:7,代码来源:Module.cs

示例12: 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

示例13: 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

示例14: TestBasicQueryParser

 public void TestBasicQueryParser()
 {
     var query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "description", new SimpleAnalyzer())
         .Parse("partnum:Q36 AND SPACE");
     Assert.AreEqual("+partnum:q +description:space", query.ToString(), "note Q36 -> q");
     Assert.AreEqual(0, searcher.Search(query, 10).ScoreDocs.Length, "doc not found :(");
 }
开发者ID:diegocaxito,项目名称:LuceneTest,代码行数:7,代码来源:KeywordAnalyzerTest.cs

示例15: Find

        public SearchResults Find(string terms)
        {
            Directory directory = FSDirectory.GetDirectory("./index",false);
            // Now search the index:
            var isearcher = new IndexSearcher(directory);
            // Parse a simple query that searches for "text":
            //Query query = QueryParser.Parse("text", "fieldname", analyzer);
            var qp = new QueryParser("description", _analyzer);
            Query query = qp.Parse(terms);

            Hits hits = isearcher.Search(query);

            var sr = new SearchResults();

            // Iterate through the results:
            for (int i = 0; i < hits.Length(); i++)
            {
                Document hitDoc = hits.Doc(i);

                sr.Add(new Result() { Name = hitDoc.Get("name"), Description = hitDoc.Get("description") });
            }
            isearcher.Close();
            directory.Close();

            return sr;
        }
开发者ID:drusellers,项目名称:biblioteca,代码行数:26,代码来源:LuceneSearch.cs


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