Exemple #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));
 }
Exemple #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);
        }
Exemple #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));
        }
Exemple #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));
            }
Exemple #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);
			}
            public void Execute()
            {
                ValidateFacets();

                //We only want to run the base query once, so we capture all of the facet-ing terms then run the query
                //	once through the collector and pull out all of the terms in one shot
                var allCollector = new GatherAllCollector();
                var facetsByName = new Dictionary<string, Dictionary<string, FacetValue>>();


                using (var currentState = Database.IndexStorage.GetCurrentStateHolder(Index))
                {
                    var currentIndexSearcher = currentState.IndexSearcher;

                    var baseQuery = Database.IndexStorage.GetDocumentQuery(Index, IndexQuery, Database.IndexQueryTriggers);
                    currentIndexSearcher.Search(baseQuery, allCollector);
                    var fields = Facets.Values.Select(x => x.Name)
                            .Concat(Ranges.Select(x => x.Key));
                    var fieldsToRead = new HashSet<string>(fields);
                    IndexedTerms.ReadEntriesForFields(currentState,
                        fieldsToRead,
                        allCollector.Documents,
                        (term, doc) =>
                        {
                            var facets = Facets.Values.Where(facet => facet.Name == term.Field);
                            foreach (var facet in facets)
                            {
                                switch (facet.Mode)
                                {
                                    case FacetMode.Default:
                                        var facetValues = facetsByName.GetOrAdd(facet.DisplayName);
                                        FacetValue existing;
                                        if (facetValues.TryGetValue(term.Text, out existing) == false)
                                        {
                                            existing = new FacetValue
                                            {
                                                Range = GetRangeName(term)
                                            };
                                            facetValues[term.Text] = existing;
                                        }
                                        ApplyFacetValueHit(existing, facet, doc, null);
                                        break;
                                    case FacetMode.Ranges:
                                        List<ParsedRange> list;
                                        if (Ranges.TryGetValue(term.Field, out list))
                                        {
                                            for (int i = 0; i < list.Count; i++)
                                            {
                                                var parsedRange = list[i];
                                                if (parsedRange.IsMatch(term.Text))
                                                {
                                                    var facetValue = Results.Results[term.Field].Values[i];
                                                    ApplyFacetValueHit(facetValue, facet, doc, parsedRange);
                                                }
                                            }
                                        }
                                        break;
                                    default:
                                        throw new ArgumentOutOfRangeException();
                                }
                            }

                        });
                    UpdateFacetResults(facetsByName);

                    CompleteFacetCalculationsStage1(currentState);
                    CompleteFacetCalculationsStage2();
                }
            }
Exemple #7
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);
			}
            public void Execute()
            {
                //We only want to run the base query once, so we capture all of the facet-ing terms then run the query
                //	once through the collector and pull out all of the terms in one shot
                var allCollector = new GatherAllCollector();
                var facetsByName = new Dictionary<string, Dictionary<string, FacetValue>>();


                using (var currentState = Database.IndexStorage.GetCurrentStateHolder(Index))
                {
                    var currentIndexSearcher = currentState.IndexSearcher;

                    var baseQuery = Database.IndexStorage.GetLuceneQuery(Index, IndexQuery, Database.IndexQueryTriggers);
                    currentIndexSearcher.Search(baseQuery, allCollector);
                    var fields = Facets.Values.Select(x => x.Name)
                            .Concat(Ranges.Select(x => x.Key));
                    var fieldsToRead = new HashSet<string>(fields);

                    FieldTermVector fieldTermVector;
                    var allVectoredTerms =
                        fieldsToRead.All(s => indexDefinition.TermVectors.TryGetValue(s, out fieldTermVector) && fieldTermVector != FieldTermVector.No);

                    if (allVectoredTerms)
                    {
                        IndexedTerms.ReadEntriesForFieldsFromTermVectors(currentState,
                            fieldsToRead,
                            allCollector.Documents,
                            (field,value, doc) => HandleFacets(field,value, facetsByName, doc));
                    }
                    else
                    {
                        IndexedTerms.ReadEntriesForFields(currentState,
                            fieldsToRead,
                            allCollector.Documents,
                            (field, value, doc) => HandleFacets(field,value, facetsByName, doc));
                    }
                    UpdateFacetResults(facetsByName);

                    CompleteFacetCalculationsStage1(currentState, allVectoredTerms);
                    CompleteFacetCalculationsStage2();
                }
            }
Exemple #9
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);
			}
Exemple #10
0
			public void Execute()
			{
				//We only want to run the base query once, so we capture all of the facet-ing terms then run the query
				//	once through the collector and pull out all of the terms in one shot
				var allCollector = new GatherAllCollector();
				var facetsByName = new Dictionary<string, Dictionary<string, int>>();

				IndexSearcher currentIndexSearcher;
				using (Database.IndexStorage.GetCurrentIndexSearcher(Index, out currentIndexSearcher))
				{
					var baseQuery = Database.IndexStorage.GetLuceneQuery(Index, IndexQuery, Database.IndexQueryTriggers);
					currentIndexSearcher.Search(baseQuery, allCollector);
					var fields = Facets.Values.Select(x => x.Name)
							.Concat(Ranges.Select(x => x.Key));
					var fieldsToRead = new HashSet<string>(fields);
					IndexedTerms.ReadEntriesForFields(currentIndexSearcher.IndexReader,
						fieldsToRead,
						allCollector.Documents,
						term =>
						{
							List<ParsedRange> list;
							if (Ranges.TryGetValue(term.Field, out list))
							{
								for (int i = 0; i < list.Count; i++)
								{
									var parsedRange = list[i];
									if (parsedRange.IsMatch(term.Text))
									{
										Results.Results[term.Field].Values[i].Hits++;
									}
								}
							}

							Facet value;
							if (Facets.TryGetValue(term.Field, out value))
							{
								var facetValues = facetsByName.GetOrAdd(term.Field);
								facetValues[term.Text] = facetValues.GetOrDefault(term.Text) + 1;
							}
						});
				}

				UpdateFacetResults(facetsByName);
			}
Exemple #11
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);
			}