//////////////////////////////////////////////////////////////// public Uri[] PropertyQuery(Property prop) { // FIXME: Should we support scanning the secondary // index as well? IndexReader primary_reader; primary_reader = LuceneCommon.GetReader(PrimaryStore); Term term; term = new Term(PropertyToFieldName(prop.Type, prop.Key), prop.Value.ToLower()); TermDocs term_docs; term_docs = primary_reader.TermDocs(); term_docs.Seek(term); ArrayList uri_list = new ArrayList(); while (term_docs.Next()) { Document doc = primary_reader.Document(term_docs.Doc()); uri_list.Add(GetUriFromDocument(doc)); } term_docs.Close(); LuceneCommon.ReleaseReader(primary_reader); return((Uri[])uri_list.ToArray(typeof(Uri))); }
//////////////////////////////////////////////////////////////// public bool HasUri(Uri uri) { IndexReader primary_reader; primary_reader = LuceneCommon.GetReader(PrimaryStore); Term term; term = new Term("Uri", UriFu.UriToEscapedString(uri)); TermDocs term_docs; term_docs = primary_reader.TermDocs(); term_docs.Seek(term); bool has_uri = false; if (term_docs.Next()) { has_uri = true; } term_docs.Close(); LuceneCommon.ReleaseReader(primary_reader); return(has_uri); }
//////////////////////////////////////////////////////////////// public NameInfo GetNameInfoById(Guid id) { Uri uri; uri = GuidFu.ToUri(id); IndexReader reader; reader = LuceneCommon.GetReader(SecondaryStore); TermDocs term_docs; term_docs = reader.TermDocs(); Term term = new Term("Uri", UriFu.UriToEscapedString(uri)); term_docs.Seek(term); int match_id = -1; if (term_docs.Next()) { match_id = term_docs.Doc(); } term_docs.Close(); NameInfo info = null; if (match_id != -1) { Document doc; doc = reader.Document(match_id, fields_nameinfo); info = DocumentToNameInfo(doc); } LuceneCommon.ReleaseReader(reader); return(info); }
//////////////////////////////////////////////////////////////// public Guid GetIdByNameAndParentId(string name, Guid parent_id) { string parent_uri_str; parent_uri_str = GuidFu.ToUriString(parent_id); string key1, key2; key1 = PropertyToFieldName(PropertyType.Keyword, Property.ParentDirUriPropKey); key2 = PropertyToFieldName(PropertyType.Keyword, Property.ExactFilenamePropKey); Term term1, term2; term1 = new Term(key1, parent_uri_str); term2 = new Term(key2, name.ToLower()); // Lets walk the exact file name terms first (term2) // since there are probably fewer than parent directory // Uri terms. List <int> term2_doc_ids = new List <int> (); IndexReader reader = LuceneCommon.GetReader(SecondaryStore); TermDocs term_docs = reader.TermDocs(); term_docs.Seek(term2); while (term_docs.Next()) { term2_doc_ids.Add(term_docs.Doc()); } term_docs.Seek(term1); int match_id = -1; while (term_docs.Next()) { int doc_id = term_docs.Doc(); if (term2_doc_ids.BinarySearch(doc_id) >= 0) { match_id = doc_id; break; } } term_docs.Close(); Guid id; if (match_id != -1) { Document doc; doc = reader.Document(match_id); id = GuidFu.FromUriString(doc.Get("Uri")); } else { id = Guid.Empty; } LuceneCommon.ReleaseReader(reader); return(id); }