unsafe public DocumentResultWhereDictionary OrMerge(DocumentResultWhereDictionary fst, DocumentResultWhereDictionary sec) { if (fst == null) { return(sec); } if (sec == null) { return(fst); } foreach (int docid in sec.Keys) { if (fst.ContainsKey(docid)) { fst.Update(docid, fst[docid].Score + sec[docid].Score); } else { fst.Add(docid, sec[docid]); } } return(fst); }
/// <summary> /// And merge when the Not property is ture of fst or sec. /// </summary> /// <param name="fst"></param> /// <param name="sec"></param> /// <returns></returns> public DocumentResultWhereDictionary AndMergeForNot(DocumentResultWhereDictionary fst, DocumentResultWhereDictionary sec) { if (fst == null) { return(sec); } if (sec == null) { return(fst); } if (fst.Count > sec.Count) { //Swap input dictionaries //Let fst count less than sec DocumentResultWhereDictionary temp; temp = fst; fst = sec; sec = temp; } if (fst.Not && sec.Not) { foreach (int key in fst.Keys) { if (!sec.ContainsKey(key)) { sec.Add(key, fst[key]); } } sec.RelTotalCount = sec.Count; return(sec); } else { DocumentResultWhereDictionary yes; DocumentResultWhereDictionary not; if (fst.Not) { yes = sec; not = fst; } else { yes = fst; not = sec; } foreach (int key in not.Keys) { yes.Remove(key); } yes.RelTotalCount = yes.Count; return(yes); } }