本文整理汇总了Java中org.apache.lucene.store.IndexOutput.writeString方法的典型用法代码示例。如果您正苦于以下问题:Java IndexOutput.writeString方法的具体用法?Java IndexOutput.writeString怎么用?Java IndexOutput.writeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.store.IndexOutput
的用法示例。
在下文中一共展示了IndexOutput.writeString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CompletionFieldsConsumer
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public CompletionFieldsConsumer(SegmentWriteState state) throws IOException {
this.delegatesFieldsConsumer = delegatePostingsFormat.fieldsConsumer(state);
String suggestFSTFile = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
IndexOutput output = null;
boolean success = false;
try {
output = state.directory.createOutput(suggestFSTFile, state.context);
CodecUtil.writeHeader(output, CODEC_NAME, SUGGEST_VERSION_CURRENT);
/*
* we write the delegate postings format name so we can load it
* without getting an instance in the ctor
*/
output.writeString(delegatePostingsFormat.getName());
output.writeString(writeProvider.getName());
this.suggestFieldsConsumer = writeProvider.consumer(output);
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(output);
}
}
}
示例2: write
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Save a single segment's info. */
@Override
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene40SegmentInfoFormat.SI_EXTENSION);
si.addFile(fileName);
final IndexOutput output = dir.createOutput(fileName, ioContext);
boolean success = false;
try {
CodecUtil.writeHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT);
// Write the Lucene version that created this segment, since 3.1
output.writeString(si.getVersion().toString());
output.writeInt(si.getDocCount());
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
output.writeStringStringMap(si.getDiagnostics());
output.writeStringStringMap(Collections.<String,String>emptyMap());
output.writeStringSet(si.files());
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(output);
// TODO: why must we do this? do we not get tracking dir wrapper?
IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
} else {
output.close();
}
}
}
示例3: write
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Save a single segment's info. */
@Override
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene46SegmentInfoFormat.SI_EXTENSION);
si.addFile(fileName);
final IndexOutput output = dir.createOutput(fileName, ioContext);
boolean success = false;
try {
CodecUtil.writeHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT);
Version version = si.getVersion();
if (version.major < 3 || version.major > 4) {
throw new IllegalArgumentException("invalid major version: should be 3 or 4 but got: " + version.major + " segment=" + si);
}
// Write the Lucene version that created this segment, since 3.1
output.writeString(version.toString());
output.writeInt(si.getDocCount());
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
output.writeStringStringMap(si.getDiagnostics());
output.writeStringSet(si.files());
CodecUtil.writeFooter(output);
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(output);
// TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?
IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
} else {
output.close();
}
}
}
示例4: testDummy
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public void testDummy() throws Exception {
MockDirectoryWrapper dir = newMockDirectory();
dir.setAssertNoUnrefencedFilesOnClose(true);
IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
iw.addDocument(new Document());
iw.close();
IndexOutput output = dir.createOutput("_hello.world", IOContext.DEFAULT);
output.writeString("i am unreferenced!");
output.close();
dir.sync(Collections.singleton("_hello.world"));
dir.close();
}
示例5: writeToIndexOutput
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/**
* Writes the object vectors to this Lucene output stream.
* Caller is responsible for opening and closing stream output stream.
*/
public static void writeToIndexOutput(VectorStore objectVectors, FlagConfig flagConfig, IndexOutput outputStream)
throws IOException {
// Write header giving vector type and dimension for all vectors.
outputStream.writeString(generateHeaderString(flagConfig));
Enumeration<ObjectVector> vecEnum = objectVectors.getAllVectors();
// Write each vector.
while (vecEnum.hasMoreElements()) {
ObjectVector objectVector = vecEnum.nextElement();
outputStream.writeString(objectVector.getObject().toString());
objectVector.getVector().writeToLuceneStream(outputStream);
}
VerbatimLogger.info("finished writing vectors.\n");
}
示例6: testListWithinTransaction
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Test
public void testListWithinTransaction() throws IOException {
final Connection con = DataSourceUtils.getConnection(dataSource);
jdbcDirectory.create();
String[] list = jdbcDirectory.listAll();
Assert.assertEquals(0, list.length);
final IndexOutput indexOutput = jdbcDirectory.createOutput("test1", new IOContext());
indexOutput.writeString("TEST STRING");
indexOutput.close();
jdbcTemplate.executeSelect("select * from test", new JdbcTemplate.ExecuteSelectCallback() {
@Override
public void fillPrepareStatement(final PreparedStatement ps) throws Exception {
}
@Override
public Object execute(final ResultSet rs) throws Exception {
Assert.assertTrue(rs.next());
return null;
}
});
list = jdbcDirectory.listAll();
Assert.assertEquals(1, list.length);
jdbcDirectory.deleteFile("test1");
list = jdbcDirectory.listAll();
Assert.assertEquals(0, list.length);
DataSourceUtils.rollbackConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
}
示例7: testDeleteContent
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Test
public void testDeleteContent() throws IOException {
Connection con = DataSourceUtils.getConnection(dataSource);
jdbcDirectory.create();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
con = DataSourceUtils.getConnection(dataSource);
String[] list = jdbcDirectory.listAll();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
Assert.assertEquals(0, list.length);
con = DataSourceUtils.getConnection(dataSource);
final IndexOutput indexOutput = jdbcDirectory.createOutput("test1", new IOContext());
indexOutput.writeString("TEST STRING");
indexOutput.close();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
con = DataSourceUtils.getConnection(dataSource);
list = jdbcDirectory.listAll();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
Assert.assertEquals(1, list.length);
con = DataSourceUtils.getConnection(dataSource);
jdbcDirectory.deleteContent();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
con = DataSourceUtils.getConnection(dataSource);
list = jdbcDirectory.listAll();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
Assert.assertEquals(0, list.length);
}
示例8: write3xInfo
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Deprecated
public static String write3xInfo(Directory dir, SegmentInfo si, IOContext context) throws IOException {
// Defensive check: we are about to write this SI in 3.x format, dropping all codec information, etc.
// so it had better be a 3.x segment or you will get very confusing errors later.
if ((si.getCodec() instanceof Lucene3xCodec) == false) {
throw new IllegalStateException("cannot write 3x SegmentInfo unless codec is Lucene3x (got: " + si.getCodec() + ")");
}
// NOTE: this is NOT how 3.x is really written...
String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION);
si.addFile(fileName);
//System.out.println("UPGRADE write " + fileName);
boolean success = false;
IndexOutput output = dir.createOutput(fileName, context);
try {
CodecUtil.writeHeader(output, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME,
Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT);
// Write the Lucene version that created this segment, since 3.1
output.writeString(si.getVersion().toString());
output.writeInt(si.getDocCount());
output.writeStringStringMap(si.attributes());
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
output.writeStringStringMap(si.getDiagnostics());
output.writeStringSet(si.files());
output.close();
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(output);
try {
si.dir.deleteFile(fileName);
} catch (Throwable t) {
// Suppress so we keep throwing the original exception
}
}
}
return fileName;
}
示例9: main
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
VectorStoreRAM objectVectors = new VectorStoreRAM(flagConfig);
String[] argsRemaining = flagConfig.remainingArgs;
String incomingVecs = argsRemaining[0];
int newDimension = Integer.parseInt(argsRemaining[1]);
objectVectors.initFromFile(incomingVecs);
if (newDimension > flagConfig.dimension())
{
System.out.println("Incoming file has dimensionality of " +flagConfig.dimension());
System.out.println("New dimensionality must be less than incoming vector length, quitting");
System.exit(0);
}
String vectorFileName = incomingVecs.replaceAll("\\.bin", "")+"_"+newDimension+".bin";
File vectorFile = new File(vectorFileName);
String parentPath = vectorFile.getParent();
if (parentPath == null) parentPath = "";
FSDirectory fsDirectory = FSDirectory.open(FileSystems.getDefault().getPath(parentPath));
IndexOutput outputStream = fsDirectory.createOutput(vectorFile.getName(), IOContext.DEFAULT);
flagConfig.setDimension(newDimension);
outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
Enumeration<ObjectVector> vecEnum = objectVectors.getAllVectors();
// Write each vector.
while (vecEnum.hasMoreElements()) {
ObjectVector objectVector = vecEnum.nextElement();
outputStream.writeString(objectVector.getObject().toString());
objectVector.getVector().writeToLuceneStream(outputStream,flagConfig.dimension());
}
outputStream.close();
fsDirectory.close();
VerbatimLogger.info("wrote "+objectVectors.getNumVectors()+" vectors to file "+ vectorFileName);
VerbatimLogger.info("finished writing vectors.\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Usage: VectorStoreTruncater incomingFile.bin newDimensinoality");
}
}
示例10: testList
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Test
public void testList() throws IOException {
Connection con = DataSourceUtils.getConnection(dataSource);
jdbcDirectory.create();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
con = DataSourceUtils.getConnection(dataSource);
String[] list = jdbcDirectory.listAll();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
Assert.assertEquals(0, list.length);
con = DataSourceUtils.getConnection(dataSource);
final IndexOutput indexOutput = jdbcDirectory.createOutput("test1", new IOContext());
indexOutput.writeString("TEST STRING");
indexOutput.close();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
jdbcTemplate.executeSelect("select * from test", new JdbcTemplate.ExecuteSelectCallback() {
@Override
public void fillPrepareStatement(final PreparedStatement ps) throws Exception {
}
@Override
public Object execute(final ResultSet rs) throws Exception {
Assert.assertTrue(rs.next());
return null;
}
});
con = DataSourceUtils.getConnection(dataSource);
list = jdbcDirectory.listAll();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
Assert.assertEquals(1, list.length);
con = DataSourceUtils.getConnection(dataSource);
jdbcDirectory.deleteFile("test1");
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
con = DataSourceUtils.getConnection(dataSource);
list = jdbcDirectory.listAll();
DataSourceUtils.commitConnectionIfPossible(con);
DataSourceUtils.releaseConnection(con);
Assert.assertEquals(0, list.length);
}