Esempio n. 1
0
        public void Join(LuceneBitArray other)
        {
            LuceneBitArray image;

            image = new LuceneBitArray(other.searcher);
            this.ProjectOnto(image);

            other.Or(image);

            // We only need to project back items in the other
            // bit array that are not in the image of the
            // first projection.
            image.Not();
            image.And(other);
            image.ProjectOnto(this);
        }
Esempio n. 2
0
        ////////////////////////////////////////////////////////////////

        //
        // Special logic for handling our set of required queries
        //

        // This is the easy case: we just combine all of the queries
        // into one big BooleanQuery.
        private static BetterBitArray DoRequiredQueries(LNS.IndexSearcher primary_searcher,
                                                        ArrayList primary_queries,
                                                        BetterBitArray primary_whitelist)
        {
            LNS.BooleanQuery combined_query;
            combined_query = new LNS.BooleanQuery();
            foreach (LNS.Query query in primary_queries)
            {
                combined_query.Add(query, LNS.BooleanClause.Occur.MUST);
            }

            LuceneBitArray matches;

            matches = new LuceneBitArray(primary_searcher, combined_query);
            if (primary_whitelist != null)
            {
                matches.And(primary_whitelist);
            }

            return(matches);
        }
Esempio n. 3
0
        public void ProjectOnto(LuceneBitArray other)
        {
            int j = 0;

            while (j < this.Count)
            {
                int i;
                i = this.GetNextTrueIndex(j);
                if (i >= this.Count)
                {
                    break;
                }
                j = i + 1;

                Document doc;
                doc = searcher.Doc(i, fields_uri);

                other.AddUri(doc.Get("Uri"));
            }

            other.FlushUris();
        }
Esempio n. 4
0
        // 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);
        }
Esempio n. 5
0
        private void CreateQueryWhitelists(ICollection search_subset_uris,
                                           LNS.IndexSearcher primary_searcher,
                                           LNS.IndexSearcher secondary_searcher,
                                           LNS.BooleanQuery primary_prohibited_part_query,
                                           LNS.BooleanQuery secondary_prohibited_part_query,
                                           out LuceneBitArray primary_whitelist,
                                           out LuceneBitArray secondary_whitelist)
        {
            primary_whitelist   = null;
            secondary_whitelist = null;

            if (search_subset_uris != null && search_subset_uris.Count > 0)
            {
                primary_whitelist = new LuceneBitArray(primary_searcher);
                if (secondary_searcher != null)
                {
                    secondary_whitelist = new LuceneBitArray(secondary_searcher);
                }

                foreach (Uri uri in search_subset_uris)
                {
                    primary_whitelist.AddUri(uri);
                    if (secondary_whitelist != null)
                    {
                        secondary_whitelist.AddUri(uri);
                    }
                }
                primary_whitelist.FlushUris();
                if (secondary_whitelist != null)
                {
                    secondary_whitelist.FlushUris();
                }
            }


            // Build blacklists from our prohibited parts.

            LuceneBitArray primary_blacklist   = null;
            LuceneBitArray secondary_blacklist = null;

            if (primary_prohibited_part_query != null)
            {
                primary_blacklist = new LuceneBitArray(primary_searcher,
                                                       primary_prohibited_part_query);

                if (secondary_searcher != null)
                {
                    secondary_blacklist = new LuceneBitArray(secondary_searcher);
                    if (secondary_prohibited_part_query != null)
                    {
                        secondary_blacklist.Or(secondary_prohibited_part_query);
                    }
                    primary_blacklist.Join(secondary_blacklist);
                }
            }


            // Combine our whitelist and blacklist into just a whitelist.

            if (primary_blacklist != null)
            {
                if (primary_whitelist == null)
                {
                    primary_blacklist.Not();
                    primary_whitelist = primary_blacklist;
                }
                else
                {
                    primary_whitelist.AndNot(primary_blacklist);
                }
            }

            if (secondary_blacklist != null)
            {
                if (secondary_whitelist == null)
                {
                    secondary_blacklist.Not();
                    secondary_whitelist = secondary_blacklist;
                }
                else
                {
                    secondary_whitelist.AndNot(secondary_blacklist);
                }
            }
        }
Esempio n. 6
0
		public void Join (LuceneBitArray other)
		{
			LuceneBitArray image;
			image = new LuceneBitArray (other.searcher);
			this.ProjectOnto (image);

			other.Or (image);

			// We only need to project back items in the other
			// bit array that are not in the image of the
			// first projection.
			image.Not ();
			image.And (other);
			image.ProjectOnto (this);
		}
Esempio n. 7
0
		public void ProjectOnto (LuceneBitArray other)
		{
			int j = 0;
			while (j < this.Count) {
				int i;
				i = this.GetNextTrueIndex (j);
				if (i >= this.Count)
					break;
				j = i+1;

				Document doc;
				doc = searcher.Doc (i, fields_uri);

				other.AddUri (doc.Get ("Uri"));
			}

			other.FlushUris ();
		}
Esempio n. 8
0
		// 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;
		}		
Esempio n. 9
0
		////////////////////////////////////////////////////////////////

		//
		// Special logic for handling our set of required queries
		//

		// This is the easy case: we just combine all of the queries
		// into one big BooleanQuery.
		private static BetterBitArray DoRequiredQueries (LNS.IndexSearcher primary_searcher,
								 ArrayList primary_queries,
								 BetterBitArray primary_whitelist)
		{
			LNS.BooleanQuery combined_query;
			combined_query = new LNS.BooleanQuery ();
			foreach (LNS.Query query in primary_queries)
				combined_query.Add (query, LNS.BooleanClause.Occur.MUST);

			LuceneBitArray matches;
			matches = new LuceneBitArray (primary_searcher, combined_query);
			if (primary_whitelist != null)
				matches.And (primary_whitelist);

			return matches;
		}
Esempio n. 10
0
		private void CreateQueryWhitelists (ICollection		search_subset_uris,
						    LNS.IndexSearcher	primary_searcher,
						    LNS.IndexSearcher	secondary_searcher,
						    LNS.BooleanQuery	primary_prohibited_part_query,
						    LNS.BooleanQuery	secondary_prohibited_part_query,
						    out LuceneBitArray	primary_whitelist,
						    out LuceneBitArray	secondary_whitelist)
		{
			primary_whitelist = null;
			secondary_whitelist = null;
			
			if (search_subset_uris != null && search_subset_uris.Count > 0) {
				primary_whitelist = new LuceneBitArray (primary_searcher);
				if (secondary_searcher != null)
					secondary_whitelist = new LuceneBitArray (secondary_searcher);

				foreach (Uri uri in search_subset_uris) {
					primary_whitelist.AddUri (uri);
					if (secondary_whitelist != null)
						secondary_whitelist.AddUri (uri);
				}
				primary_whitelist.FlushUris ();
				if (secondary_whitelist != null)
					secondary_whitelist.FlushUris ();
			}


			// Build blacklists from our prohibited parts.
			
			LuceneBitArray primary_blacklist = null;
			LuceneBitArray secondary_blacklist = null;

			if (primary_prohibited_part_query != null) {
				primary_blacklist = new LuceneBitArray (primary_searcher,
									primary_prohibited_part_query);
				
				if (secondary_searcher != null) {
					secondary_blacklist = new LuceneBitArray (secondary_searcher);
					if (secondary_prohibited_part_query != null)
						secondary_blacklist.Or (secondary_prohibited_part_query);
					primary_blacklist.Join (secondary_blacklist);
				}
			}

			
			// Combine our whitelist and blacklist into just a whitelist.
			
			if (primary_blacklist != null) {
				if (primary_whitelist == null) {
					primary_blacklist.Not ();
					primary_whitelist = primary_blacklist;
				} else {
					primary_whitelist.AndNot (primary_blacklist);
				}
			}

			if (secondary_blacklist != null) {
				if (secondary_whitelist == null) {
					secondary_blacklist.Not ();
					secondary_whitelist = secondary_blacklist;
				} else {
					secondary_whitelist.AndNot (secondary_blacklist);
				}
			}
		}