Search in sources :

Example 16 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class LuceneTestCase method newDirectoryImpl.

static Directory newDirectoryImpl(Random random, String clazzName, LockFactory lf) {
    if (clazzName.equals("random")) {
        if (rarely(random)) {
            clazzName = RandomPicks.randomFrom(random, CORE_DIRECTORIES);
        } else {
            clazzName = "RAMDirectory";
        }
    }
    try {
        final Class<? extends Directory> clazz = CommandLineUtil.loadDirectoryClass(clazzName);
        // If it is a FSDirectory type, try its ctor(Path)
        if (FSDirectory.class.isAssignableFrom(clazz)) {
            final Path dir = createTempDir("index-" + clazzName);
            return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir, lf);
        }
        // FSDir subclass:
        try {
            Constructor<? extends Directory> pathCtor = clazz.getConstructor(Path.class, LockFactory.class);
            final Path dir = createTempDir("index");
            return pathCtor.newInstance(dir, lf);
        } catch (NoSuchMethodException nsme) {
        // Ignore
        }
        // the remaining dirs are no longer filesystem based, so we must check that the passedLockFactory is not file based:
        if (!(lf instanceof FSLockFactory)) {
            // try ctor with only LockFactory (e.g. RAMDirectory)
            try {
                return clazz.getConstructor(LockFactory.class).newInstance(lf);
            } catch (NoSuchMethodException nsme) {
            // Ignore
            }
        }
        // try empty ctor
        return clazz.newInstance();
    } catch (Exception e) {
        Rethrow.rethrow(e);
        // dummy to prevent compiler failure
        throw null;
    }
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FSLockFactory(org.apache.lucene.store.FSLockFactory) FSDirectory(org.apache.lucene.store.FSDirectory) FSLockFactory(org.apache.lucene.store.FSLockFactory) LockFactory(org.apache.lucene.store.LockFactory) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException)

Example 17 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class TestUtil method enableVirusChecker.

public static void enableVirusChecker(Directory in) {
    Directory dir = FilterDirectory.unwrap(in);
    if (dir instanceof FSDirectory) {
        FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
        while (fs instanceof FilterFileSystem) {
            FilterFileSystem ffs = (FilterFileSystem) fs;
            if (ffs.getParent() instanceof VirusCheckingFS) {
                VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
                vfs.enable();
                return;
            }
            fs = ffs.getDelegate();
        }
    }
}
Also used : FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FSDirectory(org.apache.lucene.store.FSDirectory) VirusCheckingFS(org.apache.lucene.mockfile.VirusCheckingFS) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory)

Example 18 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class TestUtil method disableVirusChecker.

/** Returns true if VirusCheckingFS is in use and was in fact already enabled */
public static boolean disableVirusChecker(Directory in) {
    Directory dir = FilterDirectory.unwrap(in);
    if (dir instanceof FSDirectory) {
        FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
        while (fs instanceof FilterFileSystem) {
            FilterFileSystem ffs = (FilterFileSystem) fs;
            if (ffs.getParent() instanceof VirusCheckingFS) {
                VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
                boolean isEnabled = vfs.isEnabled();
                vfs.disable();
                return isEnabled;
            }
            fs = ffs.getDelegate();
        }
    }
    return false;
}
Also used : FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FSDirectory(org.apache.lucene.store.FSDirectory) VirusCheckingFS(org.apache.lucene.mockfile.VirusCheckingFS) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory)

Example 19 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class SolrDeletionPolicy method getId.

private String getId(IndexCommit commit) {
    StringBuilder sb = new StringBuilder();
    Directory dir = commit.getDirectory();
    // be the same, regardless of the Directory instance.
    if (dir instanceof FSDirectory) {
        FSDirectory fsd = (FSDirectory) dir;
        File fdir = fsd.getDirectory().toFile();
        sb.append(fdir.getPath());
    } else {
        sb.append(dir);
    }
    sb.append('/');
    sb.append(commit.getGeneration());
    return sb.toString();
}
Also used : FSDirectory(org.apache.lucene.store.FSDirectory) File(java.io.File) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 20 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class StandardDirectoryFactory method move.

/**
   * Override for more efficient moves.
   * 
   * Intended for use with replication - use
   * carefully - some Directory wrappers will
   * cache files for example.
   * 
   * You should first {@link Directory#sync(java.util.Collection)} any file that will be 
   * moved or avoid cached files through settings.
   * 
   * @throws IOException
   *           If there is a low-level I/O error.
   */
@Override
public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext) throws IOException {
    Directory baseFromDir = getBaseDir(fromDir);
    Directory baseToDir = getBaseDir(toDir);
    if (baseFromDir instanceof FSDirectory && baseToDir instanceof FSDirectory) {
        Path path1 = ((FSDirectory) baseFromDir).getDirectory().toAbsolutePath();
        Path path2 = ((FSDirectory) baseToDir).getDirectory().toAbsolutePath();
        try {
            Files.move(path1.resolve(fileName), path2.resolve(fileName), StandardCopyOption.ATOMIC_MOVE);
        } catch (AtomicMoveNotSupportedException e) {
            Files.move(path1.resolve(fileName), path2.resolve(fileName));
        }
        return;
    }
    super.move(fromDir, toDir, fileName, ioContext);
}
Also used : Path(java.nio.file.Path) FSDirectory(org.apache.lucene.store.FSDirectory) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Aggregations

FSDirectory (org.apache.lucene.store.FSDirectory)43 File (java.io.File)18 Directory (org.apache.lucene.store.Directory)12 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 IndexSearcher (org.apache.lucene.search.IndexSearcher)9 FileNotFoundException (java.io.FileNotFoundException)5 FileSystem (java.nio.file.FileSystem)5 Document (org.apache.lucene.document.Document)5 IndexReader (org.apache.lucene.index.IndexReader)5 MMapDirectory (org.apache.lucene.store.MMapDirectory)5 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)5 FilterDirectory (org.apache.lucene.store.FilterDirectory)4 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)4 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 Term (org.apache.lucene.index.Term)3 WindowsFS (org.apache.lucene.mockfile.WindowsFS)3 TermQuery (org.apache.lucene.search.TermQuery)3