Java Code Examples for org.apache.lucene.analysis.core.SimpleAnalyzer

The following examples show how to use org.apache.lucene.analysis.core.SimpleAnalyzer. These examples are extracted from open source projects. 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
private List<Document> runQuery(final File indexDirectory, final List<File> storageDirs, final String query) throws IOException, ParseException {
    try (final DirectoryReader directoryReader = DirectoryReader.open(FSDirectory.open(indexDirectory))) {
        final IndexSearcher searcher = new IndexSearcher(directoryReader);

        final Analyzer analyzer = new SimpleAnalyzer();
        final org.apache.lucene.search.Query luceneQuery = new QueryParser("uuid", analyzer).parse(query);

        final Query q = new Query("");
        q.setMaxResults(1000);
        final TopDocs topDocs = searcher.search(luceneQuery, 1000);

        final List<Document> docs = new ArrayList<>();
        for (final ScoreDoc scoreDoc : topDocs.scoreDocs) {
            final int docId = scoreDoc.doc;
            final Document d = directoryReader.document(docId);
            docs.add(d);
        }

        return docs;
    }
}
 
Example 2
Source Project: arcusplatform   Source File: ProductIndex.java    License: Apache License 2.0 6 votes vote down vote up
public List<ProductCatalogEntry> search(String queryString) throws IOException, ParseException {
	List<ProductCatalogEntry> results = new ArrayList<ProductCatalogEntry>();
	
	IndexReader reader = DirectoryReader.open(dir);
	IndexSearcher searcher = new IndexSearcher(reader);
	Analyzer analyzer = new SimpleAnalyzer();
	
	QueryParser parser = new QueryParser(searchField, analyzer);
	Query query = parser.parse(queryString);
	
	TopDocs docs = searcher.search(query, 100);
	ScoreDoc[] hits = docs.scoreDocs;
	
	for (ScoreDoc sd: hits) {
		Document doc = searcher.doc(sd.doc);
		results.add(prodcat.getProductById(doc.get("id")));
	}
	reader.close();
	
	return results;
}
 
Example 3
Source Project: nifi   Source File: ITestPersistentProvenanceRepository.java    License: Apache License 2.0 6 votes vote down vote up
private List<Document> runQuery(final File indexDirectory, final List<File> storageDirs, final String query) throws IOException, ParseException {
    assumeFalse(isWindowsEnvironment());
    try (final DirectoryReader directoryReader = DirectoryReader.open(FSDirectory.open(indexDirectory.toPath()))) {
        final IndexSearcher searcher = new IndexSearcher(directoryReader);

        final Analyzer analyzer = new SimpleAnalyzer();
        final org.apache.lucene.search.Query luceneQuery = new QueryParser("uuid", analyzer).parse(query);

        final Query q = new Query("");
        q.setMaxResults(1000);
        final TopDocs topDocs = searcher.search(luceneQuery, 1000);

        final List<Document> docs = new ArrayList<>();
        for (final ScoreDoc scoreDoc : topDocs.scoreDocs) {
            final int docId = scoreDoc.doc;
            final Document d = directoryReader.document(docId);
            docs.add(d);
        }

        return docs;
    }
}
 
Example 4
Source Project: arcusplatform   Source File: ProductIndex.java    License: Apache License 2.0 5 votes vote down vote up
public ProductIndex(ProductCatalog prodcat) throws IOException {
	this.prodcat = prodcat;
	dir = new RAMDirectory(NoLockFactory.INSTANCE);
	Analyzer analyzer = new SimpleAnalyzer();
	
	IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
	iwc.setOpenMode(OpenMode.CREATE);
	IndexWriter iw = new IndexWriter(dir, iwc);
	indexProducts(iw, prodcat);
	iw.close();
}
 
Example 5
Source Project: tephra   Source File: LuceneHelperImpl.java    License: MIT License 5 votes vote down vote up
private Analyzer newAnalyzer() {
    switch (analyzer) {
        case "char":
            return new CharAnalyzer();
        case "simple":
            return new SimpleAnalyzer();
        case "standard":
            return new StandardAnalyzer();
        default:
            return new CJKAnalyzer();
    }
}
 
Example 6
Source Project: hmftools   Source File: TreatmentCurator.java    License: GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private static SpellChecker createIndexSpellchecker(@NotNull Directory index) throws IOException {
    Directory spellCheckerDirectory = new RAMDirectory();
    IndexReader indexReader = DirectoryReader.open(index);
    Analyzer analyzer = new SimpleAnalyzer();
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    Dictionary dictionary = new HighFrequencyDictionary(indexReader, DRUG_TERMS_FIELD, 0.0f);
    SpellChecker spellChecker = new SpellChecker(spellCheckerDirectory);

    spellChecker.indexDictionary(dictionary, config, false);
    spellChecker.setAccuracy(SPELLCHECK_ACCURACY);
    return spellChecker;
}
 
Example 7
public void createIndex(List<File> files, String idxDirectory, String baseURI) {
	try {
		urlAnalyzer = new SimpleAnalyzer(LUCENE_VERSION);
		literalAnalyzer = new LiteralAnalyzer(LUCENE_VERSION);
		Map<String, Analyzer> mapping = new HashMap<String, Analyzer>();
		mapping.put(TripleIndex.FIELD_NAME_SUBJECT, urlAnalyzer);
		mapping.put(TripleIndex.FIELD_NAME_PREDICATE, urlAnalyzer);
		mapping.put(TripleIndex.FIELD_NAME_OBJECT_URI, urlAnalyzer);
		mapping.put(TripleIndex.FIELD_NAME_OBJECT_LITERAL, literalAnalyzer);
		PerFieldAnalyzerWrapper perFieldAnalyzer = new PerFieldAnalyzerWrapper(urlAnalyzer, mapping);

		File indexDirectory = new File(idxDirectory);
		indexDirectory.mkdir();
		directory = new MMapDirectory(indexDirectory);
		IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, perFieldAnalyzer);
		iwriter = new IndexWriter(directory, config);
		iwriter.commit();
		for (File file : files) {
			String type = FileUtil.getFileExtension(file.getName());
			if (type.equals(TTL))
				indexTTLFile(file, baseURI);
			if (type.equals(TSV))
				indexTSVFile(file);
			iwriter.commit();
		}
		iwriter.close();
		ireader = DirectoryReader.open(directory);
	} catch (Exception e) {
		log.error("Error while creating TripleIndex.", e);
	}
}
 
Example 8
public void createIndex(List<File> files, String idxDirectory, String baseURI) {
	try {
		urlAnalyzer = new SimpleAnalyzer(LUCENE_VERSION);
		literalAnalyzer = new LiteralAnalyzer(LUCENE_VERSION);
		Map<String, Analyzer> mapping = new HashMap<String, Analyzer>();
		mapping.put(FIELD_NAME_URI, urlAnalyzer);
		mapping.put(FIELD_NAME_SURFACE_FORM, literalAnalyzer);
		mapping.put(FIELD_NAME_URI_COUNT, literalAnalyzer);
		mapping.put(FIELD_NAME_CONTEXT, literalAnalyzer);
		PerFieldAnalyzerWrapper perFieldAnalyzer = new PerFieldAnalyzerWrapper(urlAnalyzer, mapping);

		File indexDirectory = new File(idxDirectory);
		indexDirectory.mkdir();
		directory = new MMapDirectory(indexDirectory);
		IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, perFieldAnalyzer);
		iwriter = new IndexWriter(directory, config);
		iwriter.commit();
		for (File file : files) {
			String type = FileUtil.getFileExtension(file.getName());
			if (type.equals(TTL))
				indexTTLFile(file, baseURI);
			iwriter.commit();
		}
	} catch (Exception e) {
		log.error("Error while creating TripleIndex.", e);
	}
}
 
Example 9
Source Project: Elasticsearch   Source File: SimpleAnalyzerProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Inject
public SimpleAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);
    this.simpleAnalyzer = new SimpleAnalyzer();
    this.simpleAnalyzer.setVersion(version);
}
 
Example 10
Source Project: Elasticsearch   Source File: SimpleAnalyzerProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleAnalyzer get() {
    return this.simpleAnalyzer;
}
 
Example 11
Source Project: ache   Source File: Tokenizers.java    License: Apache License 2.0 4 votes vote down vote up
public ShingleTokenizer(int size) {
    this.analyzer = new ShingleAnalyzerWrapper(new SimpleAnalyzer(), size);
}
 
Example 12
Source Project: stratio-cassandra   Source File: PreBuiltAnalyzersTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testGetSimple() {
    Analyzer analyzer = PreBuiltAnalyzers.SIMPLE.get();
    Assert.assertEquals(SimpleAnalyzer.class, analyzer.getClass());
}
 
Example 13
Source Project: tutorials   Source File: LuceneAnalyzerIntegrationTest.java    License: MIT License 4 votes vote down vote up
@Test
public void whenUseSimpleAnalyzer_thenAnalyzed() throws IOException {
    List<String> result = analyze(SAMPLE_TEXT, new SimpleAnalyzer());

    assertThat(result, contains("this", "is", "baeldung", "com", "lucene", "analyzers", "test"));
}
 
Example 14
Source Project: crate   Source File: SimpleAnalyzerProvider.java    License: Apache License 2.0 4 votes vote down vote up
public SimpleAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
    super(indexSettings, name, settings);
    this.simpleAnalyzer = new SimpleAnalyzer();
    this.simpleAnalyzer.setVersion(version);
}
 
Example 15
Source Project: crate   Source File: SimpleAnalyzerProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleAnalyzer get() {
    return this.simpleAnalyzer;
}