• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# QueryParsers.MultiFieldQueryParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



MultiFieldQueryParser类属于Lucene.Net.QueryParsers命名空间,在下文中一共展示了MultiFieldQueryParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Get

        public Query Get(ProductSearchQuery searchQuery)
        {
            var booleanQuery = new BooleanQuery { ProductSearchPublishedDefinition.PublishedOnly };
            if (!searchQuery.Options.Any() && !searchQuery.Specifications.Any() && Math.Abs(searchQuery.PriceFrom - 0) < 0.01 && !searchQuery.PriceTo.HasValue &&
                !searchQuery.CategoryId.HasValue && string.IsNullOrWhiteSpace(searchQuery.SearchTerm)
                && !searchQuery.BrandId.HasValue)
            {
                return booleanQuery;
            }

            if (searchQuery.Options.Any())
                booleanQuery.Add(GetOptionsQuery(searchQuery.Options), Occur.MUST);
            if (searchQuery.Specifications.Any())
                booleanQuery.Add(GetSpecificationsQuery(searchQuery.Specifications), Occur.MUST);
            if (searchQuery.CategoryId.HasValue)
                booleanQuery.Add(GetCategoriesQuery(searchQuery.CategoryId.Value), Occur.MUST);
            if (searchQuery.PriceFrom > 0 || searchQuery.PriceTo.HasValue)
                booleanQuery.Add(GetPriceRangeQuery(searchQuery), Occur.MUST);
            if (!String.IsNullOrWhiteSpace(searchQuery.SearchTerm))
            {
                IndexDefinition indexDefinition = IndexingHelper.Get<ProductSearchIndex>();
                Analyzer analyser = indexDefinition.GetAnalyser();
                var parser = new MultiFieldQueryParser(Version.LUCENE_30, indexDefinition.SearchableFieldNames, analyser);
                Query query = searchQuery.SearchTerm.SafeGetSearchQuery(parser, analyser);

                booleanQuery.Add(query, Occur.MUST);
            }
            if (searchQuery.BrandId.HasValue)
                booleanQuery.Add(GetBrandQuery(searchQuery.BrandId.Value), Occur.MUST);
            return booleanQuery;
        }
开发者ID:neozhu,项目名称:Ecommerce,代码行数:31,代码来源:GetProductSearchLuceneQuery.cs


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


示例4: Query

        public static SearchResults Query(HttpContext ctx, string query, int page = 1) {
            if (string.IsNullOrWhiteSpace(query)) {
                return new SearchResults {
                    Documents = new SearchResult[0],
                    TotalCount = 0
                };
            }
            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 = GetSafeQuery(parser, 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:DotNetCoderDFW,项目名称:OrchardDoc,代码行数:31,代码来源:SearchHelpers.cs


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


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

        /// <summary>
        /// Performs the explanation.
        /// </summary>
        /// <param name="luceneVersion">The lucene version.</param>
        /// <param name="fsDirectory">The fs directory.</param>
        /// <param name="searchQuery">The search query.</param>
        /// <param name="resultId">The result identifier.</param>
        /// <returns></returns>
        protected virtual string PerformExplain(Version luceneVersion, FSDirectory fsDirectory, string searchQuery, int resultId)
		{
			/*
			 * The obvious problem here is that we're not using the exact same search as the real one.
			 */

			var explanation = string.Empty;

			using (var indexSearcher = new IndexSearcher(fsDirectory, false))
			{
				var analyzer = new StandardAnalyzer(luceneVersion);
				
				var queryParser = new MultiFieldQueryParser(luceneVersion, new[] { "Id".ToLowerInvariant() }, analyzer)
									{
										DefaultOperator = QueryParser.Operator.AND
									};
				
				var query = this.searchQueryParser.ParseQuery(searchQuery, queryParser);

				explanation = indexSearcher.Explain(query, resultId).ToHtml();

				analyzer.Close();
			}

			return explanation;
		}
开发者ID:KaraokeStu,项目名称:LeadPipe.Net,代码行数:34,代码来源:SearchScoreExplainer.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: GetQuery

        public Query GetQuery()
        {
            var booleanQuery = new BooleanQuery
                                   {
                                       {
                                           new TermRangeQuery(
                                           FieldDefinition.GetFieldName<PublishedOnFieldDefinition>(), null,
                                           DateTools.DateToString(CurrentRequestData.Now, DateTools.Resolution.SECOND), false, true),
                                           Occur.MUST
                                       }
                                   };
            if (!String.IsNullOrWhiteSpace(Term))
            {
                var indexDefinition = IndexingHelper.Get<WebpageSearchIndexDefinition>();
                var analyser = indexDefinition.GetAnalyser();
                var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, indexDefinition.SearchableFieldNames, analyser);
                Query query = Term.SafeGetSearchQuery(parser, analyser);

                booleanQuery.Add(query, Occur.MUST);
            }
            if (CreatedOnFrom.HasValue || CreatedOnTo.HasValue)
                booleanQuery.Add(GetDateQuery(), Occur.MUST);
            if (!string.IsNullOrEmpty(Type))
                booleanQuery.Add(new TermQuery(new Term(FieldDefinition.GetFieldName<TypeFieldDefinition>(), Type)),
                                 Occur.MUST);
            if (Parent != null)
                booleanQuery.Add(
                    new TermQuery(new Term(FieldDefinition.GetFieldName<ParentIdFieldDefinition>(), Parent.Id.ToString())), Occur.MUST);

            return booleanQuery;
        }
开发者ID:neozhu,项目名称:MrCMS,代码行数:31,代码来源:WebpageSearchQuery.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: 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


示例12: _search

		// main search method
		private static IEnumerable<SampleData> _search(string searchQuery, string searchField = "") {
			// validation
			if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<SampleData>();

			// set up lucene searcher
			using (var searcher = new IndexSearcher(_directory, false)) {
				var hits_limit = 1000;
				var analyzer = new StandardAnalyzer(Version.LUCENE_29);

				// search by single field
				if (!string.IsNullOrEmpty(searchField)) {
					var parser = new QueryParser(Version.LUCENE_29, searchField, analyzer);
					var query = parseQuery(searchQuery, parser);
					var hits = searcher.Search(query, hits_limit).ScoreDocs;
					var results = _mapLuceneToDataList(hits, searcher);
					analyzer.Close();
					searcher.Close();
					searcher.Dispose();
					return results;
				}
				// search by multiple fields (ordered by RELEVANCE)
				else {
					var parser = new MultiFieldQueryParser
						(Version.LUCENE_29, new[] {"Id", "Name", "Description"}, analyzer);
					var query = parseQuery(searchQuery, parser);
					var hits = searcher.Search(query, null, hits_limit, Sort.INDEXORDER).ScoreDocs;
					var results = _mapLuceneToDataList(hits, searcher);
					analyzer.Close();
					searcher.Close();
					searcher.Dispose();
					return results;
				}
			}
		}
开发者ID:CelticHarp,项目名称:Lucene.Net-search-MVC-sample-site,代码行数:35,代码来源:LuceneSearch.cs


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


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

        private static Query ParseQuery(string searchTerm)
        {
            var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 1.0f}, { "Description", 0.8f }, { "Author", 0.6f } };
            var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
            searchTerm = QueryParser.Escape(searchTerm).ToLowerInvariant();

            var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);

            var conjuctionQuery = new BooleanQuery();
            conjuctionQuery.SetBoost(1.5f);
            var disjunctionQuery = new BooleanQuery();
            var wildCardQuery = new BooleanQuery();
            wildCardQuery.SetBoost(0.7f);
            var exactIdQuery = new TermQuery(new Term("Id-Exact", searchTerm));
            exactIdQuery.SetBoost(2.5f);

            foreach(var term in searchTerm.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                conjuctionQuery.Add(queryParser.Parse(term), BooleanClause.Occur.MUST);
                disjunctionQuery.Add(queryParser.Parse(term), BooleanClause.Occur.SHOULD);

                foreach (var field in fields)
                {
                    var wildCardTermQuery = new WildcardQuery(new Term(field.Key, term + "*"));
                    wildCardTermQuery.SetBoost(0.7f * field.Value);
                    wildCardQuery.Add(wildCardTermQuery, BooleanClause.Occur.SHOULD);
                }
            }

            return conjuctionQuery.Combine(new Query[] { exactIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
        }
开发者ID:N198,项目名称:NugetGallery21-DeleteMe,代码行数:31,代码来源:LuceneSearchService.cs


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


示例17: GetQuery

        public Query GetQuery()
        {
            if (String.IsNullOrWhiteSpace(Term) && String.IsNullOrWhiteSpace(Type) && !CreatedOnTo.HasValue && !CreatedOnFrom.HasValue && Parent == null)
                return new MatchAllDocsQuery();

            var booleanQuery = new BooleanQuery();
            if (!String.IsNullOrWhiteSpace(Term))
            {
                var indexDefinition = IndexingHelper.Get<AdminWebpageIndexDefinition>();
                var analyser = indexDefinition.GetAnalyser();
                var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, indexDefinition.SearchableFieldNames, analyser);
                Query query = Term.SafeGetSearchQuery(parser, analyser);

                booleanQuery.Add(query, Occur.MUST);
            }
            if (CreatedOnFrom.HasValue || CreatedOnTo.HasValue)
                booleanQuery.Add(GetDateQuery(), Occur.MUST);
            if (!string.IsNullOrEmpty(Type))
                booleanQuery.Add(new TermQuery(new Term(FieldDefinition.GetFieldName<TypeFieldDefinition>(), Type)),
                                 Occur.MUST);
            if (Parent != null)
                booleanQuery.Add(
                    new TermQuery(new Term(FieldDefinition.GetFieldName<ParentIdFieldDefinition>(), Parent.Id.ToString())), Occur.MUST);

            return booleanQuery;
        }
开发者ID:neozhu,项目名称:MrCMS,代码行数:26,代码来源:AdminWebpageSearchQuery.cs


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


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


示例20: GenerateLuceneQuery

 public Query GenerateLuceneQuery(string query, ILocationGroupingStrategy groupingStrategy)
 {
     var parser = new MultiFieldQueryParser(Version.LUCENE_29,
      groupingStrategy.Fields.Select(f => f.Name).ToArray(),
      _analyzer);
     parser.DefaultOperator = QueryParser.Operator.AND;
     Query luceneQuery = parser.Parse(query);
     return luceneQuery;
 }
开发者ID:NHSChoices,项目名称:location-service,代码行数:9,代码来源:LucenceIndexManager.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# QueryParsers.QueryParser类代码示例发布时间:2022-05-26
下一篇:
C# Index.TermVectorMapper类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap