public int Compare(object a, object b) { ThreadHeader itemA = (ThreadHeader)a; ThreadHeader itemB = (ThreadHeader)b; int levela = (int)itemA.Tag; int levelb = (int)itemB.Tag; // itemA が itemB より上に表示させるならマイナスの値、itemB の方が上に表示させるならプラスの値を返す…? int ret = (levelb - levela); if (ret == 0) { // レベルが同一の場合、レス数とスレの勢いで判定する int a_resCount = itemA.ResCount, b_resCount = itemB.ResCount, a_no = itemA.No, b_no = itemB.No; float a_force = new ThreadHeaderInfo(itemA).ForceValueDay, b_force = new ThreadHeaderInfo(itemB).ForceValueDay; // レス数は多いほうが優先 int compareValue = 0; if (a_resCount != b_resCount) { compareValue += (a_resCount - b_resCount) < 0 ? 1 : -1; } // 勢いは多いほうが優先 if (a_force != b_force) { compareValue += (a_force - b_force) < 0 ? 1 : -1; } // スレNOは小さいほうが優先 if (a_no != b_no) { compareValue += (a_no - b_no) < 0 ? -1 : 1; } compareValue += String.Compare(itemA.Subject, itemB.Subject); return(compareValue); } else { return(ret); } }
protected virtual bool IsMatch(List <__WordSet> wordList, ThreadHeader checkItem, ref int level) { if (checkItem.IsLimitOverThread) { return(false); } float matchCount = 0; string input = checkItem.Subject; string backWord = String.Empty; foreach (__WordSet ws in wordList) { WordType type = ws.Key; string key = ws.Value; // ひらがな1文字は無視 if (key.Length == 1 && type == WordType.Hira) { continue; } if (Regex.IsMatch(input, Regex.Escape(key), RegexOptions.IgnoreCase)) { if (type == WordType.Kanji || type == WordType.Kata || type == WordType.Hankaku || type == WordType.Alpha) { matchCount += key.Length * 2.0f; } else { matchCount += 1; } } // key を直前の単語 backWord と結合し、ひとつのワードとして検索。 // "BS11 3691" と "BSフジ 1125" が両方とも "BS" と "11" が一致し、同じ一致レベルとされてしまう問題があったたため if (backWord != "" && Regex.IsMatch(input, Regex.Escape(backWord + key), RegexOptions.IgnoreCase)) { string longKey = backWord + key; matchCount += longKey.Length * 1.5f; } // スレのカウント+1 の数字が存在したら有力候補…? if (type == WordType.Decimal) { int dec; if (Int32.TryParse(key, out dec)) { dec += 1; if (Regex.IsMatch(input, dec + "|" + HtmlTextUtility.HanToZen(dec.ToString()))) { matchCount += 3; } } } backWord = key; } // スレの勢いがあればあるほど matchCount += new ThreadHeaderInfo(checkItem).ForceValueDay / 10000; if (level - matchCount <= 0) { level = (int)Math.Round(matchCount, MidpointRounding.AwayFromZero); Console.WriteLine("{0} level of {1}", level, input); return(true); } return(false); }