use of org.apache.lucene.store.Directory in project ansj_seg by NLPchina.
the class IndexTest method indexTest.
@Test
public void indexTest() throws CorruptIndexException, LockObtainFailedException, IOException, ParseException {
MyStaticValue.DIC.put(MyStaticValue.DIC_DEFAULT, "../../library/default.dic");
HashSet<String> hs = new HashSet<String>();
hs.add("的");
Analyzer analyzer = new AnsjIndexAnalysis(hs, false);
Directory directory = null;
IndexWriter iwriter = null;
String text = "季德胜蛇药片 10片*6板 ";
UserDefineLibrary.insertWord("蛇药片", "n", 1000);
IndexWriterConfig ic = new IndexWriterConfig(Version.LUCENE_44, analyzer);
// 建立内存索引对象
directory = new RAMDirectory();
iwriter = new IndexWriter(directory, ic);
addContent(iwriter, text);
iwriter.commit();
iwriter.close();
System.out.println("索引建立完毕");
Analyzer queryAnalyzer = new AnsjAnalysis(hs, false);
;
System.out.println("index ok to search!");
search(queryAnalyzer, directory, "\"季德胜蛇药片\"");
}
use of org.apache.lucene.store.Directory in project ansj_seg by NLPchina.
the class NearTest method createIndex.
public static void createIndex() throws Exception {
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_32, new AnsjAnalysis());
Directory directory = FSDirectory.open(new File("c:/index"));
IndexWriter writer = new IndexWriter(directory, conf);
String str = "文化人;文化人谈文化";
String[] values = str.split(";");
for (String value : values) {
Document doc = new Document();
Field field = new Field("test", value, Store.YES, Index.ANALYZED_NO_NORMS, TermVector.WITH_POSITIONS_OFFSETS);
// field.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
doc.add(field);
writer.addDocument(doc);
writer.commit();
}
writer.close();
}
use of org.apache.lucene.store.Directory in project neo4j by neo4j.
the class SimpleUniquenessVerifierTest method initLuceneResources.
@Before
public void initLuceneResources() throws Exception {
dirFactory = new DirectoryFactory.InMemoryDirectoryFactory();
Directory dir = dirFactory.open(testDir.directory("test"));
writer = new IndexWriter(dir, IndexWriterConfigs.standard());
searcherManager = new SearcherManager(writer, true, new SearcherFactory());
}
use of org.apache.lucene.store.Directory in project neo4j by neo4j.
the class PartitionedIndexStorageTest method prepareFolderRemovesFromLucene.
@Test
public void prepareFolderRemovesFromLucene() throws IOException {
File folder = createRandomFolder(testDir.graphDbDir());
Directory dir = createRandomLuceneDir(folder);
assertFalse(ArrayUtil.isEmpty(dir.listAll()));
storage.prepareFolder(folder);
assertTrue(fs.fileExists(folder));
assertTrue(ArrayUtil.isEmpty(dir.listAll()));
}
use of org.apache.lucene.store.Directory in project neo4j by neo4j.
the class PartitionedIndexStorageTest method openIndexDirectoriesForEmptyIndex.
@Test
public void openIndexDirectoriesForEmptyIndex() throws IOException {
File indexFolder = storage.getIndexFolder();
Map<File, Directory> directories = storage.openIndexDirectories();
assertTrue(directories.isEmpty());
}
Aggregations