本文整理汇总了Golang中github.com/balzaczyy/golucene/core/store.Directory.FileLength方法的典型用法代码示例。如果您正苦于以下问题:Golang Directory.FileLength方法的具体用法?Golang Directory.FileLength怎么用?Golang Directory.FileLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/balzaczyy/golucene/core/store.Directory
的用法示例。
在下文中一共展示了Directory.FileLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newIndexFileDeleter
/*
Initialize the deleter: find all previous commits in the Directory,
incref the files they reference, call the policy to let it delete
commits. This will remove any files not referenced by any of the
commits.
*/
func newIndexFileDeleter(directory store.Directory, policy IndexDeletionPolicy,
segmentInfos *SegmentInfos, infoStream util.InfoStream, writer *IndexWriter,
initialIndexExists bool) (*IndexFileDeleter, error) {
currentSegmentsFile := segmentInfos.SegmentsFileName()
if infoStream.IsEnabled("IFD") {
infoStream.Message("IFD", "init: current segments file is '%v'; deletePolicy=%v",
currentSegmentsFile, policy)
}
fd := &IndexFileDeleter{
infoStream: infoStream,
writer: writer,
policy: policy,
directory: directory,
refCounts: make(map[string]*RefCount),
}
// First pass: walk the files and initialize our ref counts:
currentGen := segmentInfos.generation
var currentCommitPoint *CommitPoint
var files []string
files, err := directory.ListAll()
if _, ok := err.(*store.NoSuchDirectoryError); ok {
// it means the directory is empty, so ignore it
files = make([]string, 0)
} else if err != nil {
return nil, err
}
if currentSegmentsFile != "" {
m := model.CODEC_FILE_PATTERN
for _, filename := range files {
if !strings.HasSuffix(filename, "write.lock") &&
filename != INDEX_FILENAME_SEGMENTS_GEN &&
(m.MatchString(filename) || strings.HasPrefix(filename, util.SEGMENTS)) {
// Add this file to refCounts with initial count 0:
fd.refCount(filename)
if strings.HasPrefix(filename, util.SEGMENTS) {
// This is a commit (segments or segments_N), and it's
// valid (<= the max gen). Load it, then incref all files
// it refers to:
if infoStream.IsEnabled("IFD") {
infoStream.Message("IFD", "init: load commit '%v'", filename)
}
sis := &SegmentInfos{}
err := sis.Read(directory, filename)
if os.IsNotExist(err) {
// LUCENE-948: on NFS (and maybe others), if
// you have writers switching back and forth
// between machines, it's very likely that the
// dir listing will be stale and will claim a
// file segments_X exists when in fact it
// doesn't. So, we catch this and handle it
// as if the file does not exist
if infoStream.IsEnabled("IFD") {
infoStream.Message("IFD",
"init: hit FileNotFoundException when loading commit '%v'; skipping this commit point",
filename)
}
sis = nil
} else if err != nil {
if GenerationFromSegmentsFileName(filename) <= currentGen {
length, _ := directory.FileLength(filename)
if length > 0 {
return nil, err
}
}
// Most likely we are opening an index that has an
// aborted "future" commit, so suppress exc in this case
sis = nil
} else { // sis != nil
commitPoint := newCommitPoint(fd.commitsToDelete, directory, sis)
if sis.generation == segmentInfos.generation {
currentCommitPoint = commitPoint
}
fd.commits = append(fd.commits, commitPoint)
fd.incRef(sis, true)
if fd.lastSegmentInfos == nil || sis.generation > fd.lastSegmentInfos.generation {
fd.lastSegmentInfos = sis
}
}
}
}
}
}
if currentCommitPoint == nil && currentSegmentsFile != "" && initialIndexExists {
// We did not in fact see the segments_N file corresponding to
// the segmentInfos that was passed in. Yet, it must exist,
//.........这里部分代码省略.........