/// <summary> /// Initializes a new instance of the <see cref="IndexDocument"/> class. /// </summary> public IndexDocument() { this.luceneDoc = new Lucene29.Net.Documents.Document(); this.luceneDoc.SetBoost(StaticValues.DefaultBoost); }
/// <summary> /// Retrieves data from this index. /// </summary> /// <param name="topNResults">The number of results to return from this index</param> /// <param name="buildFieldFiltersFromAllData">Specifies whether distinct values from all fields should be stored, even if all actual results are not returned from the index</param> /// <param name="filterFieldNames">The field names to build filters from</param> /// <returns>A <see cref="IndexLibrary.SearchResultDataSet"/> that contains all data from this index</returns> /// <remarks> /// filterFieldNames was added as a parameter to allow you to only pull data from specific fields into the filters, /// this can significantly increase the performance and the total amount of time required by this method. /// </remarks> public virtual SearchResultDataSet ReadDocuments(int topNResults, bool buildFieldFiltersFromAllData, string[] filterFieldNames) { if (this.isDisposed) { throw new ObjectDisposedException("IndexReader", "You cannot call RetrieveIndex(int, string[], bool) from a disposed IndexReader"); } if (topNResults == -1) { topNResults = this.TotalDocuments; } if (topNResults <= 0) { return(new SearchResultDataSet()); } bool filterAll = (filterFieldNames == null || filterFieldNames.Length == 0); SearchResultDataSet dataSet = new SearchResultDataSet(); int resultsToCollect = this.TotalDocuments; if (OnBeginRead(new ReaderEventArgs(this.index.IndexDirectory.FullName, topNResults, buildFieldFiltersFromAllData, filterFieldNames))) { OnEndRead(new ReaderEventArgs(this.index.IndexDirectory.FullName, topNResults, buildFieldFiltersFromAllData, filterFieldNames)); LibraryAnalysis.Fire(new ReadInfo(this.index.IndexDirectory.FullName, resultsToCollect, this.TotalDocuments, buildFieldFiltersFromAllData, this.IsOptimized)); return(dataSet); } if (!buildFieldFiltersFromAllData && topNResults < this.TotalDocuments) { resultsToCollect = topNResults; } LibraryAnalysis.Fire(new ReadInfo(this.index.IndexDirectory.FullName, topNResults, this.TotalDocuments, buildFieldFiltersFromAllData, this.isDisposed)); for (int i = 0; i < resultsToCollect; i++) { bool pastWantedResults = (buildFieldFiltersFromAllData && i >= topNResults); Lucene29.Net.Documents.Document document = this.luceneReader.Document(i); System.Collections.IList fieldList = document.GetFields(); Dictionary <string, string> values = new Dictionary <string, string>(); int totalValues = 0; int totalFields = fieldList.Count; for (int j = 0; j < totalFields; j++) { if (fieldList[j] == null) { continue; } Lucene29.Net.Documents.Field field = fieldList[j] as Lucene29.Net.Documents.Field; string name = field.Name(); string value = field.StringValue(); if (filterAll || filterFieldNames.Contains(name)) { SearchResultFilter filter = null; if (!dataSet.ContainsFilter(name)) { filter = new SearchResultFilter(name); dataSet.AddFilter(filter); } else { filter = dataSet.GetFilter(name); } if (!filter.ContainsKey(value)) { filter.AddValue(new KeyValuePair <string, bool>(value, true)); } } if (values.ContainsKey(name)) { int revision = 1; while (values.ContainsKey(name + "(" + revision.ToString() + ")")) { revision++; } name += "(" + revision.ToString() + ")"; } values.Add(name, value); if (OnReadResultFound(new ReaderEventArgs(this.index.IndexDirectory.FullName, topNResults, buildFieldFiltersFromAllData, filterFieldNames))) { OnEndRead(new ReaderEventArgs(this.index.IndexDirectory.FullName, topNResults, buildFieldFiltersFromAllData, filterFieldNames)); LibraryAnalysis.Fire(new ReadInfo(this.index.IndexDirectory.FullName, resultsToCollect, this.TotalDocuments, buildFieldFiltersFromAllData, this.IsOptimized)); return(dataSet); } ++totalValues; } if (totalValues > 0 && !pastWantedResults) { dataSet.AddSearchResult(new SearchResult(values, this.index.IndexDirectory.FullName, 1f)); } } OnEndRead(new ReaderEventArgs(this.index.IndexDirectory.FullName, topNResults, buildFieldFiltersFromAllData, filterFieldNames)); return(dataSet); }
/// <summary> /// Initializes a new instance of the <see cref="IndexDocument"/> class. /// </summary> public IndexDocument() { this.luceneDoc = new Lucene29.Net.Documents.Document(); this.luceneDoc.SetBoost(StaticValues.DefaultBoost); }