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


C# Search.Query类代码示例

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


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

示例1: HandleMethods

		private static Query HandleMethods(Query query)
		{
			var termQuery = query as TermQuery;
			if (termQuery != null && termQuery.Term.Field.StartsWith("@"))
			{
				return HandleMethodsForQueryAndTerm(query, termQuery.Term);
			}
			var wildcardQuery = query as WildcardQuery;
			if (wildcardQuery != null)
			{
				return HandleMethodsForQueryAndTerm(query, wildcardQuery.Term);
			}
			var booleanQuery = query as BooleanQuery;
			if (booleanQuery != null)
			{
				foreach (var c in booleanQuery.Clauses)
				{
					c.Query = HandleMethods(c.Query);
				}
				var requiresMerging = booleanQuery.Clauses.All(x => x.Query is IRavenLuceneMethodQuery);
				if (requiresMerging == false)
					return booleanQuery;
				if (booleanQuery.Clauses.Count == 0)
					return booleanQuery;
				var first = (IRavenLuceneMethodQuery)booleanQuery.Clauses[0].Query;
				var ravenLuceneMethodQuery = booleanQuery.Clauses.Skip(1).Aggregate(first, (methodQuery, clause) => methodQuery.Merge(clause.Query));
				return (Query)ravenLuceneMethodQuery;
			}
			return query;
		}
开发者ID:Trebornide,项目名称:ravendb,代码行数:30,代码来源:QueryBuilder.cs

示例2: Search

        public SearchResult Search(Query searchQuery, int maxHits, string NameField = "Name", Sort sort = null)
        {
            SearchResult result = new SearchResult();
            TopDocs hits = null;
            result.SearchResultItems = new List<SearchResultItem>();
            if(sort != null)
            {
                hits = seacher.Search(searchQuery, null, maxHits, sort);
            }
            else
            {
                hits = seacher.Search(searchQuery, null, maxHits);
            }
            for (int i = 0; i < hits.ScoreDocs.Count(); i++)
            {
                Document doctemp = seacher.Doc(hits.ScoreDocs[i].Doc);
                result.SearchResultItems.Add(new SearchResultItem
                {
                    Id = int.Parse(doctemp.Get("Id")),
                    Name = doctemp.Get(NameField),
                    Type = (DocumentType) Enum.Parse(typeof(DocumentType), doctemp.Get("Type"))
                });
            }
            result.Hits = hits.ScoreDocs.Count();

            return result;
        }
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:27,代码来源:Seacher.cs

示例3: RunQuery

      public virtual List<SkinnyItem> RunQuery(Query query, bool showAllVersions)
      {
         Assert.ArgumentNotNull(Index, "Aqueduct.SitecoreLib");

         var items = new List<SkinnyItem>();

         try
         {
            using (var context = new IndexSearchContext(Index))
            {
               var hits = context.Search(query);

               if (hits == null)
               {
                  return null;
               }

               var resultCollection = hits.FetchResults(0, hits.Length);
               SearchHelper.GetItemsFromSearchResult(resultCollection, items, showAllVersions);
            }
         }
         catch (Exception exception)
         {
            Log.Error("Aqueduct.SitecoreLib. There was a problem while running a search query. Details: " + exception.Message, this);
            Log.Error(exception.StackTrace, this);
            throw;
         }

         return items;
      }
开发者ID:aqueduct,项目名称:Aqueduct.SitecoreLib,代码行数:30,代码来源:Searcher.cs

示例4: Get

        public List<int> Get(Query searchQuery)
        {
            var indexSearcher = _productSearcher.IndexSearcher;
            var name = FieldDefinition.GetFieldName<ProductSearchCategoriesDefinition>();
            var valueCollector = new ValueCollector(indexSearcher, name);
            indexSearcher.Search(searchQuery, valueCollector);
            var categoryIds = valueCollector.Values[name].Select(s => Convert.ToInt32(s)).Distinct().ToList();

            if (!categoryIds.Any())
                return categoryIds;

            var mainQuery = new BooleanQuery();
            var idsQuery = new BooleanQuery();
            const string idFieldName = "id";
            foreach (var categoryId in categoryIds)
            {
                idsQuery.Add(new TermQuery(new Term(idFieldName, categoryId.ToString())), Occur.SHOULD);
            }
            mainQuery.Add(idsQuery, Occur.MUST);

            var publishedOn = FieldDefinition.GetFieldName<PublishedOnFieldDefinition>();
            mainQuery.Add(new TermRangeQuery(
                                           publishedOn, null,
                                           DateTools.DateToString(CurrentRequestData.Now, DateTools.Resolution.SECOND), false, true), Occur.MUST);
            var webpageSearcher = _indexSearcher.IndexSearcher;
            var webpageValueCollector = new ValueCollector(webpageSearcher, idFieldName);
            webpageSearcher.Search(mainQuery, null, webpageValueCollector);

            return webpageValueCollector.Values[idFieldName].Select(s => Convert.ToInt32(s))
                .Intersect(categoryIds)
                .ToList();
        }
开发者ID:neozhu,项目名称:Ecommerce,代码行数:32,代码来源:GetProductCategories.cs

示例5: SetUp

 public override void SetUp()
 {
     base.SetUp();
     INDEX_SIZE = AtLeast(2000);
     Index = NewDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(Random(), Index);
     RandomGen random = new RandomGen(this, Random());
     for (int i = 0; i < INDEX_SIZE; ++i) // don't decrease; if to low the
     {
         // problem doesn't show up
         Document doc = new Document();
         if ((i % 5) != 0) // some documents must not have an entry in the first
         {
             // sort field
             doc.Add(NewStringField("publicationDate_", random.LuceneDate, Field.Store.YES));
         }
         if ((i % 7) == 0) // some documents to match the query (see below)
         {
             doc.Add(NewTextField("content", "test", Field.Store.YES));
         }
         // every document has a defined 'mandant' field
         doc.Add(NewStringField("mandant", Convert.ToString(i % 3), Field.Store.YES));
         writer.AddDocument(doc);
     }
     Reader = writer.Reader;
     writer.Dispose();
     Query = new TermQuery(new Term("content", "test"));
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:28,代码来源:TestCustomSearcherSort.cs

示例6: Filter

        public List<FacetReturn> Filter(Query query, List<SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
        {
            var buckets = new List<SitecoreItem>();
            using (var searcher = new IndexSearcher(Constants.Index.Name))
            {
                if (locationFilter.IsNotEmpty())
                {
                    buckets.AddRange(
                        searcher.GetItemsViaFieldQuery("isbucket", "1", 200).Value.Where(item => item.GetItem().IsNotNull()).Where(
                            itm => Context.ContentDatabase.GetItem(locationFilter).Axes.IsAncestorOf(itm.GetItem())));
                }
            }

            var bucketsSelectToList = buckets.OrderBy(i => i.GetItem().Name).Select(item => item.GetItem().ID.ToString()).ToList();

            var returnFacets = this.GetSearch(query, bucketsSelectToList, searchQuery, locationFilter, baseQuery).Select(
                          facet =>
                          new FacetReturn
                          {
                              KeyName = Context.ContentDatabase.GetItem(facet.Key).Name,
                              Value = facet.Value.ToString(),
                              Type = "location",
                              ID = facet.Key
                          });

            return returnFacets.ToList();
        }
开发者ID:csteeg,项目名称:Sitecore-Item-Buckets,代码行数:27,代码来源:LocationFacet.cs

示例7: Hits

 internal Hits(Searcher s, Query q, Filter f)
 {
     weight = q.Weight(s);
     searcher = s;
     filter = f;
     GetMoreDocs(50); // retrieve 100 initially
 }
开发者ID:vineelkovvuri,项目名称:ExtendableDesktopSearch,代码行数:7,代码来源:Hits.cs

示例8: RunQuery

        private IList<SearchResult> RunQuery(Query query)
        {
            // If two threads ran this method simultaneously, there would be issues with this.IndexReader.
            // Alternatively, there could be one RAMDirectory per filesystem directory.
            lock (this)
            {
                IndexReader newReader = this.indexReader.Reopen();
                if (newReader != this.indexReader)
                {
                    this.indexReader.Dispose();
                    this.indexReader = newReader;
                }

                IndexSearcher searcher; searcher = new IndexSearcher(newReader);
                if (query == null)
                {
                    return new List<SearchResult>();
                }
                TopDocs hits = searcher.Search(query, 1000);

                return hits.ScoreDocs
                    .Select(scoreDoc => searcher.Doc(scoreDoc.Doc).Get(FullTextFieldType.Path.ToString()))
                    .Select(path => new SearchResult(path))
                    .ToList();
            }
        }
开发者ID:c0ns0le,项目名称:PsISEProjectExplorer,代码行数:26,代码来源:FullTextDirectory.cs

示例9: LuceneSearchResults

 /// <summary>
 ///     Initializes a new instance of the <see cref="SearchResults" /> class.
 /// </summary>
 /// <param name="searcher">The searcher.</param>
 /// <param name="reader">The reader.</param>
 /// <param name="docs">The hits.</param>
 /// <param name="criteria">The criteria.</param>
 /// <param name="query">The query.</param>
 public LuceneSearchResults(Searcher searcher, IndexReader reader, TopDocs docs, ISearchCriteria criteria, Query query)
 {
     Results = new SearchResults(criteria, null);
     CreateDocuments(searcher, docs);
     CreateFacets(reader, query);
     CreateSuggestions(reader, criteria);
 }
开发者ID:sameerkattel,项目名称:vc-community,代码行数:15,代码来源:LuceneSearchResults.cs

示例10: CheckHits_

		public static void  CheckHits_(Query query, System.String defaultFieldName, Searcher searcher, int[] results, TestCase testCase)
		{
            Hits hits = searcher.Search(query);
			
            System.Collections.Hashtable correct = new System.Collections.Hashtable();
            for (int i = 0; i < results.Length; i++)
            {
                correct.Add((System.Int32) results[i], null);
            }
			
            System.Collections.Hashtable actual = new System.Collections.Hashtable();
            for (int i = 0; i < hits.Length(); i++)
            {
                actual.Add((System.Int32) hits.Id(i), null);
            }
			
            //Assert.AreEqual(correct, actual, query.ToString(defaultFieldName));
            if (correct.Count != 0)
            {
                System.Collections.IDictionaryEnumerator iter = correct.GetEnumerator();
                bool status = false;
                while (iter.MoveNext())
                {
                    status = actual.ContainsKey(iter.Key);
                    if (status == false)
                        break;
                }
                Assert.IsTrue(status, query.ToString(defaultFieldName));
            }
        }
开发者ID:emtees,项目名称:old-code,代码行数:30,代码来源:CheckHits.cs

示例11: ToChildBlockJoinQuery

 /// <summary>
 /// Create a ToChildBlockJoinQuery.
 /// </summary>
 /// <param name="parentQuery">Query that matches parent documents</param>
 /// <param name="parentsFilter">Filter (must produce FixedBitSet per-segment, like <see cref="FixedBitSetCachingWrapperFilter"/>) 
 /// identifying the parent documents.</param>
 /// <param name="doScores">True if parent scores should be calculated.</param>
 public ToChildBlockJoinQuery(Query parentQuery, Filter parentsFilter, bool doScores)
 {
     _origParentQuery = parentQuery;
     _parentQuery = parentQuery;
     _parentsFilter = parentsFilter;
     _doScores = doScores;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:14,代码来源:ToChildBlockJoinQuery.cs

示例12: BoostingQuery

        private readonly Query match; // query to match

        #endregion Fields

        #region Constructors

        public BoostingQuery(Query match, Query context, float boost)
        {
            this.match = match;
            this.context = (Query) context.Clone(); // clone before boost
            this.boost = boost;
            this.context.Boost = 0.0f; // ignore context-only matches
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:BoostingQuery.cs

示例13: BuildQuery

        /// <summary>
        /// 构建Query、Filter、Sort
        /// </summary>
        /// <param name="query"><see cref="Query"/></param>
        /// <param name="filter"><see cref="Filter"/></param>
        /// <param name="sort"><see cref="Sort"/></param>
        public void BuildQuery(out Query query, out Filter filter, out Sort sort)
        {
            BooleanQuery q = new BooleanQuery();
            foreach (var clause in clauses)
            {
                q.Add(clause);
            }
            query = q;

            if (filters.Count > 0)
            {
                BooleanQuery filterQuery = new BooleanQuery();
                foreach (var _filter in filters)
                    filterQuery.Add(_filter);

                filter = new QueryWrapperFilter(filterQuery);
            }
            else
            {
                filter = null;
            }

            if (sortFields.Count > 0)
                sort = new Sort(sortFields.ToArray());
            else
                sort = null;
        }
开发者ID:ClaytonWang,项目名称:Dw3cSNS,代码行数:33,代码来源:LuceneSearchBuilder.cs

示例14: SearchResults

        internal SearchResults(Query query, IEnumerable<SortField> sortField, Searcher searcher, int maxResults)
        {
            LuceneQuery = query;

            LuceneSearcher = searcher;
            DoSearch(query, sortField, maxResults);
        }
开发者ID:rhayesbite,项目名称:Examine,代码行数:7,代码来源:SearchResults.cs

示例15: TermsQuery

 /// <summary>
 /// 
 /// </summary>
 /// <param name="field">The field that should contain terms that are specified in the previous parameter.</param>
 /// <param name="fromQuery"></param>
 /// <param name="terms">The terms that matching documents should have. The terms must be sorted by natural order.</param>
 internal TermsQuery(string field, Query fromQuery, BytesRefHash terms)
     : base(field)
 {
     _fromQuery = fromQuery;
     _terms = terms;
     _ords = terms.Sort(BytesRef.UTF8SortedAsUnicodeComparer);
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:TermsQuery.cs


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