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


C# TermQuery.SetBoost方法代码示例

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


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

示例1: Rewrite

		public override Query Rewrite(IndexReader reader)
		{
			BooleanQuery query = new BooleanQuery(true);
			TermEnum enumerator = reader.Terms(prefix);
			try
			{
				System.String prefixText = prefix.Text();
				System.String prefixField = prefix.Field();
				do 
				{
					Term term = enumerator.Term();
#if !FRAMEWORK_1_1
                    if (term != null && term.Text().StartsWith(prefixText, StringComparison.Ordinal) && term.Field() == prefixField)
#else
                    if (term != null && term.Text().StartsWith(prefixText) && term.Field() == prefixField)
#endif
                    {
						TermQuery tq = new TermQuery(term); // found a match
						tq.SetBoost(GetBoost()); // set the boost
						query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
						//System.out.println("added " + term);
					}
					else
					{
						break;
					}
				}
				while (enumerator.Next());
			}
			finally
			{
				enumerator.Close();
			}
			return query;
		}
开发者ID:zweib730,项目名称:beagrep,代码行数:35,代码来源:PrefixQuery.cs

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

示例3: BoostedCaseInsensitiveMandatoryTerm

        public void BoostedCaseInsensitiveMandatoryTerm()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "value");
            TermQuery termQuery = new TermQuery(term);
            originalQuery.Add(termQuery, BooleanClause.Occur.MUST);
            termQuery.SetBoost(10);
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            builder.Setup(x => x.Term("_name", "Value", boost:10));
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:simonproctor,项目名称:Lucinq,代码行数:17,代码来源:EquivalencyTests.cs

示例4: Rewrite

		public override Query Rewrite(IndexReader reader)
		{
			FilteredTermEnum enumerator = GetEnum(reader);
			BooleanQuery query = new BooleanQuery(true);
			try
			{
				do 
				{
					Term t = enumerator.Term();
					if (t != null)
					{
						TermQuery tq = new TermQuery(t); // found a match
						tq.SetBoost(GetBoost() * enumerator.Difference()); // set the boost
						query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
					}
				}
				while (enumerator.Next());
			}
			finally
			{
				enumerator.Close();
			}
			return query;
		}
开发者ID:zweib730,项目名称:beagrep,代码行数:24,代码来源:MultiTermQuery.cs

示例5: Expand

		/// <summary> Perform synonym expansion on a query.
		/// 
		/// </summary>
		/// <param name="">query
		/// </param>
		/// <param name="">syns
		/// </param>
		/// <param name="">a
		/// </param>
		/// <param name="">field
		/// </param>
		/// <param name="">boost
		/// </param>
		public static Query Expand(System.String query, Searcher syns, Analyzer a, System.String field, float boost)
		{
			System.Collections.Hashtable already = new System.Collections.Hashtable(); // avoid dups		
			System.Collections.IList top = new System.Collections.ArrayList(); // needs to be separately listed..
			
			// [1] Parse query into separate words so that when we expand we can avoid dups
			TokenStream ts = a.TokenStream(field, new System.IO.StringReader(query));
			Lucene.Net.Analysis.Token t;
			while ((t = ts.Next()) != null)
			{
				System.String word = t.TermText();
				if (already.Contains(word) == false)
				{
					already.Add(word, word);
					top.Add(word);
				}
			}
			BooleanQuery tmp = new BooleanQuery();
			
			// [2] form query
			System.Collections.IEnumerator it = top.GetEnumerator();
			while (it.MoveNext())
			{
				// [2a] add to level words in
				System.String word = (System.String) it.Current;
				TermQuery tq = new TermQuery(new Term(field, word));
				tmp.Add(tq, BooleanClause.Occur.SHOULD);
				
				// [2b] add in unique synonums
				Hits hits = syns.Search(new TermQuery(new Term(Syns2Index.F_WORD, word)));
				for (int i = 0; i < hits.Length(); i++)
				{
					Document doc = hits.Doc(i);
					System.String[] values = doc.GetValues(Syns2Index.F_SYN);
					for (int j = 0; j < values.Length; j++)
					{
						System.String syn = values[j];
						if (already.Contains(syn) == false)
						{
							already.Add(syn, syn);
							tq = new TermQuery(new Term(field, syn));
							if (boost > 0)
							// else keep normal 1.0
								tq.SetBoost(boost);
							tmp.Add(tq, BooleanClause.Occur.SHOULD);
						}
					}
				}
			}
			
			
			return tmp;
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:66,代码来源:SynLookup.cs

示例6: ParseQuery

        private static Query ParseQuery(string searchTerm)
        {
            var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 0.8f }, { "Description", 0.1f },
                                                         { "Author", 1.0f } };
            var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
            var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);

            var conjuctionQuery = new BooleanQuery();
            conjuctionQuery.SetBoost(2.0f);
            var disjunctionQuery = new BooleanQuery();
            disjunctionQuery.SetBoost(0.1f);
            var wildCardQuery = new BooleanQuery();
            wildCardQuery.SetBoost(0.5f);

            // Escape the entire term we use for exact searches.
            var escapedSearchTerm = Escape(searchTerm);
            var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
            exactIdQuery.SetBoost(2.5f);
            var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));

            foreach(var term in GetSearchTerms(searchTerm))
            {
                var termQuery = queryParser.Parse(term);
                conjuctionQuery.Add(termQuery, BooleanClause.Occur.MUST);
                disjunctionQuery.Add(termQuery, 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);
                }
            }

            var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
            return new CustomScoreQuery(conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery }),
                                       downloadCountBooster);
        }
开发者ID:jimitndiaye,项目名称:NuGetGallery,代码行数:38,代码来源:LuceneSearchService.cs

示例7: ParseQuery

        private static Query ParseQuery(SearchFilter searchFilter)
        {
            var fields = new[] { "Id", "Title", "Tags", "Description", "Author" };
            var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
            var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);

            // All terms in the multi-term query appear in at least one of the fields.
            var conjuctionQuery = new BooleanQuery();
            conjuctionQuery.SetBoost(2.0f);

            // Some terms in the multi-term query appear in at least one of the fields.
            var disjunctionQuery = new BooleanQuery();
            disjunctionQuery.SetBoost(0.1f);

            // Suffix wildcard search e.g. jquer*
            var wildCardQuery = new BooleanQuery();
            wildCardQuery.SetBoost(0.5f);

            // Escape the entire term we use for exact searches.
            var escapedSearchTerm = Escape(searchFilter.SearchTerm);
            var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
            exactIdQuery.SetBoost(2.5f);
            var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));

            foreach (var term in GetSearchTerms(searchFilter.SearchTerm))
            {
                var termQuery = queryParser.Parse(term);
                conjuctionQuery.Add(termQuery, BooleanClause.Occur.MUST);
                disjunctionQuery.Add(termQuery, BooleanClause.Occur.SHOULD);

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

            // Create an OR of all the queries that we have
            var combinedQuery = conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });

            if (searchFilter.SortProperty == SortProperty.Relevance)
            {
                // If searching by relevance, boost scores by download count.
                var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
                return new CustomScoreQuery(combinedQuery, downloadCountBooster);
            }
            return combinedQuery;
        }
开发者ID:nnieslan,项目名称:NuGetGallery,代码行数:49,代码来源:LuceneSearchService.cs

示例8: BuildGeneralQuery

        private static Query BuildGeneralQuery(
            bool doExactId,
            string originalSearchText,
            Analyzer analyzer,
            IEnumerable<NuGetSearchTerm> generalTerms, 
            IEnumerable<Query> generalQueries)
        {
            // All terms in the multi-term query appear in at least one of the target fields.
            var conjuctionQuery = new BooleanQuery();
            conjuctionQuery.SetBoost(2.0f);

            // Some terms in the multi-term query appear in at least one of the target fields.
            var disjunctionQuery = new BooleanQuery();
            disjunctionQuery.SetBoost(0.1f);

            // Suffix wildcard search e.g. jquer*
            var wildCardQuery = new BooleanQuery();
            wildCardQuery.SetBoost(0.5f);

            string escapedExactId = originalSearchText.ToLowerInvariant();

            Query exactIdQuery = null;
            Query wildCardIdQuery = null;
            if (doExactId)
            {
                exactIdQuery = new TermQuery(new Term("Id-Exact", escapedExactId));
                exactIdQuery.SetBoost(7.5f);

                wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedExactId + "*"));
            }

            Query nearlyExactIdQuery = null;
            if (generalTerms.Any())
            {
                string escapedApproximateId = string.Join(" ", generalTerms.Select(c => c.TermOrPhrase));
                nearlyExactIdQuery = AnalysisHelper.GetFieldQuery(analyzer, "Id", escapedApproximateId);
                nearlyExactIdQuery.SetBoost(2.0f);
            }

            foreach (var termQuery in generalQueries)
            {
                conjuctionQuery.Add(termQuery, BooleanClause.Occur.MUST);
                disjunctionQuery.Add(termQuery, BooleanClause.Occur.SHOULD);
            }

            var sanitizedTerms = generalTerms.Select(c => c.TermOrPhrase.ToLowerInvariant());
            foreach (var sanitizedTerm in sanitizedTerms)
            {
                foreach (var field in Fields)
                {
                    var wildCardTermQuery = new WildcardQuery(new Term(field, sanitizedTerm + "*"));
                    wildCardTermQuery.SetBoost(0.7f);
                    wildCardQuery.Add(wildCardTermQuery, BooleanClause.Occur.SHOULD);
                }
            }

            // OR of all the applicable queries
            var queries = new Query[]
            {
                exactIdQuery, wildCardIdQuery, nearlyExactIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery
            };

            var queriesToCombine = queries.Where(q => !IsDegenerateQuery(q));
            var query = conjuctionQuery.Combine(queriesToCombine.ToArray());
            return query;
        }
开发者ID:argsv,项目名称:NuGetGallery,代码行数:66,代码来源:LuceneSearchService.cs

示例9: Rewrite

			public override Query Rewrite(IndexReader reader, MultiTermQuery query)
			{
				
				FilteredTermEnum enumerator = query.GetEnum(reader);
				BooleanQuery result = new BooleanQuery(true);
				int count = 0;
				try
				{
					do 
					{
						Term t = enumerator.Term();
						if (t != null)
						{
							TermQuery tq = new TermQuery(t); // found a match
							tq.SetBoost(query.GetBoost() * enumerator.Difference()); // set the boost
							result.Add(tq, BooleanClause.Occur.SHOULD); // add to query
							count++;
						}
					}
					while (enumerator.Next());
				}
				finally
				{
					enumerator.Close();
				}
				query.IncTotalNumberOfTerms(count);
				return result;
			}
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:28,代码来源:MultiTermQuery.cs

示例10: Add

 /// <summary> Add a clause to a boolean query.</summary>
 private static void Add(BooleanQuery q, System.String k, System.String v, float boost)
 {
     Query tq = new TermQuery(new Term(k, v));
     tq.SetBoost(boost);
     q.Add(new BooleanClause(tq, BooleanClause.Occur.SHOULD));
 }
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:7,代码来源:SpellChecker.cs

示例11: TestFilteredQuery_Renamed

		public virtual void  TestFilteredQuery_Renamed()
		{
			Query filteredquery = new FilteredQuery(query, filter);
			ScoreDoc[] hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			Assert.AreEqual(1, hits[0].doc);
			QueryUtils.Check(filteredquery, searcher);
			
			hits = searcher.Search(filteredquery, null, 1000, new Sort("sorter")).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			Assert.AreEqual(1, hits[0].doc);
			
			filteredquery = new FilteredQuery(new TermQuery(new Term("field", "one")), filter);
			hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(2, hits.Length);
			QueryUtils.Check(filteredquery, searcher);
			
			filteredquery = new FilteredQuery(new TermQuery(new Term("field", "x")), filter);
			hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			Assert.AreEqual(3, hits[0].doc);
			QueryUtils.Check(filteredquery, searcher);
			
			filteredquery = new FilteredQuery(new TermQuery(new Term("field", "y")), filter);
			hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(0, hits.Length);
			QueryUtils.Check(filteredquery, searcher);
			
			// test boost
			Filter f = NewStaticFilterA();
			
			float boost = 2.5f;
			BooleanQuery bq1 = new BooleanQuery();
			TermQuery tq = new TermQuery(new Term("field", "one"));
			tq.SetBoost(boost);
			bq1.Add(tq, Occur.MUST);
			bq1.Add(new TermQuery(new Term("field", "five")), Occur.MUST);
			
			BooleanQuery bq2 = new BooleanQuery();
			tq = new TermQuery(new Term("field", "one"));
			filteredquery = new FilteredQuery(tq, f);
			filteredquery.SetBoost(boost);
			bq2.Add(filteredquery, Occur.MUST);
			bq2.Add(new TermQuery(new Term("field", "five")), Occur.MUST);
			AssertScoreEquals(bq1, bq2);
			
			Assert.AreEqual(boost, filteredquery.GetBoost(), 0);
			Assert.AreEqual(1.0f, tq.GetBoost(), 0); // the boost value of the underlying query shouldn't have changed 
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:49,代码来源:TestFilteredQuery.cs

示例12: Rewrite

        public override Query Rewrite(IndexReader reader)
        {
            BooleanQuery query = new BooleanQuery(true);
            TermEnum enumerator = reader.Terms(lowerTerm);

            try
            {

                bool checkLower = false;
                if (!inclusive)
                // make adjustments to set to exclusive
                    checkLower = true;

                System.String testField = GetField();

                do
                {
                    Term term = enumerator.Term();
                    if (term != null && term.Field() == testField)
                    {
                        if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
                        {
                            checkLower = false;
                            if (upperTerm != null)
                            {
                                int compare = String.CompareOrdinal(upperTerm.Text(), term.Text());
                                /* if beyond the upper term, or is exclusive and
                                * this is equal to the upper term, break out */
                                if ((compare < 0) || (!inclusive && compare == 0))
                                    break;
                            }
                            TermQuery tq = new TermQuery(term); // found a match
                            tq.SetBoost(GetBoost()); // set the boost
                            query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return query;
        }
开发者ID:karino2,项目名称:wikipediaconv,代码行数:49,代码来源:RangeQuery.cs

示例13: Rewrite

		public override Query Rewrite(IndexReader reader)
		{
			FilteredTermEnum enumerator = GetEnum(reader);
			int maxClauseCount = BooleanQuery.GetMaxClauseCount();
			ScoreTermQueue stQueue = new ScoreTermQueue(maxClauseCount);
			
			try
			{
				do 
				{
					float minScore = 0.0f;
					float score = 0.0f;
					Term t = enumerator.Term();
					if (t != null)
					{
						score = enumerator.Difference();
						// terms come in alphabetical order, therefore if queue is full and score
						// not bigger than minScore, we can skip
						if (stQueue.Size() < maxClauseCount || score > minScore)
						{
							stQueue.Insert(new ScoreTerm(t, score));
							minScore = ((ScoreTerm) stQueue.Top()).score; // maintain minScore
						}
					}
				}
				while (enumerator.Next());
			}
			finally
			{
				enumerator.Close();
			}
			
			BooleanQuery query = new BooleanQuery(true);
			int size = stQueue.Size();
			for (int i = 0; i < size; i++)
			{
				ScoreTerm st = (ScoreTerm) stQueue.Pop();
				TermQuery tq = new TermQuery(st.term); // found a match
				tq.SetBoost(GetBoost() * st.score); // set the boost
				query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
			}
			
			return query;
		}
开发者ID:ArsenShnurkov,项目名称:beagle-1,代码行数:44,代码来源:FuzzyQuery.cs

示例14: AddTermToQuery

 private void AddTermToQuery(Term term, BooleanQuery query)
 {
     TermQuery tq = new TermQuery(term); // found a match
     tq.SetBoost(GetBoost()); // set the boost
     query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
 }
开发者ID:cqm0609,项目名称:lucene-file-finder,代码行数:6,代码来源:RangeQuery.cs

示例15: CreateWeight

		protected internal override Weight CreateWeight(Searcher searcher)
		{
			if (terms.Count == 1)
			{
				// optimize one-term case
				Term term = (Term) terms[0];
				Query termQuery = new TermQuery(term);
				termQuery.SetBoost(GetBoost());
				return termQuery.CreateWeight(searcher);
			}
			return new PhraseWeight(this, searcher);
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:12,代码来源:PhraseQuery.cs


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