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


C# Search.WildcardQuery类代码示例

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


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

示例1: AddQuery

        /// <summary>
        ///     Adds the query.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="query">The query.</param>
        /// <param name="filter">The filter.</param>
        protected void AddQuery(string fieldName, BooleanQuery query, StringCollection filter)
        {
            fieldName = fieldName.ToLower();
            if (filter.Count > 0)
            {
                if (filter.Count != 1)
                {
                    var booleanQuery = new BooleanQuery();
                    var containsFilter = false;
                    foreach (var index in filter)
                    {
                        if (String.IsNullOrEmpty(index))
                        {
                            continue;
                        }

                        var nodeQuery = new WildcardQuery(new Term(fieldName, index));
                        booleanQuery.Add(nodeQuery, Occur.SHOULD);
                        containsFilter = true;
                    }
                    if (containsFilter)
                    {
                        query.Add(booleanQuery, Occur.MUST);
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(filter[0]))
                    {
                        this.AddQuery(fieldName, query, filter[0].ToLower());
                    }
                }
            }
        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:40,代码来源:BaseSearchQueryBuilder.cs

示例2: FindSuggestionsBySubstring

        /// <summary>
        /// Returns a collection of all suggestions that match the given searchTerm.
        /// A match means search term appears anywhere in the product code or category name.
        /// 
        /// If the searchTerm is null or empty, or doesn't match any categories, than an empty list is returned.
        /// The suggestions will be returned in the correct order.
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <returns></returns>
        public IEnumerable<ISuggestion> FindSuggestionsBySubstring(string searchTerm)
        {
            if (string.IsNullOrEmpty(searchTerm))
            {
                return new List<CategorySuggestion>();
            }

            // The product codes and category names have been stored in upper case. So need to convert search term to upper case as well.
            string searchTermUc = LuceneEscape(searchTerm.ToUpper());

            Query query1 = new WildcardQuery(new Term("UcName", "*" + searchTermUc + "*"));

            // Get the searcher. Access _searcher only once while doing a search. Another request running
            // LoadProductStore could change this property. By accessing once, you are sure your searcher stays the same.
            var searcher = _searcher;

            // Actual search

            TopDocs hits = searcher.Search(query1, searcher.MaxDoc);

            // Return results. ScoreDocs is sorted by relevancy, but we want alphabetic sorting, and category suggestions first.
            IEnumerable<ISuggestion> sortedResults = hits.ScoreDocs
                .Select(d =>
                {
                    var doc = searcher.Doc(d.Doc);
                    return DocToSuggestion(doc);
                })
                .OrderBy(s=>(s is CategorySuggestion ? 0 : 1))
                .ThenBy(s=>s.SortedName);

            return sortedResults;
        }
开发者ID:stephengodbold,项目名称:searchpdproj,代码行数:41,代码来源:SuggestionSearcher.cs

示例3: TestAsterisk

		public virtual void  TestAsterisk()
		{
			RAMDirectory indexStore = GetIndexStore("body", new System.String[]{"metal", "metals"});
			IndexSearcher searcher = new IndexSearcher(indexStore);
			Query query1 = new TermQuery(new Term("body", "metal"));
			Query query2 = new WildcardQuery(new Term("body", "metal*"));
			Query query3 = new WildcardQuery(new Term("body", "m*tal"));
			Query query4 = new WildcardQuery(new Term("body", "m*tal*"));
			Query query5 = new WildcardQuery(new Term("body", "m*tals"));
			
			BooleanQuery query6 = new BooleanQuery();
			query6.Add(query5, false, false);
			
			BooleanQuery query7 = new BooleanQuery();
			query7.Add(query3, false, false);
			query7.Add(query5, false, false);
			
			// Queries do not automatically lower-case search terms:
			Query query8 = new WildcardQuery(new Term("body", "M*tal*"));
			
			AssertMatches(searcher, query1, 1);
			AssertMatches(searcher, query2, 2);
			AssertMatches(searcher, query3, 1);
			AssertMatches(searcher, query4, 2);
			AssertMatches(searcher, query5, 1);
			AssertMatches(searcher, query6, 1);
			AssertMatches(searcher, query7, 2);
			AssertMatches(searcher, query8, 0);
		}
开发者ID:emtees,项目名称:old-code,代码行数:29,代码来源:TestWildcard.cs

示例4: TestAsterisk

        public virtual void TestAsterisk()
        {
            Directory indexStore = GetIndexStore("body", new string[] { "metal", "metals" });
            IndexReader reader = DirectoryReader.Open(indexStore);
            IndexSearcher searcher = NewSearcher(reader);
            Query query1 = new TermQuery(new Term("body", "metal"));
            Query query2 = new WildcardQuery(new Term("body", "metal*"));
            Query query3 = new WildcardQuery(new Term("body", "m*tal"));
            Query query4 = new WildcardQuery(new Term("body", "m*tal*"));
            Query query5 = new WildcardQuery(new Term("body", "m*tals"));

            BooleanQuery query6 = new BooleanQuery();
            query6.Add(query5, BooleanClause.Occur.SHOULD);

            BooleanQuery query7 = new BooleanQuery();
            query7.Add(query3, BooleanClause.Occur.SHOULD);
            query7.Add(query5, BooleanClause.Occur.SHOULD);

            // Queries do not automatically lower-case search terms:
            Query query8 = new WildcardQuery(new Term("body", "M*tal*"));

            AssertMatches(searcher, query1, 1);
            AssertMatches(searcher, query2, 2);
            AssertMatches(searcher, query3, 1);
            AssertMatches(searcher, query4, 2);
            AssertMatches(searcher, query5, 1);
            AssertMatches(searcher, query6, 1);
            AssertMatches(searcher, query7, 2);
            AssertMatches(searcher, query8, 0);
            AssertMatches(searcher, new WildcardQuery(new Term("body", "*tall")), 0);
            AssertMatches(searcher, new WildcardQuery(new Term("body", "*tal")), 1);
            AssertMatches(searcher, new WildcardQuery(new Term("body", "*tal*")), 2);
            reader.Dispose();
            indexStore.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:35,代码来源:TestWildcard.cs

示例5: TestTermWithoutWildcard

        public virtual void TestTermWithoutWildcard()
		{
		    RAMDirectory indexStore = GetIndexStore("field", new System.String[] {"nowildcard", "nowildcardx"});
		    IndexSearcher searcher = new IndexSearcher(indexStore, true);

		    MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
		    AssertMatches(searcher, wq, 1);

		    wq.RewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
		    wq.Boost = 0.1f;
		    Query q = searcher.Rewrite(wq);
		    Assert.IsTrue(q is TermQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);

		    wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
		    wq.Boost = 0.2f;
		    q = searcher.Rewrite(wq);
		    Assert.True(q is ConstantScoreQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);

		    wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
		    wq.Boost = 0.3F;
		    q = searcher.Rewrite(wq);
		    Assert.True(q is ConstantScoreQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);

		    wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
		    wq.Boost = 0.4F;
		    q = searcher.Rewrite(wq);
		    Assert.True(q is ConstantScoreQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);
		}
开发者ID:raol,项目名称:lucene.net,代码行数:32,代码来源:TestWildcard.cs

示例6: TestTermWithoutWildcard

        public virtual void TestTermWithoutWildcard()
        {
            Directory indexStore = GetIndexStore("field", new string[] { "nowildcard", "nowildcardx" });
            IndexReader reader = DirectoryReader.Open(indexStore);
            IndexSearcher searcher = NewSearcher(reader);

            MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
            AssertMatches(searcher, wq, 1);

            wq.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
            wq.Boost = 0.1F;
            Query q = searcher.Rewrite(wq);
            Assert.IsTrue(q is TermQuery);
            Assert.AreEqual(q.Boost, wq.Boost, 0);

            wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
            wq.Boost = 0.2F;
            q = searcher.Rewrite(wq);
            Assert.IsTrue(q is ConstantScoreQuery);
            Assert.AreEqual(q.Boost, wq.Boost, 0.1);

            wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
            wq.Boost = 0.3F;
            q = searcher.Rewrite(wq);
            Assert.IsTrue(q is ConstantScoreQuery);
            Assert.AreEqual(q.Boost, wq.Boost, 0.1);

            wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
            wq.Boost = 0.4F;
            q = searcher.Rewrite(wq);
            Assert.IsTrue(q is ConstantScoreQuery);
            Assert.AreEqual(q.Boost, wq.Boost, 0.1);
            reader.Dispose();
            indexStore.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:35,代码来源:TestWildcard.cs

示例7: VisitWildcardQuery

 public override Query VisitWildcardQuery(WildcardQuery wildcardq)
 {
     _dump.Append("WildcardQ(");
     var q = base.VisitWildcardQuery(wildcardq);
     _dump.Append(BoostToString(q));
     _dump.Append(")");
     return q;
 }
开发者ID:jhuntsman,项目名称:FlexNet,代码行数:8,代码来源:DumpVisitor.cs

示例8: TestTermWithoutWildcard

		public virtual void  TestTermWithoutWildcard()
		{
			RAMDirectory indexStore = GetIndexStore("field", new System.String[]{"nowildcard", "nowildcardx"});
			IndexSearcher searcher = new IndexSearcher(indexStore);
			
			Query wq = new WildcardQuery(new Term("field", "nowildcard"));
			AssertMatches(searcher, wq, 1);
			
			wq = searcher.Rewrite(wq);
			Assert.IsTrue(wq is TermQuery);
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:11,代码来源:TestWildcard.cs

示例9: BuildQuery

        protected override ParameterizedSql BuildQuery(WildcardQuery wildcardQuery)
        {
            var termText = EscapeForSql(wildcardQuery.Term.Text);
            // termText = termText.Replace("*", "%");
            termText = termText.Replace("?", "_");

            var userVariables = new Dictionary<string, string> {{"field1", "\"" + termText + "\""}};

            var sql = "CONTAINS(" + FieldPlaceholder + ", @field1)";
            return new ParameterizedSql(sql, userVariables);
        }
开发者ID:tomvonclef,项目名称:LuceneQueryToSql,代码行数:11,代码来源:SqlServerFullTextQueryBuilder.cs

示例10: BuildQuery

        protected override ParameterizedSql BuildQuery(WildcardQuery wildcardQuery)
        {
            var termText = EscapeForSql(wildcardQuery.Term.Text);
            termText = termText.Replace("*", "%");
            termText = termText.Replace("?", "_");

            var userVariables = new Dictionary<string, string> {{"field1", termText}};

            var sql = FieldPlaceholder + " LIKE '%' + @field1 + '%'";
            return new ParameterizedSql(sql, userVariables);
        }
开发者ID:tomvonclef,项目名称:LuceneQueryToSql,代码行数:11,代码来源:SqlServerQueryBuilder.cs

示例11: GetTextQuery

 protected static BooleanQuery GetTextQuery(SearchUserInput searchUserInput, params string[] fieldNames)
 {
     var masterQuery = new BooleanQuery();
     foreach (string queryTerm in searchUserInput.Terms)
     {
         foreach (string fieldName in fieldNames)
         {
             var query = new WildcardQuery(new Term(fieldName, queryTerm));
             masterQuery.Add(query, searchUserInput.BooleanCombinationLogic);
         }
     }
     return masterQuery;
 }
开发者ID:PublicHealthEngland,项目名称:fingertips-open,代码行数:13,代码来源:SearchEngine.cs

示例12: GetPlaceNameQuery

        protected static BooleanQuery GetPlaceNameQuery(SearchUserInput searchUserInput, int parentAreaTypeId)
        {
            var masterQuery = new BooleanQuery();
            foreach (string queryTerm in searchUserInput.Terms)
            {
                var query = new WildcardQuery(new Term(FieldNames.PlaceName, queryTerm));
                masterQuery.Add(query, searchUserInput.BooleanCombinationLogic);
            }

            var parentAreaTypeIdQuery = new WildcardQuery(new Term("Parent_Area_Code_" + parentAreaTypeId, "x"));
            masterQuery.Add(parentAreaTypeIdQuery, BooleanClause.Occur.MUST_NOT);

            return masterQuery;
        }
开发者ID:PublicHealthEngland,项目名称:fingertips-open,代码行数:14,代码来源:GeographicalSearch.cs

示例13: Build

        public virtual Query Build(IQueryNode queryNode)
        {
            WildcardQueryNode wildcardNode = (WildcardQueryNode)queryNode;

            WildcardQuery q = new WildcardQuery(new Term(wildcardNode.GetFieldAsString(),
                                                 wildcardNode.GetTextAsString()));

            MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.GetTag(MultiTermRewriteMethodProcessor.TAG_ID);
            if (method != null)
            {
                q.SetRewriteMethod(method);
            }

            return q;
        }
开发者ID:apache,项目名称:lucenenet,代码行数:15,代码来源:WildcardQueryNodeBuilder.cs

示例14: TestQuestionmark

        public virtual void  TestQuestionmark()
		{
			RAMDirectory indexStore = GetIndexStore("body", new System.String[]{"metal", "metals", "mXtals", "mXtXls"});
			IndexSearcher searcher = new IndexSearcher(indexStore);
			Query query1 = new WildcardQuery(new Term("body", "m?tal"));
			Query query2 = new WildcardQuery(new Term("body", "metal?"));
			Query query3 = new WildcardQuery(new Term("body", "metals?"));
			Query query4 = new WildcardQuery(new Term("body", "m?t?ls"));
			Query query5 = new WildcardQuery(new Term("body", "M?t?ls"));
			
			AssertMatches(searcher, query1, 1);
			AssertMatches(searcher, query2, 2);
			AssertMatches(searcher, query3, 1);
			AssertMatches(searcher, query4, 3);
			AssertMatches(searcher, query5, 0);
		}
开发者ID:emtees,项目名称:old-code,代码行数:16,代码来源:TestWildcard.cs

示例15: GetHint

 public ActionResult GetHint(string term)
 {
     if (!string.IsNullOrEmpty(term))
     {
         var seacher = new Seacher(dataFolder);
         WildcardQuery nameQuery = new WildcardQuery(new Term("Name", "*" + term + "*"));
         var Result = seacher.Search(nameQuery, 5);
         Result.SearchResultItems.OrderBy(x => x.Type);
         if (Result.SearchResultItems.Count > 0)
         {
             Result.SearchResultItems.OrderBy(x => x.Type);
             return Json(Result.SearchResultItems);
         }
     }
     return new JsonResult
     {
         Data = new { OK = false }
     };
 }
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:19,代码来源:SearchController.cs


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