我使用两个英语和日语分析器对我的实体类FeatureMeta进行了注释。
在我的知识库类中,我将该方法命名为“findFeatures”来搜索FeatureMeta实体。
但是当我尝试访问存储库中的“findFeatures”方法后,抛出异常:
引起:java.lang.IllegalArgumentException:没有枚举常量 org.apache.lucene.analysis.ja.JapaneseTokenizer.Mode.FINDFEATURES
请注意,在某种程度上,“JapaneseTokenizerFactory”尝试创建一个枚举,其中包含我在我的存储库中使用的方法名称的值(findFeatures)。
我不确定为什么JapaneseTokenizerFactory的逻辑与我的存储库名称之间存在关系。
实体类:
@Entity
@Table(name="feature_meta")
@Indexed
@AnalyzerDef(name = "japaneseAnalyzer",
tokenizer = @TokenizerDef(factory = JapaneseTokenizerFactory.class,
params = {@Parameter(name = "mode", value = "findFeatures"),
}),
filters = {
@TokenFilterDef(factory = JapaneseBaseFormFilterFactory.class),
@TokenFilterDef(factory = JapanesePartOfSpeechStopFilterFactory.class,
params = @Parameter(name = "tags", value = "org/apache/lucene/analysis/ja/stoptags.txt")),
@TokenFilterDef(factory = CJKWidthFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class,
params = @Parameter(name = "words", value = "org/apache/lucene/analysis/ja/stopwords.txt")),
@TokenFilterDef(factory = JapaneseKatakanaStemFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class)
})
@AnalyzerDef(name = "englishAnalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
@Parameter(name = "language", value = "English")
})
})
public class FeatureMeta implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name="feature_id",unique = true)
private String featureId;
@Column(name="category_id")
@Field(name = "categoryId", analyze=Analyze.NO)
private String categoryId;
@Field(name="featureSetId",analyze=Analyze.NO)
@Column(name = "feature_set_id")
private String featureSetId;
@Enumerated(EnumType.STRING)
@Column(name="feature_type")
private EnumFeatureType featureType;
@Fields({@Field(name="name_en", analyzer=@Analyzer(definition="englishAnalyzer"))})
@Column(name="name_en")
@Lob
private String nameEn;
@Fields({@Field(name="name_ja", analyzer=@Analyzer(definition="japaneseAnalyzer"))})
@Column(name="name_ja")
@Lob
private String nameJa;
@Fields({@Field(name="desc_en", analyzer=@Analyzer(definition="englishAnalyzer"))})
@Column(name="desc_en")
@Lob
private String descEn;
..
}
Repostory:
@Repository
public class FeatureSegmentMetaSearchRepository {
@PersistenceContext
private EntityManager entityManager;
public FeatureMetaSearchResult findFeatures(Integer offset, Integer pageSize, String text, String categoryId, String featureSetId, Collection<String> tags) {
FeatureMetaSearchResult ret = new FeatureMetaSearchResult();
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.
getFullTextEntityManager(entityManager);
//Filtering by keyword
QueryBuilder queryBuilder =
fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity(FeatureMeta.class).get();
org.apache.lucene.search.Query queryKeyword = null;
if (StringUtils.isEmpty(text)) {
queryKeyword = queryBuilder.all().createQuery();
} else {
queryKeyword = queryBuilder
.keyword()
.onFields("name_en","name_ja", "desc_en", "desc_ja","business_desc_en","business_desc_ja",
"logical_desc_en", "logical_desc_ja")
.matching(text)
.createQuery();
}
BooleanQuery.Builder aggrBuilder = new BooleanQuery.Builder();
aggrBuilder = aggrBuilder.add(new BooleanClause(queryKeyword, BooleanClause.Occur.MUST));
if (categoryId != null) {
TermQuery queryFilter = new TermQuery(new Term("categoryId",categoryId));
aggrBuilder = aggrBuilder.add(new BooleanClause(queryFilter, BooleanClause.Occur.MUST));
}
if (featureSetId != null) {
String setFilter = new EnumBridge().objectToString(featureSetId);
TermQuery queryFilter = new TermQuery(new Term("featureSetId", setFilter));
aggrBuilder = aggrBuilder.add(new BooleanClause(queryFilter, BooleanClause.Occur.MUST));
}
if(!CollectionUtils.isEmpty(tags)) {
for (String tag : tags) {
TermQuery queryFilter = new TermQuery(new Term("tags", tag));
aggrBuilder = aggrBuilder.add(new BooleanClause(queryFilter, BooleanClause.Occur.MUST));
}
}
org.hibernate.search.jpa.FullTextQuery jpaQuery =
fullTextEntityManager.createFullTextQuery(aggrBuilder.build(), FeatureMeta.class);
if (offset != null) jpaQuery.setFirstResult(offset);
if (pageSize != null) jpaQuery.setMaxResults(pageSize);
ret.setTotalCount(jpaQuery.getResultSize());
ret.setResults(jpaQuery.getResultList());
return ret;
}
}
引起:org.hibernate.search.exception.SearchException:无法执行 实例化Tokenizer工厂类: org.apache.lucene.analysis.ja.JapaneseTokenizerFactory。该 实现类没有识别应用的参数。在 org.hibernate.search.util.impl.ClassLoaderHelper.instanceFromClass(ClassLoaderHelper.java:156) 在 org.hibernate.search.analyzer.impl.LuceneAnalyzerBuilder.buildAnalysisComponent(LuceneAnalyzerBuilder.java:147) 在 org.hibernate.search.analyzer.impl.LuceneAnalyzerBuilder.buildAnalyzer(LuceneAnalyzerBuilder.java:105) 在 org.hibernate.search.analyzer.impl.LuceneAnalyzerBuilder.buildAnalyzer(LuceneAnalyzerBuilder.java:76) 在 org.hibernate.search.analyzer.impl.NamedLuceneAnalyzerReference.createAnalyzer(NamedLuceneAnalyzerReference.java:64) 在 org.hibernate.search.analyzer.impl.NamedLuceneAnalyzerReference.initialize(NamedLuceneAnalyzerReference.java:60) 在 org.hibernate.search.analyzer.impl.LuceneEmbeddedAnalyzerStrategy.initializeReference(LuceneEmbeddedAnalyzerStrategy.java:234) 在 org.hibernate.search.analyzer.impl.LuceneEmbeddedAnalyzerStrategy.lambda $ initializeReferences $ 0(LuceneEmbeddedAnalyzerStrategy.java:192) 在 java.util.ArrayList中的$ ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) 在 java.util.stream.Streams $ ConcatSpliterator.forEachRemaining(Streams.java:742) 在 java.util.stream.ReferencePipeline $ Head.forEach(ReferencePipeline.java:580) 在 org.hibernate.search.analyzer.impl.LuceneEmbeddedAnalyzerStrategy.initializeReferences(LuceneEmbeddedAnalyzerStrategy.java:192) 在 org.hibernate.search.engine.impl.SearchIntegrationConfigContext.initialize(SearchIntegrationConfigContext.java:72) 在 org.hibernate.search.engine.impl.ConfigContext.initIntegrations(ConfigContext.java:252) 在 org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:469) 在 org.hibernate.search.spi.SearchIntegratorBuilder.createNewFactoryState(SearchIntegratorBuilder.java:243) 在 org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199) 在 org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:127) 在 org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.boot(HibernateSearchSessionFactoryObserver.java:113) 在 org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:79) 在 org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35) 在 org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:375) 在 org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452) 在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889) ... 46更多引起:java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 方法)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在 org.hibernate.search.util.impl.ClassLoaderHelper.instanceFromClass(ClassLoaderHelper.java:152) ... 69更多引起:java.lang.IllegalArgumentException:没有枚举 不变 org.apache.lucene.analysis.ja.JapaneseTokenizer.Mode.FINDFEATURES at java.lang.Enum.valueOf(Enum.java:238)at org.apache.lucene.analysis.ja.JapaneseTokenizer $ Mode.valueOf(JapaneseTokenizer.java:78) 在 org.apache.lucene.analysis.ja.JapaneseTokenizerFactory。(JapaneseTokenizerFactory.java:73) ... 74更多
答案 0 :(得分:3)
问题不在于方法名称,而在于您的分析器定义。
你有这个:
tokenizer = @TokenizerDef(factory = JapaneseTokenizerFactory.class,
params = {@Parameter(name = "mode", value = "findFeatures"),
}),
即。你正在使用“findFeatures”作为一种模式。您需要使用支持的模式。