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


C# MultiFieldQueryParser.Parse方法代码示例

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


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

示例1: Search

        public ActionResult Search(string query)
        {
            ViewData["Message"] = "query : " + query;

            var searcher = new IndexSearcher(
                new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(Configuration.IndexDirectory)),
                readOnly: true);

            var fieldsToSearchIn = new[] {Configuration.Fields.Name, Configuration.Fields.Description};
            var queryanalizer = new MultiFieldQueryParser(Version.LUCENE_CURRENT,
                                                          fieldsToSearchIn,
                                                          new BrazilianAnalyzer());

            var numberOfResults = 10;
            var top10Results = searcher.Search(queryanalizer.Parse(query), numberOfResults);
            var docs = new List<DocumentViewModel>();
            foreach (var scoreDoc in top10Results.scoreDocs)
            {
                var document = searcher.Doc(scoreDoc.doc);
                var name = document.GetField(Configuration.Fields.Name).StringValue();
                var description = document.GetField(Configuration.Fields.Description).StringValue();
                var link = document.GetField(Configuration.Fields.Link).StringValue();
                docs.Add(new DocumentViewModel(name, description, link));
            }
            return View(new SearchViewModel(docs));
        }
开发者ID:brunomlopes,项目名称:techdays2010pt-lucene,代码行数:26,代码来源:HomeController.cs

示例2: TestSimple

		public virtual void  TestSimple()
		{
			string[] fields = new string[]{"b", "t"};
			MultiFieldQueryParser mfqp = new MultiFieldQueryParser(Util.Version.LUCENE_CURRENT, fields, new StandardAnalyzer(Util.Version.LUCENE_CURRENT));
			
			Query q = mfqp.Parse("one");
			Assert.AreEqual("b:one t:one", q.ToString());
			
			q = mfqp.Parse("one two");
			Assert.AreEqual("(b:one t:one) (b:two t:two)", q.ToString());
			
			q = mfqp.Parse("+one +two");
			Assert.AreEqual("+(b:one t:one) +(b:two t:two)", q.ToString());
			
			q = mfqp.Parse("+one -two -three");
			Assert.AreEqual("+(b:one t:one) -(b:two t:two) -(b:three t:three)", q.ToString());
			
			q = mfqp.Parse("one^2 two");
			Assert.AreEqual("((b:one t:one)^2.0) (b:two t:two)", q.ToString());
			
			q = mfqp.Parse("one~ two");
			Assert.AreEqual("(b:one~0.5 t:one~0.5) (b:two t:two)", q.ToString());
			
			q = mfqp.Parse("one~0.8 two^2");
			Assert.AreEqual("(b:one~0.8 t:one~0.8) ((b:two t:two)^2.0)", q.ToString());
			
			q = mfqp.Parse("one* two*");
			Assert.AreEqual("(b:one* t:one*) (b:two* t:two*)", q.ToString());
			
			q = mfqp.Parse("[a TO c] two");
			Assert.AreEqual("(b:[a TO c] t:[a TO c]) (b:two t:two)", q.ToString());
			
			q = mfqp.Parse("w?ldcard");
			Assert.AreEqual("b:w?ldcard t:w?ldcard", q.ToString());
			
			q = mfqp.Parse("\"foo bar\"");
			Assert.AreEqual("b:\"foo bar\" t:\"foo bar\"", q.ToString());
			
			q = mfqp.Parse("\"aa bb cc\" \"dd ee\"");
			Assert.AreEqual("(b:\"aa bb cc\" t:\"aa bb cc\") (b:\"dd ee\" t:\"dd ee\")", q.ToString());
			
			q = mfqp.Parse("\"foo bar\"~4");
			Assert.AreEqual("b:\"foo bar\"~4 t:\"foo bar\"~4", q.ToString());
			
			// LUCENE-1213: MultiFieldQueryParser was ignoring slop when phrase had a field.
			q = mfqp.Parse("b:\"foo bar\"~4");
			Assert.AreEqual("b:\"foo bar\"~4", q.ToString());
			
			// make sure that terms which have a field are not touched:
			q = mfqp.Parse("one f:two");
			Assert.AreEqual("(b:one t:one) f:two", q.ToString());
			
			// AND mode:
			mfqp.DefaultOperator = QueryParser.AND_OPERATOR;
			q = mfqp.Parse("one two");
			Assert.AreEqual("+(b:one t:one) +(b:two t:two)", q.ToString());
			q = mfqp.Parse("\"aa bb cc\" \"dd ee\"");
			Assert.AreEqual("+(b:\"aa bb cc\" t:\"aa bb cc\") +(b:\"dd ee\" t:\"dd ee\")", q.ToString());
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:59,代码来源:TestMultiFieldQueryParser.cs

示例3: Search

		/// <summary>
		/// Searches the lucene index with the search text.
		/// </summary>
		/// <param name="searchText">The text to search with.</param>
		/// <remarks>Syntax reference: http://lucene.apache.org/java/2_3_2/queryparsersyntax.html#Wildcard</remarks>
		/// <exception cref="SearchException">An error occured searching the lucene.net index.</exception>
		public virtual IEnumerable<SearchResultViewModel> Search(string searchText)
		{
            // This check is for the benefit of the CI builds
			if (!Directory.Exists(IndexPath))
				CreateIndex();

			List<SearchResultViewModel> list = new List<SearchResultViewModel>();

			if (string.IsNullOrWhiteSpace(searchText))
				return list;

			StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
            MultiFieldQueryParser parser = new MultiFieldQueryParser(LuceneVersion.LUCENE_29, new string[] { "content", "title", "projectlanguage", "projectstatus" }, analyzer);

			Query query = null;
			try
			{
                query = parser.Parse(searchText);
			}
			catch (Lucene.Net.QueryParsers.ParseException)
			{
				// Catch syntax errors in the search and remove them.
				searchText = QueryParser.Escape(searchText);
				query = parser.Parse(searchText);
			}

			if (query != null)
			{
				try
				{
					using (IndexSearcher searcher = new IndexSearcher(FSDirectory.Open(new DirectoryInfo(IndexPath)), true))
					{
						TopDocs topDocs = searcher.Search(query, 1000);

						foreach (ScoreDoc scoreDoc in topDocs.ScoreDocs)
						{
							Document document = searcher.Doc(scoreDoc.Doc);
							list.Add(new SearchResultViewModel(document, scoreDoc));
						}
					}
				}
				catch (FileNotFoundException)
				{
					// For 1.7's change to the Lucene search path.
					CreateIndex();
				}
				catch (Exception ex)
				{
					throw new SearchException(ex, "An error occured while searching the index, try rebuilding the search index via the admin tools to fix this.");
				}
			}

			return list;
		}
开发者ID:LocalGovDigital,项目名称:pipeline,代码行数:60,代码来源:SearchService.cs

示例4: SafeGetSearchQuery

 public static Query SafeGetSearchQuery(this string term, MultiFieldQueryParser q, Analyzer analyser)
 {
     Query query;
     try
     {
         query = q.Parse(term.MakeFuzzy());
     }
     catch
     {
         var searchTerm = term.Sanitize(analyser);
         query = q.Parse(searchTerm);
     }
     return query;
 }
开发者ID:neozhu,项目名称:MrCMS,代码行数:14,代码来源:LuceneQueryStringHelper.cs

示例5: searchLucene

        public Data searchLucene(Data data)
        {
            Account_lg account = new Account_lg();
            List<string> item = new List<string>();
            Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo("C:\\Visual Studio 2010\\Transaction" + "\\LuceneIndex"));
            var analyzer = new StandardAnalyzer(Version.LUCENE_29);
            IndexReader reader = IndexReader.Open(directory, true);
            IndexSearcher searcher = new IndexSearcher(reader);

            MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new string[] { "name", "username" }, analyzer);  //search for multifield
            Query query = parser.Parse((data.getString("search")) + "*"); //cant search blank text with wildcard as first character

            TopScoreDocCollector collector = TopScoreDocCollector.Create(1000, true);
            searcher.Search(query, collector);
            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
            int count = hits.Length;

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

                Document doc = searcher.Doc(docId);

                string id = doc.Get("id");
                item.Add(id);
            }
            Data list = account.selectUser(data, item.ToArray());
            reader.Dispose();
            searcher.Dispose();

            return list;
        }
开发者ID:hyori7,项目名称:AccountTransaction,代码行数:33,代码来源:Lucene_lg.cs

示例6: Search

        public IList<MedicalConsultory> Search(string searchText)
        {
            if (string.IsNullOrWhiteSpace(searchText))
                return new List<MedicalConsultory>();

            using (var searcher = new IndexSearcher(_indexDirectoryPath, true))
            {
                var analyzer = new StandardAnalyzer(_version);

                // Multi field search
                var query = new BooleanQuery();
                var parser = new MultiFieldQueryParser(_version, new[] { "SpecialtyName", "City" }, analyzer);

                searchText.RemoveIrrelevantTerms()
                          .Split(' ')
                          .ToList()
                          .ForEach(word =>
                          {
                              query.Add(parser.Parse(word), Occur.SHOULD);
                          });
                var hits = searcher.Search(query, null, searcher.MaxDoc, Sort.RELEVANCE).ScoreDocs;

                // Simple field search
                //var parser = new QueryParser(Version.LUCENE_30, "SpecialtyName", analyzer);
                //var query = parser.Parse(searchText.Trim());
                //var hits = searcher.Search(query, searcher.MaxDoc).ScoreDocs;

                var results = hits.Select(hit => MapMedicalConsultory(hit, searcher)).ToList();

                analyzer.Close();
                searcher.Dispose();

                return results;
            }
        }
开发者ID:rafaelzaccanini,项目名称:lucene-search-sample,代码行数:35,代码来源:MedicalSearch.cs

示例7: searchLucene

        public Data searchLucene(Data data)
        {
            Search_gl search = new Search_gl();
            List<string> item = new List<string>();
            Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo(Environment.CurrentDirectory + "\\LuceneIndex"));
            var analyzer = new StandardAnalyzer(Version.LUCENE_29);

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

            //QueryParser queryParser = new QueryParser(Version.LUCENE_29, "summary", analyzer);  //search for single field
            MultiFieldQueryParser parser = new MultiFieldQueryParser(new string[] {"name", "summary"}, analyzer);  //search for multifield
            Query query = parser.Parse((data.getString("search")) + "*"); //cant search blank text with wildcard as first character

            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
            searcher.Search(query, collector);
            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
            int count = hits.Length;

            for (int i = 0; i < count; i++)
            {
                int docId = hits[i].doc;
                float score = hits[i].score;

                Document doc = searcher.Doc(docId);

                string id = doc.Get("id");
                item.Add(id);
            }
            Data list = search.search(data, item.ToArray());
            reader.Close();
            searcher.Close();

            return list;
        }
开发者ID:hyori7,项目名称:WebDirectory,代码行数:35,代码来源:Lucene_gl.cs

示例8: Search

        public SearchResults Search(DocumentRoot root, string term)
        {
            var results = new SearchResults();
            var indexPath = _settings.GetSearchIndexPath();
            var version = Lucene.Net.Util.Version.LUCENE_30;

            using (var directory = FSDirectory.Open(new DirectoryInfo(indexPath)))
            using (var indexReader = IndexReader.Open(directory, true))
            using (var indexSearch = new IndexSearcher(indexReader))
            {
                var analyzer = new StandardAnalyzer(version);
                var queryParser = new MultiFieldQueryParser(version, new[] { "Title", "Body" }, analyzer);
                var query = queryParser.Parse(term);

                var resultDocs = indexSearch.Search(query, indexReader.MaxDoc);
                var hits = resultDocs.ScoreDocs;
                foreach (var hit in hits)
                {
                    var doc = indexSearch.Doc(hit.Doc);

                    results.Documents.Add(new SearchResult
                    {
                        Score = hit.Score,
                        Snippet = doc.Get("Snippet"),
                        Title = doc.Get("Title")
                    });
                }
            }

            return results;
        }
开发者ID:vidoardes,项目名称:mvc-docs,代码行数:31,代码来源:LuceneSearcher.cs

示例9: Query

        public static SearchResults Query(HttpContext ctx, string query, int page = 1)
        {
            var indexPath = ctx.Server.MapPath("~/App_Data/Index");
            var indexSearcher = new DirectoryIndexSearcher(new DirectoryInfo(indexPath));
            using (var searchService = new SearchService(indexSearcher)) {
                var parser = new MultiFieldQueryParser(
                    Lucene.Net.Util.Version.LUCENE_29,
                    new[] { "Text" },
                    new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
                Query multiQuery = parser.Parse(query);

                var result = searchService.SearchIndex(multiQuery);
                return new SearchResults {
                    Documents = result.Results
                    .Skip(PageSize*(page - 1))
                    .Take(PageSize)
                    .Select(d => new SearchResult {
                        Url = d.Get("Url"),
                        Title = d.Get("Title"),
                        Summary = d.Get("Summary")
                    }),
                    TotalCount = result.Results.Count()
                };
            }
        }
开发者ID:agriffard,项目名称:OrchardDoc,代码行数:25,代码来源:SearchHelpers.cs

示例10: RemoveFromIndex

 public void RemoveFromIndex(string[] keys, string value)
 {
     var analyzer = new AccentedAnalyzer();
     var query = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, keys, analyzer);
     var directory = FSDirectory.Open(System.IO.Directory.GetParent(IndexPath));
     IndexReader idxReader = IndexReader.Open(indexPath);
     var searcher = new IndexSearcher(directory, true);
     query.SetDefaultOperator(QueryParser.Operator.AND);
     var q = query.Parse(value);
     int top = idxReader.MaxDoc();
     var results = TopScoreDocCollector.create(top, true);
     searcher.Search(q, results);
     ScoreDoc[] hits = results.TopDocs().scoreDocs;
     Document[] documents = new Document[hits.Length];
     IndexReader indexReader = null;
     for (int i = 0; i < hits.Length; i++)
     {
         int docId = hits[i].doc;
         indexReader = IndexReader.Open(directory, false);
         indexReader.DeleteDocument(docId);
         indexReader.Commit();
         indexReader.Flush();
         indexReader.Close();
     }
     searcher.Close();
     directory.Close();
 }
开发者ID:arturcp,项目名称:WebToolkit,代码行数:27,代码来源:IndexManager.cs

示例11: GetSearchResult

        public override List<ISearchEntity> GetSearchResult(out int MatchCount)
        {
            Analyzer analyzer = new StandardAnalyzer();

            IndexSearcher searcher = new IndexSearcher(searchInfo.ConfigElement.IndexDirectory);
            MultiFieldQueryParser parserName = new MultiFieldQueryParser(new string[] { "title", "content", "keywords" }, analyzer);

            Query queryName = parserName.Parse(searchInfo.QueryString);

            Hits hits = searcher.Search(queryName);

            List<ISearchEntity> ResultList = new List<ISearchEntity>();

            for (int i = 0; i < hits.Length(); i++)
            {
                Document doc = hits.Doc(i);

                ResultList.Add((ISearchEntity)new NewsModel()
                {
                    EntityIdentity = Convert.ToInt32(doc.Get("newsid")),
                    Title = Convert.ToString(doc.Get("title")),
                    Content = Convert.ToString(doc.Get("content")),
                    Keywords = doc.Get("keywords")
                });
            }
            searcher.Close();

            MatchCount = hits.Length();
            return ResultList;
        }
开发者ID:ViniciusConsultor,项目名称:noname-netshop,代码行数:30,代码来源:NewsSearcher.cs

示例12: Search

        public ProjectData[] Search(string searchTerm)
        {
            IndexSearcher searcher = new IndexSearcher(luceneIndexDirectory);
            IntegralCollector searcherCollector = new IntegralCollector();
            // Setup the fields to search through
            string[] searchfields = new string[] { "name", "vessel" };

            // Build our booleanquery that will be a combination of all the queries for each individual search term
            var finalQuery = new BooleanQuery();
            var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, searchfields, analyzer);

            // Split the search string into separate search terms by word
            string[] terms = searchTerm.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string term in terms)
                finalQuery.Add(parser.Parse(term.Replace("~", "") + "~"),Occur.SHOULD);

            searcher.Search(finalQuery, searcherCollector);
            var results = new ProjectData[searcherCollector.Docs.Count];
            for (int i = 0; i < searcherCollector.Docs.Count; i++)
            {
                var doc = searcher.Doc(searcherCollector.Docs[i]);
                results[i] = new ProjectData(doc.Get("name"), doc.Get("vessel"));
            }
            return results;
        }
开发者ID:trymnilsen,项目名称:AegirServer,代码行数:25,代码来源:LuceneService.cs

示例13: SearchAds

        public List<Advert> SearchAds(string query)
        {
            if (_searcher == null) return null;

            ICollection fields = _searcher.Reader.GetFieldNames(IndexReader.FieldOption.ALL);
            List<string> fldList = new List<string>();
            foreach (DictionaryEntry f in fields)
            {
                fldList.Add(f.Key.ToString());

            }
            List<Advert> adverts = new List<Advert>();
            MultiFieldQueryParser parser = new MultiFieldQueryParser(fldList.ToArray(), _analyzer);
            Query q = parser.Parse(query);
            Hits hits = _searcher.Search(q);
            PropertyDescriptors desc = new PropertyDescriptors();
            desc.LoadData(System.Windows.Forms.Application.StartupPath + "\\PropertyDescriptors.xml");
            for (int i = 0; i < hits.Length(); i++)
            {
                Advert ad = new Advert();
                Document doc = hits.Doc(i);
                foreach (Field f in doc.Fields())
                {

                    string temp = desc.GetDisplayableFormat(f.Name(), f.StringValue());
                    ad[f.Name()] = temp;

                }
                adverts.Add(ad);
            }

            return adverts;
        }
开发者ID:usmanghani,项目名称:Misc,代码行数:33,代码来源:AdSearcher.cs

示例14: Search

        IEnumerable<string> Search(string textToFind)
        {
            var reader = IndexReader.Open(_ramDirectory, true);
            var searcher = new IndexSearcher(reader);
            var analyzer = new StandardAnalyzer(Version.LUCENE_29);
            var parser = new MultiFieldQueryParser(Version.LUCENE_29, _searchFields, analyzer);

            var query = parser.Parse(textToFind);

            var collector = TopScoreDocCollector.create(100, true);

            searcher.Search(query, collector);

            var hits = collector.TopDocs().scoreDocs;
            var foundKeys = new List<string>();
            foreach (ScoreDoc scoreDoc in hits)
            {

                var document = searcher.Doc(scoreDoc.doc);
                var key = document.Get(_keyField);

                if (key != null && !foundKeys.Contains(key))
                {
                    foundKeys.Add(key);
                }
            }
            reader.Close();
            searcher.Close();
            analyzer.Close();
            return foundKeys;
        }
开发者ID:MikeLarah,项目名称:YouTrackSharp,代码行数:31,代码来源:LuceneIssuePatternMatching.cs

示例15: Should_parse_using_lucene_query

		public void Should_parse_using_lucene_query()
		{
			var parser = new MultiFieldQueryParser(Version.LUCENE_29, new[] {"Name"}, new StandardAnalyzer(Version.LUCENE_29));
			var query = parser.Parse("Switzerland");
			var q = SearchSession.CreateFullTextQuery(query, typeof (Country))
				.List<Country>();
			Assert.AreEqual(1, q.Count);
		}
开发者ID:abusby,项目名称:NHibernate.Search,代码行数:8,代码来源:SimpleMappingsSearchTest.cs


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