Esempio n. 1
0
	static int DumpOneIndex_Metadata (string index_name, ArrayList uris, bool show_properties)
	{
		LuceneQueryingDriver driver;
		driver = new LuceneQueryingDriver (index_name, -1, true);

		Hashtable all_hits_by_uri = null;
		ArrayList all_hits = null;

		if (uris.Count == 0 || index_name == "FileSystemIndex") {
			all_hits_by_uri = driver.GetAllHitsByUri ();
			all_hits = new ArrayList (all_hits_by_uri.Values);
		}

		// A hard-wired hack
		if (index_name == "FileSystemIndex") { 
			foreach (Hit hit in all_hits) {
				string internal_uri;

				if (hit [Property.IsChildPropKey] == "true") {
					string path = RemapUriToPath (all_hits_by_uri, hit);
					
					internal_uri = UriFu.UriToEscapedString (hit.ParentUri);
					
					hit.ParentUri = UriFu.PathToFileUri (path);
					hit.Uri = UriFu.AddFragment (UriFu.PathToFileUri (path),
								     hit.Uri.Fragment,
								     true);
				} else {
					internal_uri = UriFu.UriToEscapedString (hit.Uri);

					hit.Uri = UriFu.PathToFileUri (RemapUriToPath (all_hits_by_uri, hit));
					hit.AddProperty (Property.NewUnsearched ("beagrep:InternalUri", internal_uri));
				}
			}
		}

		ArrayList matching_hits;

		if (uris.Count == 0)
			matching_hits = all_hits;
		else {
			matching_hits = new ArrayList (driver.GetHitsForUris (RemapUris (driver, uris)));

			if (index_name == "FileSystemIndex") {
				for (int i = 0; i < matching_hits.Count; i++) {
					Hit hit = (Hit) matching_hits [i];
					Hit mapped_hit = (Hit) all_hits_by_uri [hit.Uri];

					matching_hits [i] = mapped_hit;
				}
			}
		}

		matching_hits.Sort (new HitByUriComparer ());

		foreach (Hit hit in matching_hits) {

			if (! show_properties) {
				Console.WriteLine ("{0}: {1}", index_name, hit.Uri);
				continue;
			}

			Console.WriteLine (" Index: {0}", index_name);
			Console.WriteLine ("   Uri: {0}", hit.Uri);
			if (hit.ParentUri != null)
				Console.WriteLine ("Parent: {0}", hit.ParentUri);
			Console.WriteLine (" MimeT: {0}", hit.MimeType);
			Console.WriteLine ("  Type: {0}", hit.Type);
			Console.WriteLine ("Source: {0}", hit.Source);

			ArrayList props;
			props = new ArrayList (hit.Properties);
			props.Sort ();
			foreach (Property prop in props) {
				char [] legend = new char [4];

				legend [0] = prop.IsMutable  ? 'm' : ' ';
				legend [1] = prop.IsSearched ? 's' : ' ';
				legend [2] = prop.IsPersistent ? 'p' : ' ';
				legend [3] = prop.Type == PropertyType.Text ? 't' : ' ';

				Console.WriteLine ("  Prop: [{0}] {1} = '{2}'", new String (legend), prop.Key, prop.Value);
			}
				

			Console.WriteLine ();
		}

		return matching_hits.Count;
	}