Esempio n. 1
0
        void ShowResult(SearchCategory cat, ISearchDataSource result)
        {
            incompleteResults.Add(Tuple.Create(cat, result));

            incompleteResults.Sort((x, y) => {
                return(categories.IndexOf(x.Item1).CompareTo(categories.IndexOf(y.Item1)));
            }
                                   );

            if (incompleteResults.Count == categories.Count)
            {
                results.Clear();
                results.AddRange(incompleteResults);
                topItem = null;
                for (int i = 0; i < results.Count; i++)
                {
                    if (results[i].Item2.ItemCount == 0)
                    {
                        continue;
                    }
                    if (topItem == null || topItem.DataSource.GetWeight(topItem.Item) < results[i].Item2.GetWeight(0))
                    {
                        topItem = new ItemIdentifier(results[i].Item1, results[i].Item2, 0);
                    }
                }
                selectedItem = topItem;

                ShowTooltip();
                isInSearch = false;
                AnimatedResize();
            }
        }
Esempio n. 2
0
        public static IEnumerable <SearchResult> Search(ISearchDataSource source, string search, bool ignoreAccents, bool ignoreCase)
        {
            if (ignoreAccents)
            {
                search = RemoveAccents(search);
            }

            //Split the expression into sub-queries.
            string[] queryStrings = search.Split(new[] { '>' }, StringSplitOptions.RemoveEmptyEntries);
            if (queryStrings.Length == 0)
            {
                foreach (var e in source)
                {
                    //yield return new SearchResult(p.Phrase, Join(p.Translations), MatchType.NormalMatch);
                    yield return(new SearchResult(e, MatchType.NormalMatch));
                }
                yield break;
            }

            var queries = new SearchQuery[queryStrings.Length];

            for (int i = 0; i < queries.Length; ++i)
            {
                queries[i] = new SearchQuery {
                    text = queryStrings[i]
                }
            }
            ;

            //Find the terms for each query. Exit the search if any query has no terms.
            for (int i = 0; i < queries.Length; ++i)
            {
                queries[i].terms = queries[i].text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (queries[i].terms.Length == 0)
                {
                    yield break;
                }
                for (int j = 0; j < queries[i].terms.Length; j++)
                {
                    queries[i].terms[j] = queries[i].terms[j].Trim();
                }
            }

            //If none of the queries fail, we can yield the pair to the owner.
            foreach (var entry in source)
            {
                var    matchType = MatchType.NormalMatch;
                string phrase    = ignoreAccents ? entry.PhraseNoAccents : entry.Phrase;

                if (queries.All(q => q.terms.Any(term => Filter(term, phrase, ignoreCase, ref matchType))))
                {
                    yield return(new SearchResult(entry, matchType));
                }
            }
        }
Esempio n. 3
0
        string GetRowMarkup(ISearchDataSource dataSrc, int i)
        {
            string txt  = "<span foreground=\"#606060\">" + dataSrc.GetMarkup(i, false) + "</span>";
            string desc = dataSrc.GetDescriptionMarkup(i, false);

            if (!string.IsNullOrEmpty(desc))
            {
                txt += "<span foreground=\"#8F8F8F\" size=\"small\">\n" + desc + "</span>";
            }
            return(txt);
        }
Esempio n. 4
0
        void ShowResult(SearchCategory cat, ISearchDataSource result)
        {
            incompleteResults.Add(Tuple.Create(cat, result));

            incompleteResults.Sort((x, y) => {
                return(categories.IndexOf(x.Item1).CompareTo(categories.IndexOf(y.Item1)));
            }
                                   );

            if (incompleteResults.Count == categories.Count)
            {
                results.Clear();
                results.AddRange(incompleteResults);
                List <Tuple <SearchCategory, ISearchDataSource> > failedResults = null;
                topItem = null;

                for (int i = 0; i < results.Count; i++)
                {
                    var tuple = results [i];
                    try {
                        if (tuple.Item2.ItemCount == 0)
                        {
                            continue;
                        }
                        if (topItem == null || topItem.DataSource.GetWeight(topItem.Item) < tuple.Item2.GetWeight(0))
                        {
                            topItem = new ItemIdentifier(tuple.Item1, tuple.Item2, 0);
                        }
                    } catch (Exception e) {
                        LoggingService.LogError("Error while showing result " + i, e);
                        if (failedResults == null)
                        {
                            failedResults = new List <Tuple <SearchCategory, ISearchDataSource> > ();
                        }
                        failedResults.Add(results [i]);
                        continue;
                    }
                }
                selectedItem = topItem;

                if (failedResults != null)
                {
                    failedResults.ForEach(failedResult => results.Remove(failedResult));
                }

                ShowTooltip();
                isInSearch = false;
                AnimatedResize();
            }
        }
		string GetRowMarkup (ISearchDataSource dataSrc, int i)
		{
			string txt = "<span foreground=\"#606060\">" + dataSrc.GetMarkup (i, false) +"</span>";
			string desc = dataSrc.GetDescriptionMarkup (i, false);
			if (!string.IsNullOrEmpty (desc))
				txt += "<span foreground=\"#8F8F8F\" size=\"small\">\n" + desc + "</span>";
			return txt;
		}
			public ItemIdentifier (SearchCategory category, ISearchDataSource dataSource, int item)
			{
				this.Category = category;
				this.DataSource = dataSource;
				this.Item = item;
			}
		void ShowResult (SearchCategory cat, ISearchDataSource result)
		{
			incompleteResults.Add (Tuple.Create (cat, result));

			incompleteResults.Sort ((x, y) => {
				return categories.IndexOf (x.Item1).CompareTo (categories.IndexOf (y.Item1));
			}
			);

			if (incompleteResults.Count == categories.Count) {
				results.Clear ();
				results.AddRange (incompleteResults);
				List<Tuple<SearchCategory, ISearchDataSource>> failedResults = null;
				topItem = null;

				for (int i = 0; i < results.Count; i++) {
					var tuple = results [i];
					try {
						if (tuple.Item2.ItemCount == 0)
							continue;
						if (topItem == null || topItem.DataSource.GetWeight (topItem.Item) < tuple.Item2.GetWeight (0))
							topItem = new ItemIdentifier(tuple.Item1, tuple.Item2, 0);
					} catch (Exception e) {
						LoggingService.LogError ("Error while showing result " + i, e);
						if (failedResults == null)
							failedResults = new List<Tuple<SearchCategory, ISearchDataSource>> ();
						failedResults.Add (results [i]);
						continue;
					}
				}
				selectedItem = topItem;

				if (failedResults != null)
					failedResults.ForEach (failedResult => results.Remove (failedResult));

				ShowTooltip ();
				isInSearch = false;
				AnimatedResize ();
			}
		}
Esempio n. 8
0
		void ShowResult (SearchCategory cat, ISearchDataSource result)
		{
			incompleteResults.Add (Tuple.Create (cat, result));

			incompleteResults.Sort ((x, y) => {
				return categories.IndexOf (x.Item1).CompareTo (categories.IndexOf (y.Item1));
			}
			);

			if (incompleteResults.Count == categories.Count) {
				results.Clear ();
				results.AddRange (incompleteResults);
				topItem = null;
				for (int i = 0; i < results.Count; i++) {
					if (results[i].Item2.ItemCount == 0)
						continue;
					if (topItem == null || topItem.DataSource.GetWeight (topItem.Item) <  results[i].Item2.GetWeight (0)) 
						topItem = new ItemIdentifier (results[i].Item1, results[i].Item2, 0);
				}
				selectedItem = topItem;

				ShowTooltip ();
				isInSearch = false;
				AnimatedResize ();
			}
		}
Esempio n. 9
0
 public ItemIdentifier(SearchCategory category, ISearchDataSource dataSource, int item)
 {
     this.Category   = category;
     this.DataSource = dataSource;
     this.Item       = item;
 }
Esempio n. 10
0
 public SearchService(ISearchDataSource dataSource)
 {
     this.dataSource = dataSource;
 }