// Any whitelists that are passed in must be fully joined, or // query results will be incorrect. private static BetterBitArray DoRequiredQueries_TwoIndex(LNS.IndexSearcher primary_searcher, LNS.IndexSearcher secondary_searcher, ArrayList primary_queries, ArrayList secondary_queries, BetterBitArray primary_whitelist, BetterBitArray secondary_whitelist) { ArrayList match_info_list; match_info_list = new ArrayList(); // First, do all of the low-level queries // and store them in our MatchInfo for (int i = 0; i < primary_queries.Count; ++i) { LNS.Query pq, sq; pq = primary_queries [i] as LNS.Query; sq = secondary_queries [i] as LNS.Query; LuceneBitArray p_matches = null, s_matches = null; p_matches = new LuceneBitArray(primary_searcher); if (pq != null) { p_matches.Or(pq); if (primary_whitelist != null) { p_matches.And(primary_whitelist); } } s_matches = new LuceneBitArray(secondary_searcher); if (sq != null) { s_matches.Or(sq); if (secondary_whitelist != null) { s_matches.And(secondary_whitelist); } } MatchInfo info; info = new MatchInfo(); info.PrimaryMatches = p_matches; info.SecondaryMatches = s_matches; info.RestrictBy(null); // a hack to initialize the UpperBound match_info_list.Add(info); } // We want to be smart about the order we do this in, // to minimize the expense of the Join. while (match_info_list.Count > 1) { // linear scan to find the minimum int index_min = 0; for (int i = 1; i < match_info_list.Count; ++i) { if (((MatchInfo)match_info_list [i]).CompareTo((MatchInfo)match_info_list [index_min]) < 0) { index_min = i; } } MatchInfo smallest; smallest = match_info_list [index_min] as MatchInfo; match_info_list.RemoveAt(index_min); // We can short-circuit if our smallest set of // matches is empty. if (smallest.UpperBound == 0) { return(smallest.PrimaryMatches); // this must be an empty array. } smallest.Join(); foreach (MatchInfo info in match_info_list) { info.RestrictBy(smallest); } } // For the final pair, we don't need to do a full join: // mapping the secondary onto the primary is sufficient MatchInfo last; last = match_info_list [0] as MatchInfo; last.SecondaryMatches.ProjectOnto(last.PrimaryMatches); return(last.PrimaryMatches); }
// Any whitelists that are passed in must be fully joined, or // query results will be incorrect. private static BetterBitArray DoRequiredQueries_TwoIndex (LNS.IndexSearcher primary_searcher, LNS.IndexSearcher secondary_searcher, ArrayList primary_queries, ArrayList secondary_queries, BetterBitArray primary_whitelist, BetterBitArray secondary_whitelist) { ArrayList match_info_list; match_info_list = new ArrayList (); // First, do all of the low-level queries // and store them in our MatchInfo for (int i = 0; i < primary_queries.Count; ++i) { LNS.Query pq, sq; pq = primary_queries [i] as LNS.Query; sq = secondary_queries [i] as LNS.Query; LuceneBitArray p_matches = null, s_matches = null; p_matches = new LuceneBitArray (primary_searcher); if (pq != null) { p_matches.Or (pq); if (primary_whitelist != null) p_matches.And (primary_whitelist); } s_matches = new LuceneBitArray (secondary_searcher); if (sq != null) { s_matches.Or (sq); if (secondary_whitelist != null) s_matches.And (secondary_whitelist); } MatchInfo info; info = new MatchInfo (); info.PrimaryMatches = p_matches; info.SecondaryMatches = s_matches; info.RestrictBy (null); // a hack to initialize the UpperBound match_info_list.Add (info); } // We want to be smart about the order we do this in, // to minimize the expense of the Join. while (match_info_list.Count > 1) { // linear scan to find the minimum int index_min = 0; for (int i = 1; i < match_info_list.Count; ++i) if (((MatchInfo) match_info_list [i]).CompareTo ((MatchInfo) match_info_list [index_min]) < 0) index_min = i; MatchInfo smallest; smallest = match_info_list [index_min] as MatchInfo; match_info_list.RemoveAt (index_min); // We can short-circuit if our smallest set of // matches is empty. if (smallest.UpperBound == 0) return smallest.PrimaryMatches; // this must be an empty array. smallest.Join (); foreach (MatchInfo info in match_info_list) info.RestrictBy (smallest); } // For the final pair, we don't need to do a full join: // mapping the secondary onto the primary is sufficient MatchInfo last; last = match_info_list [0] as MatchInfo; last.SecondaryMatches.ProjectOnto (last.PrimaryMatches); return last.PrimaryMatches; }