private Lucene.Net.Store.Directory CreateLuceneIndex(IEnumerable <PackageVersion> packages, string luceneDirectory)
        {
            Lucene.Net.Store.Directory directory;
            if (luceneDirectory != null)
            {
                var directoryInfo = new DirectoryInfo(luceneDirectory);
                directoryInfo.Create();
                directory = new SimpleFSDirectory(directoryInfo);
            }
            else
            {
                directory = new RAMDirectoryWrapper();
            }

            using (var indexWriter = DocumentCreator.CreateIndexWriter(directory, true))
            {
                foreach (var version in packages)
                {
                    var metadata = GetPackageMetadata(version);
                    var document = DocumentCreator.CreateDocument(metadata);
                    indexWriter.AddDocument(document);
                }

                indexWriter.Commit();
            }

            return(directory);
        }