Beispiel #1
0
		static public Query NewTokenQuery (string token)
		{
			Query query;
			query = new Query ();

			QueryPart_Text part;
			part = new QueryPart_Text ();
			part.Text = token;
			query.AddPart (part);

			return query;
		}
Beispiel #2
0
        public RDFQuery(Uri subject, string predicate, string _object) : this()
        {
            // extract the property type from the property, and remove the prop:?: prefix
            // e.g. from prop:k:beagle:MimeType
            PropertyType ptype = PropertyType.Internal;

            if (predicate != null)
            {
                if ((predicate.Length > 7) && predicate.StartsWith("prop:"))
                {
                    switch (predicate [5])
                    {
                    case 't': ptype = PropertyType.Text; break;

                    case 'k': ptype = PropertyType.Keyword; break;

                    case 'd': ptype = PropertyType.Date; break;
                    }
                    // remove the prop:?:, which will be added by beagle later
                    predicate = predicate.Substring(7);
                }
            }

            this.Subject       = subject;
            this.Predicate     = (predicate == null ? String.Empty : predicate);
            this.PredicateType = ptype;
            this.Object        = (_object == null ? String.Empty : _object);

            // FIXME: the query contains a dummy part that will make the query
            // pass even if it is empty. Empty queries are not handled by default.
            //
            QueryPart_Text dummy = new QueryPart_Text();

            dummy.Logic = QueryPartLogic.Prohibited;
            dummy.Text  = "XXXXXXXXXXXXXXXXXXXXXXXXX";
            AddPart(dummy);
        }
Beispiel #3
0
		static private Query NewRandomQuery (int length,
						     bool allow_inexpensive,
						     bool inside_an_or)
		{
			Query query;
			query = new Query ();

			// One in four queries will contain some OR terms.
			if (! inside_an_or && random.Next (4) == 0) {
				int N = random.Next (3) + 1;
				for (int i = 0; i < N; ++i) {
					QueryPart_Or part;
					part = new QueryPart_Or ();

					int sub_length;
					sub_length = random.Next (length) + 1;
					if (sub_length < 2)
						sub_length = 2;
					
					// We generate a new query at random, and stuff its QueryParts
					// into our Or QueryPart.
					Query or_query;
					or_query = NewRandomQuery (sub_length, allow_inexpensive, true);
					foreach (QueryPart sub_part in or_query.Parts)
						part.Add (sub_part);
					
					query.AddPart (part);
				}
			}

			if (allow_inexpensive && ! inside_an_or) {
				int mime_type;
				mime_type = random.Next (3);

				QueryPart_Or mime_type_part = new QueryPart_Or ();
				QueryPart_Property part;
				part = new QueryPart_Property ();
				part.Type = PropertyType.Keyword;
				part.Key = "beagle:MimeType";

				if (mime_type == 0) {
					part.Value = "inode/directory";
					mime_type_part.Add (part);
					query.AddPart (mime_type_part);
				} else if (mime_type == 1) {
					part.Value = "text/plain";
					mime_type_part.Add (part);
					query.AddPart (mime_type_part);
				}
			}

			// Every query must contain at least
			// one required part.
			bool contains_required;
			contains_required = false;

			for (int i = 0; i < length; ++i) {
				QueryPart_Text part;
				part = new QueryPart_Text ();
				part.Text = Token.GetRandom ();

				// Prohibited parts are not allowed inside an or
				if (contains_required && ! inside_an_or) {
					if (random.Next (2) == 0)
						part.Logic = QueryPartLogic.Prohibited;
				} else {
					// This part will be required.
					contains_required = true;
				}
				
				if (random.Next (2) == 0)
					part.SearchTextProperties = false;
				else if (allow_inexpensive && random.Next (2) == 0)
					part.SearchFullText = false;
				
				query.AddPart (part);
			}

			// Note the ! inside_an_or; date range queries don't
			// work right inside OR queries when being searched
			// within the resolution of one day.  See the FIXME
			// about hit filters in LuceneCommon.cs
			if (allow_inexpensive && ! inside_an_or && random.Next (3) == 0) {
				DateTime a, b;
				FileSystemObject.PickTimestampRange (out a, out b);

				QueryPart_DateRange part;
				part = new QueryPart_DateRange ();
				part.StartDate = a;
				part.EndDate = b;
				query.AddPart (part);
			}

			return query;
		}
Beispiel #4
0
		public RDFQuery (Uri subject, string predicate, string _object) : this ()
		{
			// extract the property type from the property, and remove the prop:?: prefix
			// e.g. from prop:k:beagle:MimeType
			PropertyType ptype = PropertyType.Internal;
			
			if (predicate != null) {
				if ((predicate.Length > 7) && predicate.StartsWith ("prop:")) {
					switch (predicate [5]) {
						case 't': ptype = PropertyType.Text; break;
						case 'k': ptype = PropertyType.Keyword; break;
						case 'd': ptype = PropertyType.Date; break;
					}
					// remove the prop:?:, which will be added by beagle later
					predicate = predicate.Substring (7);
				}
			}

			this.Subject = subject;
			this.Predicate = (predicate == null ? String.Empty : predicate);
			this.PredicateType = ptype;
			this.Object = (_object == null ? String.Empty : _object);
						
			// FIXME: the query contains a dummy part that will make the query
			// pass even if it is empty. Empty queries are not handled by default.
			//
			QueryPart_Text dummy = new QueryPart_Text ();
			dummy.Logic = QueryPartLogic.Prohibited;
			dummy.Text = "XXXXXXXXXXXXXXXXXXXXXXXXX";
			AddPart (dummy);
		}