public StoredInfo DocumentToStoredInfo (Document doc) { int count = 0; StoredInfo info = new StoredInfo (); info.Uri = GetUriFromDocument (doc); foreach (Field f in doc.Fields ()) { Property prop = GetPropertyFromDocument (f, doc, false); if (prop == null) continue; switch (prop.Key) { case "fixme:indexDateTime": info.LastIndex = StringFu.StringToDateTime (prop.Value); count++; break; case "fixme:fullyIndexed": info.FullyIndexed = Convert.ToBoolean (prop.Value); count++; break; } if (count == 2) break; } return info; }
private NameInfo DocumentToNameInfo (Document doc) { NameInfo info; info = new NameInfo (); string str; str = doc.Get ("Uri"); info.Id = GuidFu.FromUriString (str); bool have_name = false; bool have_parent_id = false; bool have_is_dir = false; foreach (Field f in doc.Fields ()) { Property prop; prop = GetPropertyFromDocument (f, doc, false); if (prop == null) continue; switch (prop.Key) { case Property.ExactFilenamePropKey: info.Name = prop.Value; have_name = true; break; case Property.ParentDirUriPropKey: info.ParentId = GuidFu.FromUriString (prop.Value); have_parent_id = true; break; case Property.IsDirectoryPropKey: info.IsDirectory = (prop.Value == "true"); have_is_dir = true; break; } if (have_name && have_parent_id && have_is_dir) break; } return info; }
// Add a new field with whitespace separated names of the existing fields static protected void AddFieldProperies (Document doc) { const string Separator = " "; StringBuilder sb = new StringBuilder (); bool seen_properties = false; foreach (Fieldable f in doc.Fields ()) { if (f.Name () == "Properties") { seen_properties = true; continue; } sb.Append (f.Name ()); sb.Append (Separator); } if (sb.Length > 0) sb.Length -= Separator.Length; if (seen_properties) doc.RemoveFields ("Properties"); Field field = new Field ("Properties", sb.ToString (), Field.Store.NO, Field.Index.TOKENIZED); doc.Add (field); }
static protected Document MergeDocuments (Document doc, Document prop_change_doc) { if (doc == null) return prop_change_doc; if (prop_change_doc == null) return doc; foreach (Field f in prop_change_doc.Fields ()) { Property prop = GetPropertyFromDocument (f, prop_change_doc, false); if (prop != null && prop.IsPersistent) { Log.Debug ("Moving old persistent prop '{0}' = '{1}' forward", prop.Key, prop.Value); AddPropertyToDocument (prop, doc); } } return doc; }
static protected Document RewriteDocument (Document old_secondary_doc, Indexable prop_only_indexable) { Hashtable seen_props; seen_props = new Hashtable (); Document new_doc; new_doc = new Document (); Field uri_f; uri_f = new Field ("Uri", UriFu.UriToEscapedString (prop_only_indexable.Uri), Field.Store.YES, Field.Index.NO_NORMS); new_doc.Add (uri_f); Logger.Log.Debug ("Rewriting {0}", prop_only_indexable.DisplayUri); if (prop_only_indexable.ParentUri != null) { uri_f = new Field ("ParentUri", UriFu.UriToEscapedString (prop_only_indexable.ParentUri), Field.Store.YES, Field.Index.NO_NORMS); new_doc.Add (uri_f); Logger.Log.Debug ("Parent Uri {0}", prop_only_indexable.ParentUri); } // Add the new properties to the new document. To // delete a property, set the Value to null... then it // will be added to seen_props (so the old value will // be ignored below), but AddPropertyToDocument will // return w/o doing anything. foreach (Property prop in prop_only_indexable.Properties) { seen_props [prop.Key] = prop; // Don't add properties that are empty; they // essentially mean "reset this property" if (prop.Value == String.Empty) { Log.Debug ("Resetting prop '{0}'", prop.Key); continue; } AddPropertyToDocument (prop, new_doc); Logger.Log.Debug ("New prop '{0}' = '{1}'", prop.Key, prop.Value); } // Copy the other properties from the old document to the // new one, skipping any properties that we got new values // for out of the Indexable. if (old_secondary_doc != null) { foreach (Field f in old_secondary_doc.Fields ()) { Property prop; prop = GetPropertyFromDocument (f, old_secondary_doc, false); if (prop != null && ! seen_props.Contains (prop.Key)) { Logger.Log.Debug ("Old prop '{0}' = '{1}'", prop.Key, prop.Value); AddPropertyToDocument (prop, new_doc); } } } return new_doc; }
static protected void AddPropertiesToHit (Hit hit, Document doc, bool from_primary_index) { Property prop; foreach (Field f in doc.Fields ()) { prop = GetPropertyFromDocument (f, doc, from_primary_index); if (prop != null) hit.AddProperty (prop); } }
static private Dirent DocumentToDirent (Document doc) { string path; bool is_dir = false; path = doc.Get ("Uri"); string prop_key = "prop:k:" + Property.IsDirectoryPropKey; foreach (Field f in doc.Fields ()) { if (f.Name () != prop_key) continue; // Format of fields: from LuceneCommon.cs:AddPropertyToDocument is_dir = (f.StringValue ().Substring (3) == "true"); break; } //Logger.Log.Debug ("Found: " + path + " (" + is_dir + ")"); return new Dirent (path, is_dir); }
protected IndexDocument TranslateDocument(Document doc) { IndexDocument document = new IndexDocument(); foreach (Field f in doc.Fields()) { FieldType type = FieldType.Keyword; if (f.IsIndexed() && f.IsStored() && f.IsTokenized()) { type = FieldType.Text; } else if (f.IsIndexed() && f.IsStored() && !f.IsTokenized()) { type = FieldType.Keyword; } else if (f.IsIndexed() && !f.IsStored() && f.IsTokenized()) { type = FieldType.TextUnStored; } else if (f.IsIndexed() && !f.IsStored() && !f.IsTokenized()) { type = FieldType.UnStored; } else if (!f.IsIndexed() && f.IsStored()) { type = FieldType.UnIndexed; } document.AddField(type, f.Name(), f.StringValue()); } return document; }