public List <IndexedFile> Search(string pattern) { IndexSearcher searcher = new IndexSearcher(m_SearchPath); List <IndexedFile> list = null; try { list = new List <IndexedFile>(); QueryParser parser = new QueryParser(Constants.Content, new StandardAnalyzer()); parser.SetDefaultOperator(QueryParser.AND_OPERATOR); string tokenizedPattern = Tokenizer.Tokenize(pattern, false); if (pattern != tokenizedPattern) { pattern = pattern + " OR \"" + tokenizedPattern + "\""; } Query query = parser.Parse(pattern); Hits hits = searcher.Search(query); for (int i = 0; i < hits.Length(); i++) { IndexedFile fi = new IndexedFile(); Document doc = hits.Doc(i); fi.FileFullName = doc.Get(Constants.Full); fi.FileName = doc.Get(Constants.File); fi.FileFolderName = doc.Get(Constants.Folder); fi.FileExtension = doc.Get(Constants.Extension); fi.FileSizeinBytes = long.Parse(doc.Get(Constants.Size)); list.Add(fi); } return(list); } finally { searcher.Close(); } }
public List<IndexedFile> Search(string pattern) { IndexSearcher searcher = new IndexSearcher(m_SearchPath); List<IndexedFile> list = null; try { list = new List<IndexedFile>(); QueryParser parser = new QueryParser(Constants.Content, new StandardAnalyzer()); parser.SetDefaultOperator(QueryParser.AND_OPERATOR); string tokenizedPattern = Tokenizer.Tokenize(pattern, false); if (pattern != tokenizedPattern) pattern = pattern + " OR \"" + tokenizedPattern + "\""; Query query = parser.Parse(pattern); Hits hits = searcher.Search(query); for (int i = 0; i < hits.Length(); i++) { IndexedFile fi = new IndexedFile(); Document doc = hits.Doc(i); fi.FileFullName = doc.Get(Constants.Full); fi.FileName = doc.Get(Constants.File); fi.FileFolderName = doc.Get(Constants.Folder); fi.FileExtension = doc.Get(Constants.Extension); fi.FileSizeinBytes = long.Parse(doc.Get(Constants.Size)); list.Add(fi); } return list; } finally { searcher.Close(); } }