Exemplo n.º 1
0
        private void LoadIndex()
        {
            JProgressSet(0, "Loading Index...");
            try
            {
                var f = File.ReadAllText(IndexPath);
                JProgressSet(50, "Parsing Index...");
                _Index = JsonConvert.DeserializeObject <JIndex>(f);
            }
            catch
            {
                JProgressSet(0, "Error while loading index!");
                _Index = new JIndex();
            }

            JProgressSet(100, "Done.");

            ClickFilter();
        }
Exemplo n.º 2
0
        private void CreateIndex()
        {
            GC.Collect();

            Task.Run(() =>
            {
                JProgressSet(1, "Enumerating files...");

                var Idx = DirSearch(Config.SearchScopePath);

                JProgressSet(3, "Indexing files...");

                ulong fid    = 0;
                _Index       = new JIndex();
                _Index.Files = Idx.Select(x => new JIndex.File {
                    Path = x, Id = fid++, Size = new FileInfo(x).Length
                }).ToList();
                _TotalSize = _Index.Files.Sum(x => x.Size);
                _DateStart = DateTime.Now;
                _Velocity  = 0.0;

                JProgressSet(5, "Extracting and counting words...");
                _gid = 0;

                var wordGrouping = new List <JIndex.Grouping>();
                _Index.Files.ForEach(x => wordGrouping.AddRange(GetAllWords(x)));



                JProgressSet(50, $"Grouping by words...");

                var finalGrouping = wordGrouping.GroupBy(g => g.Word);


                var wordIndex = new List <JIndex.Entry>();

                JProgressSet(50, $"Counting groups...");
                int qG = finalGrouping.Count();



                double i = 0, kf = 40.0 / qG;


                JProgressSet(50, $"Groups: {qG}. Indexing words...");

                DateTime wc = DateTime.Now;

                foreach (var q in finalGrouping)
                {
                    int y = (int)(50 + kf * i);
                    JProgressSet(y, $"Indexing entry: #{i}");
                    wordIndex.Add(
                        new JIndex.Entry {
                        Key   = q.Key,
                        Items = q.Select(p => new JIndex.Item {
                            Id = p.Id, Count = p.Count
                        }).ToList()
                    });
                    i++;
                }

                JProgressSet(90, "Saving ...");

                _Index.WordsIndex = wordIndex;

                SaveIndex();
                JProgressSet(100, "Done.");

                ClickFilter();
            });
        }