Example #1
0
 private static TopDocs ExecuteQuery(IndexSearcher searcher, Query luceneQuery, int start, int pageSize, SortedField[] sortedFields)
 {
     if (pageSize == int.MaxValue)    // we want all docs
     {
         var gatherAllCollector = new GatherAllCollector();
         searcher.Search(luceneQuery, gatherAllCollector);
         return(gatherAllCollector.ToTopDocs());
     }
     // NOTE: We get Start + Pagesize results back so we have something to page on
     if (sortedFields != null && sortedFields.Length > 0)
     {
         var sort = new Sort(sortedFields.Select(x => x.ToLuceneSortField()).ToArray());
         return(searcher.Search(luceneQuery, null, pageSize + start, sort));
     }
     return(searcher.Search(luceneQuery, null, pageSize + start));
 }
Example #2
0
        private static TopDocs ExecuteQuery(IndexSearcher searcher, IndexQuery indexQuery, Query luceneQuery)
        {
        	if(indexQuery.PageSize == int.MaxValue) // we want all docs
        	{
        		var gatherAllCollector = new GatherAllCollector();
        		searcher.Search(luceneQuery, gatherAllCollector);
        		return gatherAllCollector.ToTopDocs();
        	}
            // NOTE: We get Start + Pagesize results back so we have something to page on
			if (indexQuery.SortedFields != null && indexQuery.SortedFields.Length > 0)
            {
                var sort = new Sort(indexQuery.SortedFields.Select(x => x.ToLuceneSortField()).ToArray());
                return searcher.Search(luceneQuery, null, indexQuery.PageSize + indexQuery.Start, sort);
            }
        	return searcher.Search(luceneQuery, null, indexQuery.PageSize + indexQuery.Start);
        }
Example #3
0
        private TopDocs ExecuteQuery(IndexSearcher indexSearcher, Query luceneQuery, int start, int pageSize, IndexQuery indexQuery)
        {
            Filter filter = indexQuery.GetFilter();
            Sort   sort   = indexQuery.GetSort(filter, indexDefinition);

            if (pageSize == int.MaxValue)             // we want all docs
            {
                var gatherAllCollector = new GatherAllCollector();
                indexSearcher.Search(luceneQuery, filter, gatherAllCollector);
                return(gatherAllCollector.ToTopDocs());
            }
            // NOTE: We get Start + Pagesize results back so we have something to page on
            if (sort != null)
            {
                return(indexSearcher.Search(luceneQuery, filter, pageSize + start, sort));
            }
            return(indexSearcher.Search(luceneQuery, filter, pageSize + start));
        }
Example #4
0
            private TopDocs ExecuteQuery(IndexSearcher indexSearcher, Query luceneQuery, int start, int pageSize,
                                         IndexQuery indexQuery)
            {
                var sort = indexQuery.GetSort(parent.indexDefinition);

                if (pageSize == Int32.MaxValue)                 // we want all docs
                {
                    var gatherAllCollector = new GatherAllCollector();
                    indexSearcher.Search(luceneQuery, gatherAllCollector);
                    return(gatherAllCollector.ToTopDocs());
                }
                var minPageSize = Math.Max(pageSize + start, 1);

                // NOTE: We get Start + Pagesize results back so we have something to page on
                if (sort != null)
                {
                    var ret = indexSearcher.Search(luceneQuery, null, minPageSize, sort);
                    return(ret);
                }
                return(indexSearcher.Search(luceneQuery, null, minPageSize));
            }
Example #5
0
			private TopDocs ExecuteQuery(IndexSearcher indexSearcher, Query luceneQuery, int start, int pageSize,
										IndexQuery indexQuery)
			{
				var sort = indexQuery.GetSort(parent.indexDefinition, parent.viewGenerator);

				if (pageSize == Int32.MaxValue && sort == null) // we want all docs, no sorting required
				{
					var gatherAllCollector = new GatherAllCollector();
					indexSearcher.Search(luceneQuery, gatherAllCollector);
					return gatherAllCollector.ToTopDocs();
				}
			    int absFullPage = Math.Abs(pageSize + start); // need to protect against ridicilously high values of pageSize + start that overflow
			    var minPageSize = Math.Max(absFullPage, 1);

				// NOTE: We get Start + Pagesize results back so we have something to page on
				if (sort != null)
				{
					try
					{
						//indexSearcher.SetDefaultFieldSortScoring (sort.GetSort().Contains(SortField.FIELD_SCORE), false);
						indexSearcher.SetDefaultFieldSortScoring(true, false);
						var ret = indexSearcher.Search(luceneQuery, null, minPageSize, sort);
						return ret;
					}
					finally
					{
						indexSearcher.SetDefaultFieldSortScoring(false, false);
					}
				}
				return indexSearcher.Search(luceneQuery, null, minPageSize);
			}
Example #6
0
			private TopDocs ExecuteQuery(IndexSearcher indexSearcher, Query luceneQuery, int start, int pageSize,
			                             IndexQuery indexQuery)
			{
				Filter filter = indexQuery.GetFilter();
				Sort sort = indexQuery.GetSort(filter, parent.indexDefinition);

				if (pageSize == Int32.MaxValue) // we want all docs
				{
					var gatherAllCollector = new GatherAllCollector();
					indexSearcher.Search(luceneQuery, filter, gatherAllCollector);
					return gatherAllCollector.ToTopDocs();
				}
				// NOTE: We get Start + Pagesize results back so we have something to page on
				if (sort != null)
				{
					return indexSearcher.Search(luceneQuery, filter, pageSize + start, sort);
				}
				return indexSearcher.Search(luceneQuery, filter, pageSize + start);
			}
Example #7
0
			private TopDocs ExecuteQuery(IndexSearcher indexSearcher, Query luceneQuery, int start, int pageSize,
										IndexQuery indexQuery)
			{
				var sort = indexQuery.GetSort(parent.indexDefinition);

				if (pageSize == Int32.MaxValue) // we want all docs
				{
					var gatherAllCollector = new GatherAllCollector();
					indexSearcher.Search(luceneQuery, gatherAllCollector);
					return gatherAllCollector.ToTopDocs();
				}
				var minPageSize = Math.Max(pageSize + start, 1);

				// NOTE: We get Start + Pagesize results back so we have something to page on
				if (sort != null)
				{
					try
					{
						//indexSearcher.SetDefaultFieldSortScoring (sort.GetSort().Contains(SortField.FIELD_SCORE), false);
						indexSearcher.SetDefaultFieldSortScoring(true, false);
						var ret = indexSearcher.Search(luceneQuery, null, minPageSize, sort);
						return ret;
					}
					finally
					{
						indexSearcher.SetDefaultFieldSortScoring(false, false);
					}
				}
				return indexSearcher.Search(luceneQuery, null, minPageSize);
			}
Example #8
0
			private TopDocs ExecuteQuery(IndexSearcher indexSearcher, Query luceneQuery, int start, int pageSize,
										IndexQuery indexQuery)
			{
				if (pageSize == Int32.MaxValue) // we want all docs
				{
					var gatherAllCollector = new GatherAllCollector();
					indexSearcher.Search(luceneQuery, gatherAllCollector);
					return gatherAllCollector.ToTopDocs();
				}
				var minPageSize = Math.Max(pageSize + start, 1);

				if (indexQuery.SortedFields != null || indexQuery.SortedFields.Count() > 0)
				{
					if (indexQuery.SortByAggregation == SortFieldAggregation.UseInOrder)
					{
						Sort sort = indexQuery.GetSort(parent.indexDefinition);

						// NOTE: We get Start + Pagesize results back so we have something to page on
						if (sort != null)
						{
							try
							{
								//indexSearcher.SetDefaultFieldSortScoring (sort.GetSort().Contains(SortField.FIELD_SCORE), false);
								indexSearcher.SetDefaultFieldSortScoring(true, false);
								var ret = indexSearcher.Search(luceneQuery, null, minPageSize, sort);
								return ret;
							}
							finally
							{
								indexSearcher.SetDefaultFieldSortScoring(false, false);
							}
						}
					}
					else if (indexQuery.SortByAggregation == SortFieldAggregation.UseMaximum
							 || indexQuery.SortByAggregation == SortFieldAggregation.UseMinimum)
					{
						var minMaxSortAggregationQuery = new AggregateFieldsScoreQuery(
							luceneQuery, 
							indexQuery.SortedFields.Select(f => f.Field).ToArray(), 
							indexQuery.SortByAggregation);

						return indexSearcher.Search(minMaxSortAggregationQuery, null, minPageSize);
					}
				}

				return indexSearcher.Search(luceneQuery, null, minPageSize);
			}