Ejemplo n.º 1
0
        public List <RunItem> Search(string s, int nrOfHits = 10)
        {
            if (s == null)
            {
                s = "";
            }
            s = s.Trim();
            var fileList = new List <RunItem>();
            var sw       = new Stopwatch();

            sw.Start();
            ICollection <RunItem> generalResult = MatcherGeneral.Search(s.ToLower(), nrOfHits);

            GeneralSearchTime = (int)sw.ElapsedTicks;
            sw.Restart();
            //Console.WriteLine($"    ");

            ICollection <RunItem> prioResult = MatcherPrio.Search(s.ToLower()); //Get all results from indexing

            prioResult = prioResult.Concat(generalResult).ToList();             //put the rest of the results on the stack
            //foreach (var runItem in prioResult)
            //{
            //    Console.WriteLine($"{runItem.Name}, {runItem.RunNrOfTimes}");

            //}
            prioResult = prioResult.GroupBy(x => x.Name + x.URI + x.Command)
                         .Select(x => x.OrderByDescending(p => p.RunNrOfTimes).First()).ToList(); //remove potential duplicates
            prioResult =
                prioResult.ToList().OrderByDescending(p => p.RunNrOfTimes)
                .ToList();     //sort prioresults since they will always have at least one runtime

            PrioSearchTime  = (int)sw.ElapsedTicks;
            TotalSearchTime = GeneralSearchTime + PrioSearchTime;
            return(prioResult.Take(10).ToList());
        }
Ejemplo n.º 2
0
 public void AddExecutedItem(RunItem exItem)
 {
     MatcherGeneral.Remove(exItem.Name.ToLower());
     exItem.RunNrOfTimes++;
     MatcherPrio.Replace(exItem.Name, exItem);
     SaveTries();
 }
Ejemplo n.º 3
0
        public void ResetItemRunCounter(RunItem exItem)
        {
            exItem.RunNrOfTimes = 0;
            if (exItem.Type == ItemType.File || exItem.Type == ItemType.Directory
                ) //Move it back to general list. Settings and other stuff will always be in the priolist.
            {
                MatcherPrio.Remove(exItem.Name.ToLower());
                MatcherGeneral.Insert(exItem.Name.ToLower(), exItem);
            }

            SaveTries();
        }
Ejemplo n.º 4
0
        public void RunIndexingOnSingleFolder(FolderSearch dir)
        {
            Task.Run(() =>
            {
                try
                {
                    if (IndexingIsRunning)
                    {
                        return;
                    }
                    IndexingIsRunning = true;

                    var unorderedFiles = new HashSet <RunItem>();
                    LastIndexed        = DateTime.Now;

                    var tempBag = new HashSet <RunItem>();
                    ProcessDirectory(dir, tempBag);
                    dir.NrOfFiles = tempBag.Count;
                    foreach (var item in tempBag)
                    {
                        unorderedFiles.Add(item);
                    }

                    RunItem[] tempList = unorderedFiles.ToArray();
                    tempList           = tempList.GroupBy(p => p.URI + p.Arguments + p.Command).Select(p => p.First()).ToArray();

                    for (int i = 0; i < tempList.Length; i++)
                    {
                        Progress = i / tempList.Length * 100;
                        MatcherGeneral.Insert(tempList[i].Name.ToLower(), tempList[i]);
                        //if (!string.IsNullOrEmpty(tempList[i].Group))
                        //    TempMatcher.Insert(tempList[i].Group.ToLower(), tempList[i]);
                    }

                    NrOfPaths = MatcherGeneral.DataDictionary.Count + MatcherPrio.DataDictionary.Count;
                    SaveTries();

                    IndexingIsRunning = false;
                }
                catch (Exception e)
                {
                    Log.Error(e, $"Could not search folder {dir.Path}");
                }
            });
        }