Exemple #1
0
        // Returns a list of all files and directories in dir
        static ICollection GetAllItemsInDirectory(DirectoryInfo dir)
        {
            // form the query
            string parent_uri_str = PathToUri(dir.FullName).ToString();

            // Instead of taking the painfull way of using BeagrepAnalyzer, lets just add the prefix manually
            // LuceneCommon thinks exposing secret property type encoding is bad, I think so too... except for now
            string key = "prop:k:" + Property.ParentDirUriPropKey;

            //Logger.Log.Debug ("Querying for {0}={1}", parent_uri_str, key);
            LNS.Query query = new LNS.TermQuery(new Term(key, parent_uri_str));

            // do the search
            LNS.IndexSearcher searcher;
            searcher = LuceneCommon.GetSearcher(driver.PrimaryStore);

            BetterBitArray matches;

            matches = new BetterBitArray(searcher.MaxDoc());

            BitArrayHitCollector collector;

            collector = new BitArrayHitCollector(matches);

            searcher.Search(query, null, collector);

            // Finally we pull all of the matching documents,
            // convert them to Dirent, and store them in a list.

            ArrayList match_list = new ArrayList();
            int       i          = 0;

            while (i < matches.Count)
            {
                i = matches.GetNextTrueIndex(i);
                if (i >= matches.Count)
                {
                    break;
                }

                Document doc;
                doc = searcher.Doc(i);

                Dirent info;
                info = DocumentToDirent(doc);

                match_list.Add(info);

                ++i;
            }

            LuceneCommon.ReleaseSearcher(searcher);
            //Logger.Log.Debug ("Found {0} items in {1}", match_list.Count, dir.FullName);

            return(match_list);
        }
Exemple #2
0
        public StoredInfo GetStoredInfo(Uri uri)
        {
            StoredInfo info = new StoredInfo();

            LNS.Query          query     = UriQuery("Uri", uri);
            SingletonCollector collector = new SingletonCollector();

            LNS.IndexSearcher searcher = LuceneCommon.GetSearcher(PrimaryStore);
            searcher.Search(query, null, collector);

            if (collector.MatchId != -1)
            {
                Document doc = searcher.Doc(collector.MatchId);
                info = DocumentToStoredInfo(doc);
            }

            LuceneCommon.ReleaseSearcher(searcher);

            return(info);
        }
Exemple #3
0
        public Hashtable GetStoredUriStrings(string server, string file)
        {
            Hashtable uris = new Hashtable();

            Term term = new Term(PropertyToFieldName(PropertyType.Keyword, "fixme:file"), file);

            LNS.QueryFilter filter = new LNS.QueryFilter(new LNS.TermQuery(term));

            term = new Term(PropertyToFieldName(PropertyType.Keyword, "fixme:account"), server);
            LNS.TermQuery query = new LNS.TermQuery(term);

            LNS.IndexSearcher searcher = LuceneCommon.GetSearcher(PrimaryStore);
            LNS.Hits          hits     = searcher.Search(query, filter);

            for (int i = 0; i < hits.Length(); i++)
            {
                StoredInfo info = DocumentToStoredInfo(hits.Doc(i));
                uris.Add(info.Uri.ToString(), info.FullyIndexed);
            }

            LuceneCommon.ReleaseSearcher(searcher);

            return(uris);
        }
        // Return all directories with name
        public ICollection GetAllDirectoryNameInfo(string name)
        {
            // First we assemble a query to find all of the directories.
            string field_name;

            field_name = PropertyToFieldName(PropertyType.Keyword,
                                             Property.IsDirectoryPropKey);
            LNS.Query isdir_query = new LNS.TermQuery(new Term(field_name, "true"));

            LNS.Query query = null;

            if (name == null)
            {
                query = isdir_query;
            }
            else
            {
                string dirname_field;
                dirname_field = PropertyToFieldName(PropertyType.Text,
                                                    Property.TextFilenamePropKey);
                LNS.Query dirname_query;
                dirname_query = LuceneCommon.StringToQuery(dirname_field, name, null);
                LNS.BooleanQuery bool_query = new LNS.BooleanQuery();
                bool_query.Add(isdir_query, LNS.BooleanClause.Occur.MUST);
                bool_query.Add(dirname_query, LNS.BooleanClause.Occur.MUST);

                query = bool_query;
            }

            // Then we actually run the query
            LNS.IndexSearcher searcher;
            //searcher = new LNS.IndexSearcher (SecondaryStore);
            searcher = LuceneCommon.GetSearcher(SecondaryStore);

            BetterBitArray matches;

            matches = new BetterBitArray(searcher.MaxDoc());

            BitArrayHitCollector collector;

            collector = new BitArrayHitCollector(matches);

            searcher.Search(query, null, collector);

            // Finally we pull all of the matching documents,
            // convert them to NameInfo, and store them in a list.

            ArrayList match_list = new ArrayList();
            int       i          = 0;

            while (i < matches.Count)
            {
                i = matches.GetNextTrueIndex(i);
                if (i >= matches.Count)
                {
                    break;
                }

                Document doc;
                doc = searcher.Doc(i, fields_nameinfo);

                NameInfo info;
                info = DocumentToNameInfo(doc);

                match_list.Add(info);

                ++i;
            }

            LuceneCommon.ReleaseSearcher(searcher);

            return(match_list);
        }