//////////////////////////////////////////////////////////////// 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); }
// FIXME: Move these to LuceneCommon if and when we decide to // support adding/removing arbitrary backends at runtime internal void Close() { Log.Debug("Removing static queryable {0}", IndexName); if (text_cache != null) { text_cache.Dispose(); } // Free the cached IndexReaders LuceneCommon.CloseReader(LuceneCommon.GetReader(Driver.PrimaryStore)); LuceneCommon.CloseReader(LuceneCommon.GetReader(Driver.SecondaryStore)); Driver.PrimaryStore.Close(); Driver.SecondaryStore.Close(); FileAttributesStore.Dispose(); }
//////////////////////////////////////////////////////////////// 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); }
// Returns true if there are docs to search and creates the readers and searchers // in that case. Otherwise, returns false. private bool BuildSearchers(out IndexReader primary_reader, out LNS.IndexSearcher primary_searcher, out IndexReader secondary_reader, out LNS.IndexSearcher secondary_searcher) { primary_searcher = null; secondary_reader = null; secondary_searcher = null; primary_reader = LuceneCommon.GetReader(PrimaryStore); if (primary_reader.NumDocs() == 0) { ReleaseReader(primary_reader); primary_reader = null; return(false); } primary_searcher = new LNS.IndexSearcher(primary_reader); if (SecondaryStore != null) { secondary_reader = LuceneCommon.GetReader(SecondaryStore); if (secondary_reader.NumDocs() == 0) { ReleaseReader(secondary_reader); secondary_reader = null; } } if (secondary_reader != null) { secondary_searcher = new LNS.IndexSearcher(secondary_reader); } return(true); }
//////////////////////////////////////////////////////////////// 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); }