use of org.apache.lucene.store.RAMDirectory in project ansj_seg by NLPchina.
the class PhraseTest method main.
public static void main(String[] args) throws IOException, ParseException {
DicLibrary.insert(DicLibrary.DEFAULT, "上网人");
DicLibrary.insert(DicLibrary.DEFAULT, "网人");
AnsjAnalyzer ansjAnalyzer = new AnsjAnalyzer(AnsjAnalyzer.TYPE.index_ansj);
TokenStream tokenStream = ansjAnalyzer.tokenStream("上网人员测试", "test");
while (tokenStream.incrementToken()) {
System.out.println(tokenStream.getAttribute(CharTermAttribute.class));
}
IndexWriterConfig config = new IndexWriterConfig(ansjAnalyzer);
IndexWriter writer = new IndexWriter(new RAMDirectory(), config);
Document doc = new Document();
doc.add(new TextField("test", "上网人员测试", Field.Store.YES));
writer.addDocument(doc);
writer.commit();
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(writer));
System.out.println(searcher.count(new TermQuery(new Term("test", "网人"))));
Query q = new QueryParser("test", new AnsjAnalyzer(AnsjAnalyzer.TYPE.index_ansj)).parse("\"上网人\"");
System.out.println(q);
System.out.println(searcher.count(q));
}
use of org.apache.lucene.store.RAMDirectory 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.RAMDirectory in project languagetool by languagetool-org.
the class PatternRuleQueryBuilderTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
language = new English();
directory = new RAMDirectory();
/*File indexPath = new File("/tmp/lucene");
if (indexPath.exists()) {
FileUtils.deleteDirectory(indexPath);
}
directory = FSDirectory.open(indexPath);*/
Analyzer analyzer = Indexer.getAnalyzer(language);
IndexWriterConfig config = Indexer.getIndexWriterConfig(analyzer);
try (IndexWriter writer = new IndexWriter(directory, config)) {
addDocument(writer, "How do you thin about this wonderful idea?");
addDocument(writer, "The are several grammar checkers for English, E.G. LanguageTool 123.");
}
reader = DirectoryReader.open(directory);
searcher = newSearcher(reader);
}
use of org.apache.lucene.store.RAMDirectory in project languagetool by languagetool-org.
the class IndexerSearcherTest method createIndex.
private void createIndex(String content) throws IOException {
directory = new RAMDirectory();
//directory = FSDirectory.open(new File("/tmp/lucenetest")); // for debugging
Indexer.run(content, directory, new English());
errorSearcher = new Searcher(directory);
}
use of org.apache.lucene.store.RAMDirectory in project neo4j by neo4j.
the class LuceneSchemaIndexPopulatorTest method before.
@Before
public void before() throws Exception {
directory = new RAMDirectory();
DirectoryFactory directoryFactory = new DirectoryFactory.Single(new DirectoryFactory.UncloseableDirectory(directory));
provider = new LuceneSchemaIndexProvider(fs.get(), directoryFactory, testDir.directory("folder"), NullLogProvider.getInstance(), Config.empty(), OperationalMode.single);
indexStoreView = mock(IndexStoreView.class);
IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
indexPopulator = provider.getPopulator(indexId, index, samplingConfig);
indexPopulator.create();
indexPopulator.configureSampling(true);
}
Aggregations