Пример #1
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);
			}
Пример #2
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);
			}
Пример #3
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);
			}
Пример #4
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);
			}