public void TestConcurrentSpan() { String TEXT = "the fox jumped"; Directory directory = NewDirectory(); IndexWriter indexWriter = new IndexWriter(directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))); try { Document document = new Document(); FieldType customType = new FieldType(TextField.TYPE_NOT_STORED); customType.StoreTermVectorOffsets = (true); customType.StoreTermVectorPositions = (true); customType.StoreTermVectors = (true); document.Add(new Field(FIELD, new TokenStreamConcurrent(), customType)); indexWriter.AddDocument(document); } finally { indexWriter.Dispose(); } IndexReader indexReader = DirectoryReader.Open(directory); try { assertEquals(1, indexReader.NumDocs); IndexSearcher indexSearcher = NewSearcher(indexReader); Query phraseQuery = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term(FIELD, "fox")), new SpanTermQuery(new Term(FIELD, "jumped")) }, 0, true); FixedBitSet bitset = new FixedBitSet(indexReader.MaxDoc); indexSearcher.Search(phraseQuery, new ConcurrentSpanCollectorAnonymousHelper(this, bitset)); assertEquals(1, bitset.Cardinality()); int maxDoc = indexReader.MaxDoc; Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); for (int position = bitset.NextSetBit(0); position >= 0 && position < maxDoc - 1; position = bitset .NextSetBit(position + 1)) { assertEquals(0, position); TokenStream tokenStream = TokenSources.GetTokenStream( indexReader.GetTermVector(position, FIELD), false); assertEquals(highlighter.GetBestFragment(new TokenStreamConcurrent(), TEXT), highlighter.GetBestFragment(tokenStream, TEXT)); } } finally { indexReader.Dispose(); directory.Dispose(); } }
public void TestSparseSpan() { String TEXT = "the fox did not jump"; Directory directory = NewDirectory(); IndexWriter indexWriter = new IndexWriter(directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))); try { Document document = new Document(); FieldType customType = new FieldType(TextField.TYPE_NOT_STORED); customType.StoreTermVectorOffsets = (true); customType.StoreTermVectorPositions = (true); customType.StoreTermVectors = (true); document.Add(new Field(FIELD, new TokenStreamSparse(), customType)); indexWriter.AddDocument(document); } finally { indexWriter.Dispose(); } IndexReader indexReader = DirectoryReader.Open(directory); try { assertEquals(1, indexReader.NumDocs); IndexSearcher indexSearcher = NewSearcher(indexReader); Query phraseQuery = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term(FIELD, "did")), new SpanTermQuery(new Term(FIELD, "jump")) }, 0, true); TopDocs hits = indexSearcher.Search(phraseQuery, 1); assertEquals(0, hits.TotalHits); Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); TokenStream tokenStream = TokenSources .GetTokenStream(indexReader.GetTermVector( 0, FIELD), false); assertEquals( highlighter.GetBestFragment(new TokenStreamSparse(), TEXT), highlighter.GetBestFragment(tokenStream, TEXT)); } finally { indexReader.Dispose(); directory.Dispose(); } }
public IEnumerable<Hit> Search(string query, int maxResults) { var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29); QueryParser qp = new QueryParser( Lucene.Net.Util.Version.LUCENE_29, "contents", analyzer ); Query q = qp.Parse(query); TopDocs top = searcher.Search(q, maxResults); List<Hit> result = new List<Hit>(); foreach (var scoreDoc in top.ScoreDocs) { var doc = searcher.Doc(scoreDoc.Doc); string contents = doc.Get("contents"); var scorer = new QueryScorer(q, searcher.IndexReader, "contents"); var highlighter = new Highlighter(scorer); result.Add(new Hit() { Relevance = scoreDoc.Score, Title = doc.Get("title"), Url = doc.Get("path"), Excerpt = highlighter.GetBestFragment(analyzer, "contents", contents) }); } return result; }
public void TestOverlapWithOffset() { String TEXT = "the fox did not jump"; Directory directory = NewDirectory(); IndexWriter indexWriter = new IndexWriter(directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, null)); try { Document document = new Document(); FieldType customType = new FieldType(TextField.TYPE_NOT_STORED); customType.StoreTermVectors = (true); customType.StoreTermVectorOffsets = (true); document.Add(new Field(FIELD, new OverlappingTokenStream(), customType)); indexWriter.AddDocument(document); } finally { indexWriter.Dispose(); } IndexReader indexReader = DirectoryReader.Open(directory); assertEquals(1, indexReader.NumDocs); IndexSearcher indexSearcher = NewSearcher(indexReader); try { DisjunctionMaxQuery query = new DisjunctionMaxQuery(1); query.Add(new SpanTermQuery(new Term(FIELD, "{fox}"))); query.Add(new SpanTermQuery(new Term(FIELD, "fox"))); // final Query phraseQuery = new SpanNearQuery(new SpanQuery[] { // new SpanTermQuery(new Term(FIELD, "{fox}")), // new SpanTermQuery(new Term(FIELD, "fox")) }, 0, true); TopDocs hits = indexSearcher.Search(query, 1); assertEquals(1, hits.TotalHits); Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(query)); TokenStream tokenStream = TokenSources .GetTokenStream( indexReader.GetTermVector(0, FIELD), false); assertEquals("<B>the fox</B> did not jump", highlighter.GetBestFragment(tokenStream, TEXT)); } finally { indexReader.Dispose(); directory.Dispose(); } }
public static IndexItemCollection Search( int siteId, bool isAdminContentAdminOrSiteEditor, List<string> userRoles, Guid[] featureGuids, DateTime modifiedBeginDate, DateTime modifiedEndDate, string queryText, bool highlightResults, int highlightedFragmentSize, int pageNumber, int pageSize, int maxClauseCount, out int totalHits, out bool invalidQuery) { invalidQuery = false; totalHits = 0; IndexItemCollection results = new IndexItemCollection(); if (string.IsNullOrEmpty(queryText)) { return results; } using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId)) { if (!IndexReader.IndexExists(searchDirectory)) { return results; } long startTicks = DateTime.Now.Ticks; try { if (maxClauseCount != 1024) { BooleanQuery.MaxClauseCount = maxClauseCount; } // there are different analyzers for different languages // see LuceneSettings.config in the root of the web LuceneSettingsProvider provider = LuceneSettingsManager.Providers[GetSiteProviderName(siteId)]; Analyzer analyzer = provider.GetAnalyzer(); Query searchQuery = MultiFieldQueryParser.Parse( Lucene.Net.Util.Version.LUCENE_30, new string[] { queryText, queryText, queryText, queryText, queryText, queryText.Replace("*", string.Empty) }, new string[] { "Title", "ModuleTitle", "contents", "PageName", "PageMetaDesc", "Keyword" }, analyzer); BooleanQuery filterQuery = new BooleanQuery(); // won't be used to score the results if (!isAdminContentAdminOrSiteEditor) // skip role filters for these users { AddRoleFilters(userRoles, filterQuery); AddModuleRoleFilters(userRoles, filterQuery); } TermRangeQuery beginDateFilter = new TermRangeQuery( "PublishBeginDate", DateTime.MinValue.ToString("s"), DateTime.UtcNow.ToString("s"), true, true); filterQuery.Add(beginDateFilter, Occur.MUST); TermRangeQuery endDateFilter = new TermRangeQuery( "PublishEndDate", DateTime.UtcNow.ToString("s"), DateTime.MaxValue.ToString("s"), true, true); filterQuery.Add(endDateFilter, Occur.MUST); if ((modifiedBeginDate.Date > DateTime.MinValue.Date) || (modifiedEndDate.Date < DateTime.MaxValue.Date)) { TermRangeQuery lastModifiedDateFilter = new TermRangeQuery( "LastModUtc", modifiedBeginDate.Date.ToString("s"), modifiedEndDate.Date.ToString("s"), true, true); filterQuery.Add(lastModifiedDateFilter, Occur.MUST); } //if ((!DisableSearchFeatureFilters) && (featureGuid != Guid.Empty)) //{ // BooleanQuery featureFilter = new BooleanQuery(); // featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.MUST); // filterQuery.Add(featureFilter, Occur.MUST); //} if ((featureGuids != null) && (featureGuids.Length > 0)) { BooleanQuery featureFilter = new BooleanQuery(); foreach (Guid featureGuid in featureGuids) { featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.SHOULD); } filterQuery.Add(featureFilter, Occur.MUST); } Filter filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores using (IndexSearcher searcher = new IndexSearcher(searchDirectory)) { //http://stackoverflow.com/questions/9872933/migrating-lucene-hitcollector-2-x-to-collector-3-x //TopScoreDocCollector collector = TopScoreDocCollector.Create(maxResults, true); int maxResults = int.MaxValue; TopDocs hits = searcher.Search(searchQuery, filter, maxResults); int startHit = 0; if (pageNumber > 1) { startHit = ((pageNumber - 1) * pageSize); } totalHits = hits.TotalHits; int end = startHit + pageSize; if (totalHits <= end) { end = totalHits; } int itemsAdded = 0; int itemsToAdd = end; QueryScorer scorer = new QueryScorer(searchQuery); SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class='searchterm'>", "</span>"); Highlighter highlighter = new Highlighter(formatter, scorer); highlighter.TextFragmenter = new SimpleFragmenter(highlightedFragmentSize); for (int i = startHit; i < itemsToAdd; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); IndexItem indexItem = new IndexItem(doc, hits.ScoreDocs[i].Score); if (highlightResults) { try { TokenStream stream = analyzer.TokenStream("contents", new StringReader(doc.Get("contents"))); string highlightedResult = highlighter.GetBestFragment(stream, doc.Get("contents")); if (highlightedResult != null) { indexItem.Intro = highlightedResult; } } catch (NullReferenceException) { } } results.Add(indexItem); itemsAdded += 1; } results.ItemCount = itemsAdded; results.PageIndex = pageNumber; results.ExecutionTime = DateTime.Now.Ticks - startTicks; } } catch (ParseException ex) { invalidQuery = true; log.Error("handled error for search terms " + queryText, ex); // these parser exceptions are generally caused by // spambots posting too much junk into the search form // heres an option to automatically ban the ip address HandleSpam(queryText, ex); return results; } catch (BooleanQuery.TooManyClauses ex) { invalidQuery = true; log.Error("handled error for search terms " + queryText, ex); return results; } catch (System.IO.IOException ex) { invalidQuery = true; log.Error("handled error for search terms " + queryText, ex); return results; } return results; } }
private void search() { DateTime start = DateTime.Now; // create the result DataTable this.Results.Columns.Add("title", typeof(string)); this.Results.Columns.Add("sample", typeof(string)); this.Results.Columns.Add("path", typeof(string)); this.Results.Columns.Add("url", typeof(string)); this.Results.Columns.Add("Type", typeof(string)); // create the searcher // index is placed in "index" subdirectory string indexDirectory = Server.MapPath("~/App_Data/index"); var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); // List<string> STOP_WORDS = StopAnalyzer.ENGLISH_STOP_WORDS_SET.ToList<string>(); IndexSearcher searcher = new IndexSearcher(FSDirectory.Open(indexDirectory)); BooleanQuery bquery = new BooleanQuery(); //var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "text", analyzer); List<string> SearchTerm = new List<string> { "text", "path", "title", "Extension", "EXTPRP" }; List<string> Projects = new List<string>(); if (Session["ProjectList"] != null) { Projects = (List<string>)Session["ProjectList"]; } List<string> allType = new List<string> { "A", "B", "C" }; if (this.Request.QueryString["Page"] != null) { if (allType.Contains(this.Request.QueryString["Page"].ToString())) { allType.Remove(this.Request.QueryString["Page"]); foreach (string type in allType) { TermQuery termq1 = new TermQuery(new Term("EXTPRP", type)); bquery.Add(termq1, Occur.MUST_NOT); FuzzyQuery termq = new FuzzyQuery(new Term("EXTPRP", type), 0.5f, 0); bquery.Add(termq, Occur.MUST_NOT); } } } //Query query = parser.Parse(this.Query); //foreach (string term in SearchTerm) //{ // if (term == "title") // { // TermQuery termq = new TermQuery(new Term(term, this.Query)); // termq.Boost = 50f; // bquery.Add(termq, Occur.SHOULD); // } // else // { // TermQuery termq = new TermQuery(new Term(term, this.Query)); // termq.Boost = 5f; // bquery.Add(termq, Occur.SHOULD); // } //} foreach (string term in SearchTerm) { if (term == "title") { TermQuery termq = new TermQuery(new Term(term, this.Query)); termq.Boost = 5f; bquery.Add(termq, Occur.SHOULD); } else { FuzzyQuery termq = new FuzzyQuery(new Term(term, this.Query), 0.5f, 0); termq.Boost = 0.1f; bquery.Add(termq, Occur.SHOULD); } } //foreach (string project in Projects) //{ // TermQuery termq1 = new TermQuery(new Term("Project", project)); // bquery.Add(termq1, Occur.MUST_NOT); //} //foreach (string project in Projects.Distinct()) //{ // TermQuery termq1 = new TermQuery(new Term("path", project)); // bquery.Add(termq1, Occur.MUST); // FuzzyQuery termq = new FuzzyQuery(new Term("path", project), 0.5f, 0); // bquery.Add(termq, Occur.MUST); //} //bquery.Add(new TermQuery(new Term("Project", "DEV")), Occur.SHOULD); //List<ScoreDoc> TempArrList = new List<ScoreDoc>(); TopDocs hits = searcher.Search(bquery, null, 10000); //TopDocs hits = new TopDocs(TempArrList.Count(), TempArrList.ToArray(), hitsWithText.MaxScore); //hits.ScoreDocs.CopyTo(hits.ScoreDocs, 0); //hits.ScoreDocs = hits.ScoreDocs.OrderBy(obj => searcher.Doc(obj.Doc).Get("path")).ToArray(); if (Projects.Count() != 0) { hits.ScoreDocs = hits.ScoreDocs.Where(obj => Projects.Contains(Path.GetDirectoryName(searcher.Doc(obj.Doc).Get("path")))).Distinct().ToArray(); } //foreach (string project in Projects.Distinct()) //{ // //hits.ScoreDocs = hits.ScoreDocs.Where(obj => Regex.IsMatch(searcher.Doc(obj.Doc).Get("path").Replace(@"\", @"\\"), @".*" + project.Replace(@"\", @"\\") + ".*")).ToArray(); // string s = Path.GetDirectoryName("\\SAGITEC-1629\\Soogle\\CARS\\bhagyashree.txt"); // hits.ScoreDocs = hits.ScoreDocs.Where(obj => Path.GetDirectoryName(searcher.Doc(obj.Doc).Get("path")).Contains(project)).ToArray(); //} this.total = hits.ScoreDocs.Count(); this.startAt = InitStartAt(); int resultsCount = Math.Min(total, this.maxResults + this.startAt); // create highlighter IFormatter formatter = new SimpleHTMLFormatter("<span style=\"font-weight:bold;background-color:yellow;\">", "</span>"); SimpleFragmenter fragmenter = new SimpleFragmenter(200); QueryScorer scorer = new QueryScorer(bquery); Highlighter highlighter = new Highlighter(formatter, scorer); highlighter.TextFragmenter = fragmenter; int j = 0; for (int i = startAt; i < resultsCount; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); String path = doc.Get("path"); string getExtension = doc.Get("Extension"); TokenStream stream = analyzer.TokenStream("", new StringReader(doc.Get("text"))); String sample = ""; try { string document = doc.Get("text"); if (getExtension.ToLower() == ".png" || getExtension.ToLower() == ".jpg" || getExtension.ToLower() == ".gif" || getExtension.ToLower() == ".bmp") { sample = ""; } else { sample = highlighter.GetBestFragment(stream, document);//, 2, "..."); } } catch (Exception ex) { } // create a new row with the result data DataRow row = this.Results.NewRow(); row["title"] = doc.Get("title"); row["path"] = "http://sagitec-1629/KNBASE/" + path.Replace(@"\", "/").Replace("//SAGITEC-1629/Soogle/", ""); row["url"] = "http://sagitec-1629/KNBASE/" + path.Replace(@"\", "/").Replace("//SAGITEC-1629/Soogle/", ""); row["sample"] = sample; if (path.Contains('.')) { row["Type"] = GetMIMEType(path); } //if (!Projects.Contains(doc.Get("Project")) || !allType.Contains(doc.Get("EXTPRP"))) //{ this.Results.Rows.Add(row); //} j++; } Repeater1.DataSource = Results; Repeater1.DataBind(); searcher.Dispose(); // result information this.duration = DateTime.Now - start; this.fromItem = startAt + 1; this.toItem = Math.Min(startAt + maxResults, total); }
//******************************************************************************************************************************** private void search() { if (TextBoxQuery.Text != "") { DateTime start = DateTime.Now; // create the result DataTable this.Results.Columns.Add("title", typeof(string)); this.Results.Columns.Add("sample", typeof(string)); this.Results.Columns.Add("path", typeof(string)); this.Results.Columns.Add("url", typeof(string)); this.Results.Columns.Add("Type", typeof(string)); // create the searcher // index is placed in "index" subdirectory string indexDirectory = Server.MapPath(IndexDirPath); var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); // List<string> STOP_WORDS = StopAnalyzer.ENGLISH_STOP_WORDS_SET.ToList<string>(); IndexSearcher searcher = new IndexSearcher(FSDirectory.Open(indexDirectory)); BooleanQuery bquery = new BooleanQuery(); //var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "text", analyzer); List<string> SearchTerm = new List<string> { "text", "path", "title", "Extension", "EXTPRP" }; List<string> Projects = new List<string>(); if (Session["ProjectList"] != null) { Projects = (List<string>)Session["ProjectList"]; } List<string> allType = null; if (hnkClickLink.Value == "") { allType = new List<string>(); } else { allType = new List<string> { "Doc", "Code", "Images", "Other" }; } if (this.Request.QueryString["Page"] != null) { if (allType.Contains(Convert.ToString(hnkClickLink.Value))) { allType.Remove(Convert.ToString(hnkClickLink.Value)); foreach (string type in allType) { TermQuery termq1 = new TermQuery(new Term("EXTPRP", type)); bquery.Add(termq1, Occur.MUST_NOT); FuzzyQuery termq = new FuzzyQuery(new Term("EXTPRP", type), 0.5f, 0); bquery.Add(termq, Occur.MUST_NOT); } } } //Query query = parser.Parse(this.Query); foreach (string term in SearchTerm) { if (term == "title") { TermQuery termq = new TermQuery(new Term(term, this.Query.ToLower())); termq.Boost = 5f; bquery.Add(termq, Occur.SHOULD); } else { TermQuery termq = new TermQuery(new Term(term, this.Query.ToLower())); termq.Boost = 0.1f; bquery.Add(termq, Occur.SHOULD); } } foreach (string term in SearchTerm) { if (this.Query.Contains(".")) { string SearchKeyword = this.Query.Replace(".", ""); if (term == "Extension") { TermQuery termq = new TermQuery(new Term(term, SearchKeyword.ToLower())); termq.Boost = 5f; bquery.Add(termq, Occur.SHOULD); } } else { if (term == "title") { FuzzyQuery termq = new FuzzyQuery(new Term(term, this.Query.ToLower())); termq.Boost = 5f; bquery.Add(termq, Occur.SHOULD); } else { //FuzzyQuery termq = new FuzzyQuery(new Term(term, this.Query), 0.5f, 0); //termq.Boost = 0.1f; //bquery.Add(termq, Occur.SHOULD); } } } TopDocs hits = searcher.Search(bquery, null, 10000); //TopDocs hits = new TopDocs(TempArrList.Count(), TempArrList.ToArray(), hitsWithText.MaxScore); //hits.ScoreDocs.CopyTo(hits.ScoreDocs, 0); //hits.ScoreDocs = hits.ScoreDocs.OrderBy(obj => searcher.Doc(obj.Doc).Get("path")).ToArray(); if (Projects.Count() != 0) { hits.ScoreDocs = hits.ScoreDocs.Where(obj => Projects.Contains(SplitPath(Path.GetDirectoryName(searcher.Doc(obj.Doc).Get("path"))))).Distinct().ToArray(); } this.total = hits.ScoreDocs.Count(); this.startAt = InitStartAt(); int resultsCount = Math.Min(total, this.maxResults + this.startAt); // create highlighter IFormatter formatter = new SimpleHTMLFormatter("<span style=\"font-weight:bold;background-color:yellow;\">", "</span>"); SimpleFragmenter fragmenter = new SimpleFragmenter(200); QueryScorer scorer = new QueryScorer(bquery); Highlighter highlighter = new Highlighter(formatter, scorer); highlighter.TextFragmenter = fragmenter; //highlighter.MaxDocCharsToAnalyze=200; //for (int i = startAt; i < resultsCount; i++) //{ // Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); // String path = doc.Get("path"); // string getExtension = doc.Get("Extension"); // TokenStream stream = analyzer.TokenStream("", new StringReader(doc.Get("text"))); // String sample = ""; // try // { // string document = doc.Get("text"); // if (getExtension.ToLower() == ".png" || getExtension.ToLower() == ".jpg" || getExtension.ToLower() == ".gif" || getExtension.ToLower() == ".bmp" || getExtension.ToLower() == ".jpeg") // { // sample = ""; // } // else // { // string outp = highlighter.GetBestFragment(stream, document); // if (outp != null) // sample = ReplaceSpecialChar(outp.Trim()); //, 2, "..."); // else // sample = Limit(doc.Get("text").Trim(), 200); // } // } // catch (Exception ex) // { // } // // create a new row with the result data // DataRow row = this.Results.NewRow(); // row["title"] = doc.Get("title"); // row["path"] = ApplicationPath + path.Replace(@"\", "/").Replace(VirtualPath, ""); // row["url"] = ApplicationPath + path.Replace(@"\", "/").Replace(VirtualPath, ""); // row["sample"] = sample; // if (path.Contains('.')) // { // row["Type"] = GetMIMEType(path); // } // this.Results.Rows.Add(row); //} for (int i = 0; i < this.total; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); String path = doc.Get("path"); string getExtension = doc.Get("Extension"); TokenStream stream = analyzer.TokenStream("", new StringReader(doc.Get("text"))); String sample = ""; try { string document = doc.Get("text"); if (getExtension.ToLower() == ".png" || getExtension.ToLower() == ".jpg" || getExtension.ToLower() == ".gif" || getExtension.ToLower() == ".bmp" || getExtension.ToLower() == ".jpeg") { sample = ""; } else { string outp = highlighter.GetBestFragment(stream, document); if (outp != null) sample = Limit(outp.Trim(), 200); //, 2, "..."); else sample = Limit(doc.Get("text").Trim(), 200); } } catch (Exception ex) { } // create a new row with the result data DataRow row = Results.NewRow(); row["title"] = doc.Get("title"); row["path"] = ApplicationPath + path.Replace(@"\", "/").Replace(VirtualPath, ""); row["url"] = ApplicationPath + path.Replace(@"\", "/").Replace(VirtualPath, ""); row["sample"] = sample; if (path.Contains('.')) { row["Type"] = GetMIMEType(path); } Results.Rows.Add(row); } //****************************** Logic for Paging for Repeater Control**************************************** PagedDataSource pgitems = new PagedDataSource(); DataView dv = new DataView(Results); pgitems.DataSource = dv; pgitems.AllowPaging = true; pgitems.PageSize = 10;//You can set the number of items here using some logic. pgitems.CurrentPageIndex = PageNumber; btnPrev.Visible = !pgitems.IsFirstPage; btnNext.Visible = !pgitems.IsLastPage; if (pgitems.PageCount > 1) { rptPages.Visible = true; ArrayList pages = new ArrayList(); for (int i = PageNumber; i < 5 + PageNumber; i++) pages.Add((i + 1).ToString()); rptPages.DataSource = pages; rptPages.DataBind(); } else rptPages.Visible = false; Repeater1.DataSource = pgitems; Repeater1.DataBind(); //************************************************************************************************************* //Repeater1.DataSource = Results; //Repeater1.DataBind(); searcher.Dispose(); // result information this.duration = DateTime.Now - start; this.fromItem = startAt + 1; this.toItem = Math.Min(startAt + maxResults, total); } }