Java Code Examples for org.apache.lucene.store.FSDirectory#getDirectory()

The following examples show how to use org.apache.lucene.store.FSDirectory#getDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MixedDirectory.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
public MixedDirectory(FileSystem readFs, Path readPath, FileSystem writeFs,
    Path writePath, Configuration conf) throws IOException {

  try {
    readDir = new FileSystemDirectory(readFs, readPath, false, conf);
    // check writeFS is a local FS?
    writeDir = FSDirectory.getDirectory(writePath.toString());

  } catch (IOException e) {
    try {
      close();
    } catch (IOException e1) {
      // ignore this one, throw the original one
    }
    throw e;
  }

  lockFactory = new NoLockFactory();
}
 
Example 2
Source File: IndexApi.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
protected IndexApi(Object /*Directory*/ indexDirObj, boolean applyAllDeletes) throws IOException {
    // Note; indexDirOjb must actually be a org.apache.lucene.store.Directory (but we don't export it
    // in the API so that it's not in the public API -- that way clients don't need to depend on it
    // as they'll usually use the other constructor which receive as File anyways).
    Directory indexDir = (Directory) indexDirObj;
    Directory resultDir = indexDir;
    if (indexDir instanceof FSDirectory) {
        FSDirectory dir = (FSDirectory) indexDir;
        java.nio.file.Path indexPath = dir.getDirectory();
        File indexFile = indexPath.toFile();
        if (!indexFile.getAbsolutePath().endsWith(lucene6dot1Suffix)) {
            File newIndexFile = new File(indexFile.getAbsolutePath() + lucene6dot1Suffix);
            resultDir = FSDirectory.open(newIndexFile.toPath());
        }
    }
    this.indexDir = resultDir;
    init(applyAllDeletes);
}
 
Example 3
Source File: MixedDirectory.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public MixedDirectory(FileSystem readFs, Path readPath, FileSystem writeFs,
    Path writePath, Configuration conf) throws IOException {

  try {
    readDir = new FileSystemDirectory(readFs, readPath, false, conf);
    // check writeFS is a local FS?
    writeDir = FSDirectory.getDirectory(writePath.toString());

  } catch (IOException e) {
    try {
      close();
    } catch (IOException e1) {
      // ignore this one, throw the original one
    }
    throw e;
  }

  lockFactory = new NoLockFactory();
}
 
Example 4
Source File: CourseServiceImpl.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
public boolean createCourseIndex() {
    List<Course> list = this.getCourses();
    try {
        Directory directory = FSDirectory.getDirectory(INDEXPATH);
        IndexWriter indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
        for (Course course : list) {
            Document doc = new Document();
            String courseTitle = course.getCourseTitle() == null ? "" : course.getCourseTitle().trim();
            String courseIntro = course.getCourseIntro() == null ? "" : course.getCourseIntro();
            String courseId = course.getCourseId() == null ? "" : course.getCourseId();
            String type = course.getType() == null ? "" : course.getType();
            String courseState = course.getCourseState() == null ? "" : course.getCourseState();
            doc.add(new Field("courseIntro", courseIntro, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            doc.add(new Field("courseTitle", courseTitle, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            doc.add(new Field("courseId", courseId, Field.Store.COMPRESS, Field.Index.NO));
            doc.add(new Field("type", type, Field.Store.COMPRESS, Field.Index.NO));
            doc.add(new Field("courseState", courseState, Field.Store.COMPRESS, Field.Index.NO));

            indexWriter.addDocument(doc);
        }
        indexWriter.optimize();
        indexWriter.close();
        return true;
    } catch (Exception e) {
        logger.error("createCourseIndex error.");
        return false;
    }
}
 
Example 5
Source File: IndexManager.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unlocks the index at the given directory if it is currently locked.
 * Otherwise, does nothing.
 * @param indexName index name
 * @throws IOException thrown if there is a problem unlocking the index.
 */
private void unlockIndex(String indexName) throws IOException {
    String path = indexWorkDir + indexName;
    File f = new File(path);
    Directory dir = FSDirectory.getDirectory(f);
    if (IndexReader.isLocked(dir)) {
        IndexReader.unlock(dir);
    }
}
 
Example 6
Source File: IndexManager.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unlocks the index at the given directory if it is currently locked.
 * Otherwise, does nothing.
 * @param indexName index name
 * @throws IOException thrown if there is a problem unlocking the index.
 */
private void unlockIndex(String indexName) throws IOException {
    String path = indexWorkDir + indexName;
    File f = new File(path);
    Directory dir = FSDirectory.getDirectory(f);
    if (IndexReader.isLocked(dir)) {
        IndexReader.unlock(dir);
    }
}
 
Example 7
Source File: left_IndexWriter_1.2.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>d</code>, replacing the index
  already there, if any. */
public IndexWriter(File path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 8
Source File: right_IndexWriter_1.22.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>path</code>, replacing the index
  already there, if any. */
public IndexWriter(String path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 9
Source File: right_IndexWriter_1.22.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>path</code>, replacing the index
  already there, if any. */
public IndexWriter(File path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 10
Source File: left_IndexWriter_1.21.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>path</code>, replacing the index
  already there, if any. */
public IndexWriter(String path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 11
Source File: left_IndexWriter_1.21.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>path</code>, replacing the index
  already there, if any. */
public IndexWriter(File path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 12
Source File: left_IndexWriter_1.2.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>d</code>, replacing the index
  already there, if any. */
public IndexWriter(String path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 13
Source File: right_IndexWriter_1.3.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>d</code>, replacing the index
  already there, if any. */
public IndexWriter(File path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 14
Source File: right_IndexWriter_1.3.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/** Constructs an IndexWriter for the index in <code>path</code>.  Text will
  be analyzed with <code>a</code>.  If <code>create</code> is true, then a
  new, empty index will be created in <code>d</code>, replacing the index
  already there, if any. */
public IndexWriter(String path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create);
}
 
Example 15
Source File: right_IndexWriter_1.42.java    From gumtree-spoon-ast-diff with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an IndexWriter for the index in <code>path</code>.
 * Text will be analyzed with <code>a</code>.  If <code>create</code>
 * is true, then a new, empty index will be created in
 * <code>path</code>, replacing the index already there, if any.
 *
 * @param path the path to the index directory
 * @param a the analyzer to use
 * @param create <code>true</code> to create the index or overwrite
 *  the existing one; <code>false</code> to append to the existing
 *  index
 * @throws IOException if the directory cannot be read/written to, or
 *  if it does not exist, and <code>create</code> is
 *  <code>false</code>
 */
public IndexWriter(String path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create, true);
}
 
Example 16
Source File: right_IndexWriter_1.42.java    From gumtree-spoon-ast-diff with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an IndexWriter for the index in <code>path</code>.
 * Text will be analyzed with <code>a</code>.  If <code>create</code>
 * is true, then a new, empty index will be created in
 * <code>path</code>, replacing the index already there, if any.
 *
 * @param path the path to the index directory
 * @param a the analyzer to use
 * @param create <code>true</code> to create the index or overwrite
 *  the existing one; <code>false</code> to append to the existing
 *  index
 * @throws IOException if the directory cannot be read/written to, or
 *  if it does not exist, and <code>create</code> is
 *  <code>false</code>
 */
public IndexWriter(File path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create, true);
}
 
Example 17
Source File: left_IndexWriter_1.41.java    From gumtree-spoon-ast-diff with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an IndexWriter for the index in <code>path</code>.
 * Text will be analyzed with <code>a</code>.  If <code>create</code>
 * is true, then a new, empty index will be created in
 * <code>path</code>, replacing the index already there, if any.
 *
 * @param path the path to the index directory
 * @param a the analyzer to use
 * @param create <code>true</code> to create the index or overwrite
 *  the existing one; <code>false</code> to append to the existing
 *  index
 * @throws IOException if the directory cannot be read/written to, or
 *  if it does not exist, and <code>create</code> is
 *  <code>false</code>
 */
public IndexWriter(String path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create, true);
}
 
Example 18
Source File: left_IndexWriter_1.41.java    From gumtree-spoon-ast-diff with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an IndexWriter for the index in <code>path</code>.
 * Text will be analyzed with <code>a</code>.  If <code>create</code>
 * is true, then a new, empty index will be created in
 * <code>path</code>, replacing the index already there, if any.
 *
 * @param path the path to the index directory
 * @param a the analyzer to use
 * @param create <code>true</code> to create the index or overwrite
 *  the existing one; <code>false</code> to append to the existing
 *  index
 * @throws IOException if the directory cannot be read/written to, or
 *  if it does not exist, and <code>create</code> is
 *  <code>false</code>
 */
public IndexWriter(File path, Analyzer a, boolean create)
     throws IOException {
  this(FSDirectory.getDirectory(path, create), a, create, true);
}