java - 使用 Solr 和 Spring 自动完成 - 多个单词的问题

标签 java solr lucene spring-data spring-data-solr

我已经使用 Spring Data Solr 为位置数据库建立了索引。我有以下字段:

   <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="name" type="text_ws" indexed="true" stored="true"/>
   <field name="autocomplete" type="lowercase" indexed="true" stored="false"/>

我正在尝试实现自动完成功能。我的 ajax 调用由 Controller 处理,该 Controller 通过以下方式调用存储库:

List<POISearch> findByAutocompleteStartingWith(String autocomplete, Pageable pageable);

这对于“加利福尼亚”或“洛斯”等搜索效果很好。但是当我尝试使用“Los Ang”等多个单词时,我遇到了异常:

SEVERE: Servlet.service() for servlet [spring-mvc] in context with path [/xxx] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Cannot constructQuery '"los an"'. Use epxression or mulitple clauses instead.] with root cause org.springframework.dao.InvalidDataAccessApiUsageException: Cannot constructQuery '"los an"'. Use epxression or mulitple clauses instead. at org.springframework.data.solr.core.query.Criteria.assertNoBlankInWildcardedQuery(Criteria.java:596) at org.springframework.data.solr.core.query.Criteria.contains(Criteria.java:230) at org.springframework.data.solr.core.query.Criteria.contains(Criteria.java:257) at org.springframework.data.solr.core.query.Criteria.contains(Criteria.java:244) at org.springframework.data.solr.repository.query.SolrQueryCreator.from(SolrQueryCreator.java:112) at org.springframework.data.solr.repository.query.SolrQueryCreator.create(SolrQueryCreator.java:56) at org.springframework.data.solr.repository.query.SolrQueryCreator.create(SolrQueryCreator.java:43) at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109) at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88) at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73) at org.springframework.data.solr.repository.query.PartTreeSolrQuery.createQuery(PartTreeSolrQuery.java:46) at org.springframework.data.solr.repository.query.AbstractSolrQuery.execute(AbstractSolrQuery.java:95) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:312) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy44.findByAutocompleteContaining(Unknown Source)

有什么解决办法吗?

最佳答案

使用最新版本的 spring-data-solr,您可以执行以下操作:

List<POISearch> results = repository.findByAutocompleteStartingWith(Arrays.asList("los", "ange"));

效果很好!

感谢 Christoph 帮助解答:https://jira.springsource.org/browse/DATASOLR-74

关于java - 使用 Solr 和 Spring 自动完成 - 多个单词的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16441538/

相关文章:

java - 如何将主 Solr 服务器(基于查询)的部分索引导入到另一个 Solr 服务器,然后稍后进行增量导入(更新后的索引)?

java - 您可以从 Solr 索引中的文档中删除一个字段吗?

java - 如何在 Apache wicket 中使用从 BasePage 继承的 AdminBasePage(从 WebPage 继承)

java - 添加组件到JPanel,屏幕上没有变化

solr - 海布里斯 : How to exclude Facet Value from the Solr Result

java - 自动识别文本中的公司名称

Solr 文本字段和字符串字段 - 不同的搜索行为

hibernate - Hibernate Search直接计数,而不是使用Lucene和Elasticsearch进行常规查询

java - DatePickerDialog 将选项限制为最长一周

java - 为什么 JVM 先请求 Application ClassLoader 加载一个类,而最终这个请求被委托(delegate)给 Bootstrap 类加载器?