public int Count(NuixLogRepo repo, string queryString) { // Lucene seems to be picky about lower case for some things? Regex notFix = new Regex(@"\bnot\b", RegexOptions.Compiled); queryString = notFix.Replace(queryString, "NOT"); // Blank query means all items if (string.IsNullOrWhiteSpace(queryString)) { return((int)repo.Database.TotalRecords); } else { luceneDirectory = FSDirectory.Open(IndexDirectory); analyzer = getAnalyzer(); IndexSearcher searcher = new IndexSearcher(luceneDirectory); Query query = parseQuery(queryString); var hitsFound = searcher.Search(query, int.MaxValue); int hitCount = hitsFound.TotalHits; luceneDirectory.Dispose(); searcher.Dispose(); analyzer.Dispose(); return(hitCount); } }
public IList <long> Search(NuixLogRepo repo, string queryString) { // Lucene seems to be picky about lower case for some things? Regex notFix = new Regex(@"\bnot\b", RegexOptions.Compiled); queryString = notFix.Replace(queryString, "NOT"); // Emtpy query is all items, we return a special collection that pretends to be a full list of ID values // but that is actually just based on the range of possible values. if (string.IsNullOrWhiteSpace(queryString)) { return(new AllEntriesIDList((int)repo.Database.TotalRecords)); } else { luceneDirectory = FSDirectory.Open(IndexDirectory); analyzer = getAnalyzer(); IndexSearcher searcher = new IndexSearcher(luceneDirectory); Query query = parseQuery(queryString); var hitsFound = searcher.Search(query, int.MaxValue); long[] ids = new long[hitsFound.TotalHits]; for (int i = 0; i < hitsFound.TotalHits; i++) { Document doc = searcher.Doc(hitsFound.ScoreDocs[i].Doc); ids[i] = long.Parse(doc.Get("id")); } luceneDirectory.Dispose(); searcher.Dispose(); analyzer.Dispose(); return(ids); } }