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

C# Search.BooleanQuery类代码示例

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

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



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

示例1: BuildQuery

 public static Query BuildQuery(string query)
 {
     var matchCollection = untokenizedQuery.Matches(query);
     if (matchCollection.Count == 0)
         return new QueryParser(Version.LUCENE_CURRENT, "", new StandardAnalyzer(Version.LUCENE_CURRENT)).Parse(query);
     var sb = new StringBuilder(query);
     var booleanQuery = new BooleanQuery();
     foreach (Match match in matchCollection)
     {
         BooleanClause.Occur occur;
         switch (match.Groups[1].Value)
         {
             case "+":
                 occur=BooleanClause.Occur.MUST;
                 break;
             case "-":
                 occur=BooleanClause.Occur.MUST_NOT;
                 break;
             default:
                 occur=BooleanClause.Occur.SHOULD;
                 break;
         }
         booleanQuery.Add(new TermQuery(new Term(match.Groups[2].Value, match.Groups[3].Value)), occur);
         sb.Replace(match.Value, "");
     }
     var remaining = sb.ToString().Trim();
     if(remaining.Length > 0)
     {
         booleanQuery.Add(new QueryParser(Version.LUCENE_CURRENT, "", new StandardAnalyzer(Version.LUCENE_CURRENT)).Parse(remaining), BooleanClause.Occur.SHOULD);
     }
     return booleanQuery;
 }
开发者ID:kenegozi,项目名称:ravendb,代码行数:32,代码来源:QueryBuilder.cs


示例2: TestNullOrSubScorer

		public virtual void  TestNullOrSubScorer()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
			Document doc = new Document();
			doc.Add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
			w.AddDocument(doc);
			IndexReader r = w.GetReader();
			IndexSearcher s = new IndexSearcher(r);
			BooleanQuery q = new BooleanQuery();
			q.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
			
			// PhraseQuery w/ no terms added returns a null scorer
			PhraseQuery pq = new PhraseQuery();
			q.Add(pq, BooleanClause.Occur.SHOULD);
			Assert.AreEqual(1, s.Search(q, 10).TotalHits);
			
			// A required clause which returns null scorer should return null scorer to
			// IndexSearcher.
			q = new BooleanQuery();
			pq = new PhraseQuery();
			q.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
			q.Add(pq, BooleanClause.Occur.MUST);
			Assert.AreEqual(0, s.Search(q, 10).TotalHits);
			
			DisjunctionMaxQuery dmq = new DisjunctionMaxQuery(1.0f);
			dmq.Add(new TermQuery(new Term("field", "a")));
			dmq.Add(pq);
			Assert.AreEqual(1, s.Search(dmq, 10).TotalHits);
			
			r.Close();
			w.Close();
			dir.Close();
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:34,代码来源:TestBooleanQuery.cs


示例3: TestQuery

		public virtual void  TestQuery()
		{
			RAMDirectory dir = new RAMDirectory();
			IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true);
			AddDoc("one", iw);
			AddDoc("two", iw);
			AddDoc("three four", iw);
			iw.Close();
			
			IndexSearcher is_Renamed = new IndexSearcher(dir);
			Hits hits = is_Renamed.Search(new MatchAllDocsQuery());
			Assert.AreEqual(3, hits.Length());
			
			// some artificial queries to trigger the use of skipTo():
			
			BooleanQuery bq = new BooleanQuery();
			bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
			bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
			hits = is_Renamed.Search(bq);
			Assert.AreEqual(3, hits.Length());
			
			bq = new BooleanQuery();
			bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
			bq.Add(new TermQuery(new Term("key", "three")), BooleanClause.Occur.MUST);
			hits = is_Renamed.Search(bq);
			Assert.AreEqual(1, hits.Length());
			
			// delete a document:
			is_Renamed.GetIndexReader().DeleteDocument(0);
			hits = is_Renamed.Search(new MatchAllDocsQuery());
			Assert.AreEqual(2, hits.Length());
			
			is_Renamed.Close();
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:34,代码来源:TestMatchAllDocsQuery.cs


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


示例5: TestBQ14

 public virtual void TestBQ14()
 {
     BooleanQuery q = new BooleanQuery(true);
     q.Add(new TermQuery(new Term(FIELD, "QQQQQ")), BooleanClause.Occur.SHOULD);
     q.Add(new TermQuery(new Term(FIELD, "w1")), BooleanClause.Occur.SHOULD);
     Qtest(q, new int[] { 0, 1, 2, 3 });
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:TestSimpleExplanations.cs


示例6: Get

        public IEnumerable<BeerReview> Get(string reviewText = null, int limit = 10, double minAroma = 0, double minAppearance = 0, double minOverall = 0, double minTaste = 0, double minPalate = 0)
        {
            var query = new BooleanQuery();
            Query reviewTextQuery = new TermQuery(new Term("reviewText", reviewText));
            Query reviewAppearanceQuery = NumericRangeQuery.NewDoubleRange("reviewAppearance", minAppearance, null, minInclusive: true, maxInclusive: true);
            Query reviewAromaQuery = NumericRangeQuery.NewDoubleRange("reviewAroma", minAroma, null, minInclusive: true, maxInclusive: true);
            Query reviewPalateQuery = NumericRangeQuery.NewDoubleRange("reviewPalate", minPalate, null, minInclusive: true, maxInclusive: true);
            Query reviewTasteQuery = NumericRangeQuery.NewDoubleRange("reviewTaste", minTaste, null, minInclusive: true, maxInclusive: true);
            Query reviewOverallQuery = NumericRangeQuery.NewDoubleRange("reviewOverall", minOverall, null, minInclusive: true, maxInclusive: true);

            if (reviewText != null) { query.Add(reviewTextQuery, Occur.MUST); }
            query.Add(reviewAppearanceQuery, Occur.MUST);
            query.Add(reviewAromaQuery, Occur.MUST);
            query.Add(reviewOverallQuery, Occur.MUST);
            query.Add(reviewPalateQuery, Occur.MUST);
            query.Add(reviewTasteQuery, Occur.MUST);

            var hits = indexSearcher.Search(query, limit);

            var beers = new List<BeerReview>();

            for (int i = 0; i < hits.ScoreDocs.Count(); i++)
            {
                beers.Add(BeerReviewFromDoc(hits.ScoreDocs[i]));
            }

            return beers;
        }
开发者ID:ramhemasri,项目名称:bigdatahackathon2013,代码行数:28,代码来源:BeerController.cs


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


示例8: AddDateRangeQuery

        internal static void AddDateRangeQuery(BooleanQuery query, DateRangeSearchParam.DateRangeField dateRangeField, BooleanClause.Occur occurance)
        {
            var startDateTime = dateRangeField.StartDate;
            if (dateRangeField.InclusiveStart)
            {
                if (startDateTime != DateTime.MinValue)
                {
                    startDateTime.ChangeTime(0, 0, 0, 0);
                }
            }

            var endDateTime = dateRangeField.EndDate;
            if (dateRangeField.InclusiveStart)
            {
                if (endDateTime != DateTime.MaxValue)
                {
                    endDateTime = endDateTime.ChangeTime(23, 59, 59, 59);
                }
            }

            BooleanQuery.SetMaxClauseCount(int.MaxValue);

            if (!(dateRangeField.StartDate == DateTime.MinValue && dateRangeField.EndDate == DateTime.MaxValue))
            {
                query.Add(new RangeQuery(new Term(SearchFieldIDs.CreatedDate, startDateTime.ToString("yyyyMMdd")), new Term(SearchFieldIDs.CreatedDate, endDateTime.ToString("yyyyMMdd")), true), occurance);
            }
        }
开发者ID:udt1106,项目名称:Sitecore-Item-Buckets,代码行数:27,代码来源:SearcherMethods.cs


示例9: FilterQueryByClasses

        public static Lucene.Net.Search.Query FilterQueryByClasses(ISet<System.Type> classesAndSubclasses, Lucene.Net.Search.Query luceneQuery)
        {
            // A query filter is more practical than a manual class filtering post query (esp on scrollable resultsets)
            // it also probably minimise the memory footprint
            if (classesAndSubclasses == null)
            {
                return luceneQuery;
            }

            BooleanQuery classFilter = new BooleanQuery();

            // annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
            classFilter.SetBoost(0);
            foreach (System.Type clazz in classesAndSubclasses)
            {
                Term t = new Term(DocumentBuilder.CLASS_FIELDNAME, TypeHelper.LuceneTypeName(clazz));
                TermQuery termQuery = new TermQuery(t);
                classFilter.Add(termQuery, BooleanClause.Occur.SHOULD);
            }

            BooleanQuery filteredQuery = new BooleanQuery();
            filteredQuery.Add(luceneQuery, BooleanClause.Occur.MUST);
            filteredQuery.Add(classFilter, BooleanClause.Occur.MUST);
            return filteredQuery;
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:25,代码来源:FullTextSearchHelper.cs


示例10: Build

        public virtual Query Build(IQueryNode queryNode)
        {
            StandardBooleanQueryNode booleanNode = (StandardBooleanQueryNode)queryNode;

            BooleanQuery bQuery = new BooleanQuery(booleanNode.DisableCoord);
            IList<IQueryNode> children = booleanNode.GetChildren();

            if (children != null)
            {
                foreach (IQueryNode child in children)
                {
                    object obj = child.GetTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

                    if (obj != null)
                    {
                        Query query = (Query)obj;

                        try
                        {
                            bQuery.Add(query, GetModifierValue(child));
                        }
                        catch (BooleanQuery.TooManyClauses ex)
                        {
                            throw new QueryNodeException(new MessageImpl(
                                QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery
                                    .MaxClauseCount, queryNode
                                    .ToQueryString(new EscapeQuerySyntaxImpl())), ex);
                        }
                    }
                }
            }

            return bQuery;
        }
开发者ID:apache,项目名称:lucenenet,代码行数:34,代码来源:StandardBooleanQueryNodeBuilder.cs


示例11: Decorate

 /// <summary>
 /// Decorates the specified query adding context information.
 /// </summary>
 /// <param name="query">The source query.</param>
 /// <returns>The decorated query.</returns>
 public Lucene.Net.Search.Query Decorate(Lucene.Net.Search.Query query)
 {
     BooleanQuery result = new BooleanQuery(true);
       result.Add(query, Occur.MUST);
       this.AddDecorations(result);
       return result;
 }
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:12,代码来源:SearchContext.cs


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


示例13: TestMethod

        public virtual void TestMethod()
        {
            Directory directory = NewDirectory();

            string[] values = new string[] { "1", "2", "3", "4" };

            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, Similarity, TimeZone);
            for (int i = 0; i < values.Length; i++)
            {
                Document doc = new Document();
                doc.Add(NewStringField(FIELD, values[i], Field.Store.YES));
                writer.AddDocument(doc);
            }
            IndexReader ir = writer.Reader;
            writer.Dispose();

            BooleanQuery booleanQuery1 = new BooleanQuery();
            booleanQuery1.Add(new TermQuery(new Term(FIELD, "1")), BooleanClause.Occur.SHOULD);
            booleanQuery1.Add(new TermQuery(new Term(FIELD, "2")), BooleanClause.Occur.SHOULD);

            BooleanQuery query = new BooleanQuery();
            query.Add(booleanQuery1, BooleanClause.Occur.MUST);
            query.Add(new TermQuery(new Term(FIELD, "9")), BooleanClause.Occur.MUST_NOT);

            IndexSearcher indexSearcher = NewSearcher(ir);
            ScoreDoc[] hits = indexSearcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(2, hits.Length, "Number of matched documents");
            ir.Dispose();
            directory.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:30,代码来源:TestBooleanScorer.cs


示例14: TestMethod

		public virtual void  TestMethod()
		{
			RAMDirectory directory = new RAMDirectory();
			
			System.String[] values = new System.String[]{"1", "2", "3", "4"};
			
			try
			{
				IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
				for (int i = 0; i < values.Length; i++)
				{
					Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
					doc.Add(new Field(FIELD, values[i], Field.Store.YES, Field.Index.UN_TOKENIZED));
					writer.AddDocument(doc);
				}
				writer.Close();
				
				BooleanQuery booleanQuery1 = new BooleanQuery();
				booleanQuery1.Add(new TermQuery(new Term(FIELD, "1")), BooleanClause.Occur.SHOULD);
				booleanQuery1.Add(new TermQuery(new Term(FIELD, "2")), BooleanClause.Occur.SHOULD);
				
				BooleanQuery query = new BooleanQuery();
				query.Add(booleanQuery1, BooleanClause.Occur.MUST);
				query.Add(new TermQuery(new Term(FIELD, "9")), BooleanClause.Occur.MUST_NOT);
				
				IndexSearcher indexSearcher = new IndexSearcher(directory);
				Hits hits = indexSearcher.Search(query);
				Assert.AreEqual(2, hits.Length(), "Number of matched documents");
			}
			catch (System.IO.IOException e)
			{
				Assert.Fail(e.Message);
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:34,代码来源:TestBooleanScorer.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: AddDecorations

    /// <summary>
    /// Adds the decorations to the BooleanQuery object. Override in derived class to change the way context affects queries.
    /// </summary>
    /// <param name="result">The result.</param>
    protected override void AddDecorations(BooleanQuery result)
    {
      Assert.ArgumentNotNull(result, "result");
      User user = this.User;
      if (user != null)
      {
        result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Creator, user.Name)), Occur.SHOULD);
        result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Editor, user.Name)), Occur.SHOULD);
      }

      Item item = this.Item;
      if (item != null)
      {
        result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Path, ShortID.Encode(item.ID).ToLowerInvariant())), Occur.MUST);
        result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Database, item.Database.Name)), Occur.MUST);
        // result.Add(new TermQuery(new Term(BuiltinFields.Language, item.Language.ToString())), Occur.MUST);
      }

      if (!this.IgnoreContentEditorOptions)
      {
        if (!UserOptions.View.ShowHiddenItems)
        {
          result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Hidden, "1")), Occur.MUST_NOT);
        }

        if (!UserOptions.View.ShowEntireTree && (item != null))
        {
          Item item2 = item.Database.GetItem(RootSections.GetSection(item));
          if (item2 != null)
          {
            result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Path, ShortID.Encode(item2.ID).ToLowerInvariant())), Occur.MUST);
          }
        }
      }
    }
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:39,代码来源:LuceneSearchContext.cs


示例17: AndExtension

        public void AndExtension()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            BooleanQuery innerQuery = new BooleanQuery();

            Term term = new Term("_name", "value1");
            TermQuery termQuery1 = new TermQuery(term);
            innerQuery.Add(termQuery1, Occur.MUST);

            Term term2 = new Term("_name", "value2");
            TermQuery termQuery2 = new TermQuery(term2);
            innerQuery.Add(termQuery2, Occur.MUST);

            originalQuery.Add(innerQuery, Occur.MUST);
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            builder.And
                (
                    x => x.Term("_name", "value1"),
                    x => x.Term("_name", "value2")
                );
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

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


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


示例19: TestOutOfOrderDocsScoringSort

        public virtual void TestOutOfOrderDocsScoringSort()
        {
            // Two Sort criteria to instantiate the multi/single comparators.
            Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() };
            bool[][] tfcOptions = new bool[][] { new bool[] { false, false, false }, new bool[] { false, false, true }, new bool[] { false, true, false }, new bool[] { false, true, true }, new bool[] { true, false, false }, new bool[] { true, false, true }, new bool[] { true, true, false }, new bool[] { true, true, true } };
            string[] actualTFCClasses = new string[] { "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector" };

            BooleanQuery bq = new BooleanQuery();
            // Add a Query with SHOULD, since bw.Scorer() returns BooleanScorer2
            // which delegates to BS if there are no mandatory clauses.
            bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
            // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
            // the clause instead of BQ.
            bq.MinimumNumberShouldMatch = 1;
            for (int i = 0; i < sort.Length; i++)
            {
                for (int j = 0; j < tfcOptions.Length; j++)
                {
                    TopDocsCollector<Entry> tdc = TopFieldCollector.Create(sort[i], 10, tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);

                    Assert.IsTrue(tdc.GetType().Name.EndsWith(actualTFCClasses[j]));

                    @is.Search(bq, tdc);

                    TopDocs td = tdc.TopDocs();
                    ScoreDoc[] sd = td.ScoreDocs;
                    Assert.AreEqual(10, sd.Length);
                }
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:30,代码来源:TestTopFieldCollector.cs


示例20: BuildQuery

		public static Query BuildQuery(string query)
		{
			var untokenizedMatches = untokenizedQuery.Matches(query);
			var rangeMatches = rangeQuery.Matches(query);
		    var standardAnalyzer = new StandardAnalyzer(Version.LUCENE_29);
		    try
		    {
                if (untokenizedMatches.Count == 0 && rangeMatches.Count == 0)
                    return new QueryParser(Version.LUCENE_29, "", standardAnalyzer).Parse(query);
                var sb = new StringBuilder(query);
                var booleanQuery = new BooleanQuery();
                AddUntokenizedTerms(untokenizedMatches, booleanQuery, sb, query);
		    	AddRangeTerms(rangeMatches, booleanQuery, sb, query);
                var remaining = sb.ToString();
		    	remaining = hangingConditionAtStart.Replace(remaining, "");
		    	remaining = hangingConditionAtEnd.Replace(remaining, "");
				remaining = remaining.Trim();
		    	if (remaining.Length > 0)
                {
                    booleanQuery.Add(new QueryParser(Version.LUCENE_29, "", standardAnalyzer).Parse(remaining), BooleanClause.Occur.SHOULD);
                }
                return booleanQuery;
		    }
		    finally
		    {
		        standardAnalyzer.Close();
		    }
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:28,代码来源:QueryBuilder.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Search.Collector类代码示例发布时间:2022-05-26
下一篇:
C# Search.BooleanClause类代码示例发布时间: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