Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-01-2022 05:45 AM - edited 08-01-2022 09:47 PM
With the example given here, we have implemented a custom Analyzer that supports 'case insensitive exact matches' by combining KeywordTokenizerFactory and LowerCaseFilterFactory .
Implementation:
package com.test.nosql.neo4j;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.KeywordTokenizerFactory;
import org.apache.lucene.analysis.core.LowerCaseFilterFactory;
import org.apache.lucene.analysis.custom.CustomAnalyzer;
import org.neo4j.annotations.service.ServiceProvider;
import org.neo4j.graphdb.schema.AnalyzerProvider;
import java.io.IOException;
@ServiceProvider
public class KeywordLowerAnalyzerProvider extends AnalyzerProvider {
public static final String DESCRIPTION = "same as keyword analyzer, but additionally applies a lower case filter to all tokens";
public static final String ANALYZER_NAME = "keyword_lower";
public KeywordLowerAnalyzerProvider() {
super(ANALYZER_NAME);
}
public Analyzer createAnalyzer() {
try {
return CustomAnalyzer.builder()
.withTokenizer(KeywordTokenizerFactory.class)
.addTokenFilter(LowerCaseFilterFactory.class)
.build();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public String description() {
return DESCRIPTION;
}
}
We can now,
CREATE (n:Account) set n.nativeId = 'JOhN DoE' return n;
CREATE (n:Account) set n.nativeId = 'John Doe' return n;
Now query Graph using index:
CALL db.index.fulltext.queryNodes('acc_idx_1', 'john DOE') yield node as n return n
Overall, what is the working of Custom Analyzer, What values are stored and how are they compared at runtime?
All the sessions of the conference are now available online