public bool SearchCollection(string query, SortedList list, SongListBox resultBox, bool text, bool matchCase, bool whole, bool trans, SortMethod sortMethod) { DirectoryInfo indexDir = new DirectoryInfo(this.indexDir); IndexSearcher searcher = new IndexSearcher(indexDir.FullName); QueryParser parser = new QueryParser(text ? "text" : "title", this.indexAnalyzer); LyraQuery lQuery = SearchUtil.CreateLyraQuery(query, whole); List<ISong> numberSongs = new List<ISong>(); // search for nr if (lQuery.Numbers != null) { foreach (int nr in lQuery.Numbers) { Song song = this.nrIndex[nr] as Song; if (song != null) { numberSongs.Add(song); } } } List<ISong> songs = new List<ISong>(); if (!string.IsNullOrEmpty(lQuery.LuceneQuery)) { Query luceneQuery = parser.Parse(lQuery.LuceneQuery); Hits hits = searcher.Search(luceneQuery); resultBox.Ratings.Clear(); for (int i = 0; i < hits.Length(); i++) { Document doc = hits.Doc(i); int nr = Int32.Parse(doc.GetField("nr").StringValue()); Song song = (Song)this.nrIndex[nr]; if (song != null) { songs.Add(song); resultBox.Ratings.Add(song, hits.Score(i)); } } } searcher.Close(); lock (resultBox) { resultBox.BeginUpdate(); resultBox.Items.Clear(); resultBox.SetSearchTags(GetTags(query)); resultBox.ShowSongs(numberSongs, songs, sortMethod); resultBox.EndUpdate(); } return true; }
public bool SearchCollection(string query, SortedList list, SongListBox resultBox, bool text, bool matchCase, bool whole, bool trans, SortMethod sortMethod) { LyraQuery lQuery = SearchUtil.CreateLyraQuery(query, whole, !text); List<ISong> numberSongs = new List<ISong>(); // search for nr if (lQuery.Numbers != null) { foreach (int nr in lQuery.Numbers) { IList<Song> nrMatches = this.nrIndex.ContainsKey(nr) ? this.nrIndex[nr] : null; if (nrMatches != null) { numberSongs.AddRange(nrMatches); } } } List<ISong> songs = new List<ISong>(); resultBox.Ratings.Clear(); if (!string.IsNullOrEmpty(lQuery.Query)) { foreach (RatedResult<Song> songResult in this.indexer.SearchObjects(query, !text)) { if (numberSongs.Contains(songResult.Result)) continue; resultBox.Ratings.Add(songResult.Result, (float)songResult.Rating); songs.Add(songResult.Result); } } lock (resultBox) { resultBox.BeginUpdate(); resultBox.Items.Clear(); resultBox.SetSearchTags(GetTags(query)); resultBox.ShowSongs(numberSongs, songs, sortMethod); resultBox.EndUpdate(); } return true; }