Beispiel #1
0
        private ListViewItem LvCreate(JIndex.File x)
        {
            var lv = new ListViewItem {
                Text = Path.GetFileName(x.Path), Tag = x
            };

            lv.SubItems.Add(new ListViewItem.ListViewSubItem {
                Text = Directory.GetParent(x.Path).Name
            });
            lv.SubItems.Add(new ListViewItem.ListViewSubItem {
                Text = x.Path
            });
            lv.SubItems.Add(new ListViewItem.ListViewSubItem {
                Text = x.Id.ToString()
            });
            return(lv);
        }
Beispiel #2
0
        public List <JIndex.Grouping> GetAllWords(JIndex.File x) //, string phraseToFind = "")
        {
            List <JIndex.Grouping> L = new List <JIndex.Grouping>();

            try
            {
                using (PdfDocument document = PdfDocument.Open(x.Path))
                {
                    Dictionary <string, ulong> D = new Dictionary <string, ulong>();

                    double perc = (100.0 * _CurrentSize) / _TotalSize;

                    var    tsEL = DateTime.Now - _DateStart;
                    double secs = tsEL.TotalSeconds;
                    int    estimated;

                    _Velocity = _CurrentSize / secs;
                    estimated = (int)(_TotalSize / _Velocity);
                    tsEL      = TimeSpan.FromSeconds((int)secs);
                    var tsES = TimeSpan.FromSeconds(estimated);
                    var P    = (int)(perc * 0.45 + 5);

                    JProgressSet(P, $"[{perc.ToString("F1", CultureInfo.InvariantCulture)}%] EL {tsEL} ES {tsES}"
                                 + $"   Processing file {x.Id} of {_Index.Files.Count}: {Path.GetFileName(x.Path)} ");

                    DateTime wc = DateTime.Now;

                    try
                    {
                        foreach (Page page in document.GetPages())
                        {
                            // string pageText = page.Text;
                            foreach (Word word in page.GetWords())
                            {
                                if (D.ContainsKey(word.Text))
                                {
                                    D[word.Text]++;
                                }
                                else
                                {
                                    D[word.Text] = 0;
                                }
                                // TODO: queue words to find phrases - move it outside this code.

                                if (DateTime.Now > wc)
                                {
                                    perc = (100.0 * _CurrentSize) / _TotalSize;

                                    tsEL = DateTime.Now - _DateStart;
                                    secs = tsEL.TotalSeconds;

                                    _Velocity = _CurrentSize / secs;
                                    estimated = (int)(_TotalSize / _Velocity);
                                    tsEL      = TimeSpan.FromSeconds((int)secs);
                                    tsES      = TimeSpan.FromSeconds(estimated);
                                    P         = (int)(perc * 0.45 + 5);
                                    JProgressSet(P, $"[{perc.ToString("F1", CultureInfo.InvariantCulture)}%] EL {tsEL} ES {tsES}"
                                                 + $"   Processing file {x.Id} of {_Index.Files.Count}: {Path.GetFileName(x.Path)} ");
                                    wc = DateTime.Now.AddMilliseconds(200);
                                }
                            }
                        }
                    }
                    catch { }

                    _CurrentSize += x.Size;


                    // JProgressSet(P, $"Collecting file words: {x.Id} Words: {D.Count} {Path.GetFileName(x.Path)}");

                    foreach (var kv in D)
                    {
                        L.Add(new JIndex.Grouping {
                            GId = _gid++, Count = kv.Value, Id = x.Id, Word = kv.Key
                        });
                    }
                    D.Clear();
                }
            }
            catch
            { }

            return(L);
        }