org.apache.lucene.analysis.core.SimpleAnalyzer Java Examples
The following examples show how to use
org.apache.lucene.analysis.core.SimpleAnalyzer.
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
Source File: TestPersistentProvenanceRepository.java From localization_nifi with Apache License 2.0 | 7 votes |
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 File: ProductIndex.java From arcusplatform with Apache License 2.0 | 6 votes |
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 File: ITestPersistentProvenanceRepository.java From nifi with Apache License 2.0 | 6 votes |
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 File: ProductIndex.java From arcusplatform with Apache License 2.0 | 5 votes |
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 File: LuceneHelperImpl.java From tephra with MIT License | 5 votes |
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 File: TreatmentCurator.java From hmftools with GNU General Public License v3.0 | 5 votes |
@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
Source File: TripleIndexCreator.java From AGDISTIS with GNU Affero General Public License v3.0 | 5 votes |
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
Source File: TripleIndexCreatorContext.java From AGDISTIS with GNU Affero General Public License v3.0 | 5 votes |
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 File: SimpleAnalyzerProvider.java From Elasticsearch with Apache License 2.0 | 4 votes |
@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 File: SimpleAnalyzerProvider.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public SimpleAnalyzer get() { return this.simpleAnalyzer; }
Example #11
Source File: Tokenizers.java From ache with Apache License 2.0 | 4 votes |
public ShingleTokenizer(int size) { this.analyzer = new ShingleAnalyzerWrapper(new SimpleAnalyzer(), size); }
Example #12
Source File: PreBuiltAnalyzersTest.java From stratio-cassandra with Apache License 2.0 | 4 votes |
@Test public void testGetSimple() { Analyzer analyzer = PreBuiltAnalyzers.SIMPLE.get(); Assert.assertEquals(SimpleAnalyzer.class, analyzer.getClass()); }
Example #13
Source File: LuceneAnalyzerIntegrationTest.java From tutorials with MIT License | 4 votes |
@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 File: SimpleAnalyzerProvider.java From crate with Apache License 2.0 | 4 votes |
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 File: SimpleAnalyzerProvider.java From crate with Apache License 2.0 | 4 votes |
@Override public SimpleAnalyzer get() { return this.simpleAnalyzer; }