示例#1
0
 public BibleSearchMatch Clone(BibleSearchVerse verse = null)
 {
     return(new BibleSearchMatch()
     {
         BookId = this.BookId,
         BookName = this.BookName,
         BookNames = this.BookNames,
         Chapter = this.Chapter,
         Verses = this.Verses,
         SelectedVerse = verse,
     });
 }
示例#2
0
        public static BibleSearchResults FindEn(BibleIndexRequest req)
        {
            var res  = new List <BibleSearchMatch>();
            var bres = new BibleSearchResults()
            {
                Request = req, Matches = res.ToArray()
            };

            if (req.Prefix.IsNullOrEmpty())
            {
                return(bres);
            }
            BibleSearchVerse vs;

            foreach (var n in EngBookNames.Values)
            {
                if (!n.Suffix.ToLower().StartsWith(req.Prefix))
                {
                    continue;
                }
                //if (req.Volume > 0 && n.Volume != req.Volume) continue;
                var bk = EngBible.Books[n.Id];
                //if (req.Prefix == "john") {TraceLogger.Send($"Book: {req.Prefix} Request Chapter: {req.Chapter.ToString()} Count: {bk.Chapters.Count.ToString()} Term: {req.SearchText}"); }
                var cn = req.Chapter;
                if (cn > bk.Chapters.Count)
                {
                    cn = bk.Chapters.Count;
                }
                else if (cn < 1)
                {
                    cn = 1;
                }
                var sr = new BibleSearchMatch()
                {
                    BookId    = bk.Id,
                    BookName  = bk.Name,
                    BookNames = new SortedDictionary <string, string>(),
                    Chapter   = cn,
                };
                var vss = new SortedDictionary <int, BibleSearchVerse>();
                int v = req.Verse, r = req.Range;
                var vl = new List <BibleSearchVerse>();
                foreach (var b in Bibles.Values)
                {
                    bk = b.Books[sr.BookId.ToLower()];
                    sr.BookNames[b.Lang] = bk.Name;
                    var ch = bk.Chapters[sr.Chapter];
                    //if (bk.Name == "John") {TraceLogger.Send("{0}:{1}/{2} Count: {3} Book: {4} Number: {5}", sr.BookId, sr.Chapter.ToString(), req.Chapter.ToString(), bk.Chapters.Count.ToString(), ch.Book, ch.Number.ToString()); }
                    //TraceLogger.Send("{0}:{1} Count: {2} Book: {3} Number: {4}", sr.BookId, sr.Chapter.ToString(), bk.Chapters.Count.ToString(), ch.Book, ch.Number.ToString());
                    if (v > ch.Verses.Count)
                    {
                        v = ch.Verses.Count;
                    }
                    else if (v < 1)
                    {
                        v = 1;
                        r = ch.Verses.Count;
                    }
                    if (r < v)
                    {
                        r = v;
                    }
                    else if (r > ch.Verses.Count)
                    {
                        r = ch.Verses.Count;
                    }
                    string txt = null;
                    for (var idx = v; idx <= r; idx++)
                    {
                        if (!ch.Verses.TryGetValue(idx, out txt))
                        {
                            continue;
                        }
                        if (txt.IsNullOrEmpty())
                        {
                            continue;
                        }
                        if (!vss.TryGetValue(idx, out vs))
                        {
                            vs = new BibleSearchVerse()
                            {
                                Verse   = idx,
                                Content = new SortedDictionary <string, string>(),
                            };
                            vss[idx] = vs;
                            vl.Add(vs);
                        }
                        vs.Content[b.Lang] = txt;
                    }
                }
                if (vl.Count < 1)
                {
                    continue;
                }
                sr.Verses = vl.ToArray();
                res.Add(sr);
            }
            bres.Matches = res.OrderBy(m => {
                var prefix = "A ";
                var name   = EngBookNames[m.BookId.ToLower()];
                if (req.Volume > 0 && req.Volume != name.Volume)
                {
                    prefix = name.Volume > 0 ? "B " : "Z ";
                }
                return(prefix + name.Suffix + string.Format(" {0}", name.Volume.ToString()));
            }).ToArray();
            return(bres);
        }