示例#1
0
		        public Hit (uint id, Beagle.Hit hit, string[] fields, Query query)
			{
				this.id = id;
				bHit = hit;
				hitValue = new object[fields.Length];
				int i = 0;

				uri = hit.Uri;

				foreach (string field in fields) {
					// We add String.Empty to attributes because they may be null and we cannot
					// return null objects over DBus
					string[] bfields = Ontologies.XesamToBeagleField (field);

					switch (bfields [0]) {
					case "uri":
						hitValue [i++] = hit.Uri.ToString ();
						break;

					case "mimetype":
						hitValue [i++] = hit.MimeType + String.Empty;
						break;

					case "date":
						hitValue [i++] = hit.Timestamp.ToString ("s");
						break;

					case "snippet":
						SnippetRequest sreq = new SnippetRequest (query, hit);
						SnippetResponse sresp = (SnippetResponse) sreq.Send ();
						hitValue [i++] = sresp.Snippet != null ? sresp.Snippet : String.Empty;
						break;
					    
					default:
						// FIXME: This *will* break since we don't know what the expected
						// type here is, and we're always using strings
						
						List<string> values = new List<string> ();

						foreach (string bfield in bfields) {
							string[] prop = hit.GetProperties (bfield);

							if (prop != null)
								values.AddRange (prop);
						}

						if (values.Count == 0)
							// No values found
							hitValue [i++] = String.Empty;
						else if (values.Count == 1)
							// Only one value -- return as string
							hitValue [i++] = values [0];
						else
							// Multiple values -- returns as string[]
							hitValue [i++] = values.ToArray ();

						break;
					}
				}
			}
示例#2
0
	private static void OnHitsAdded (HitsAddedResponse response)
	{
		lastQueryTime = DateTime.Now;

		if (count == 0 && verbose) {
			Console.WriteLine ("First hit returned in {0:0.000}s",
					   (lastQueryTime - queryStartTime).TotalSeconds);
		}

		if (verbose) {
			if (response.NumMatches >= 0)
				Console.WriteLine ("Returned latest {0} results out of total {1} matches", response.Hits.Count, response.NumMatches);
			else
				Console.WriteLine ("Returned latest {0} results", response.Hits.Count);
		}

		if (! display_hits) {
			count += response.Hits.Count;
			return;
		}

		foreach (Hit hit in response.Hits) {
			string uri = (raw_uri ?  hit.Uri.OriginalString : UriFu.EscapedUriToString (hit.Uri));
			if (verbose)
				Console.WriteLine ("  Uri: {0}", uri);
			else
				Console.WriteLine (uri);

			if (verbose) {
				SnippetRequest sreq = new SnippetRequest (query, hit);
				if (display_cached_text)
					sreq.FullText = true;

				SnippetResponse sresp = (SnippetResponse) sreq.Send ();
				Console.WriteLine ("PaUri: {0}", hit.ParentUri != null ? hit.ParentUri.ToString () : "(null)");
				if (! display_cached_text)
					Console.WriteLine (" Snip: {0}", sresp.Snippet != null ? sresp.Snippet : "(null)");
				Console.WriteLine (" Type: {0}", hit.Type);
				Console.WriteLine ("MimeT: {0}", hit.MimeType == null ? "(null)" : hit.MimeType);
				Console.WriteLine ("  Src: {0}", hit.Source);
				Console.WriteLine ("Score: {0}", hit.Score);
				if (hit.ValidTimestamp)
					Console.WriteLine (" Time: {0}", DateTimeUtil.ToString (hit.Timestamp));
				
				foreach (Property prop in hit.Properties)
					Console.WriteLine ("    {0} = '{1}'",
						prop.Key,
						(prop.Type != PropertyType.Date ? prop.Value : DateTimeUtil.ToString (StringFu.StringToDateTime (prop.Value))));
				

				if (display_cached_text) {
					Console.WriteLine ("-- Cache -------------------------------------");
					if (sresp.SnippetList.Snippets == null)
						Console.WriteLine ("(empty)");
					else {
						foreach (SnippetLine snippet_line in sresp.SnippetList.Snippets) {
							if (snippet_line == null || snippet_line.Fragments == null)
								Console.WriteLine ("(empty)");
							else
								Console.WriteLine (((Fragment)snippet_line.Fragments [0]).Text);
						}
					}
					Console.WriteLine ("----------------------------------------------");
				}
				Console.WriteLine ();
			}

			++count;
		}
	}