Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring solr动态场模拟_Java_Solrj_Spring Data Solr - Fatal编程技术网

Java Spring solr动态场模拟

Java Spring solr动态场模拟,java,solrj,spring-data-solr,Java,Solrj,Spring Data Solr,我试着做一个这样的查询,从文档中检索一个特定的字段,执行查询时我没有得到运行时错误,但我没有得到我应该从查询中检索的3个字段,只有日期和来源,但没有变量,应该返回所有字段的字段都为空。 如何选择只想在查询中检索的字段 当前我的查询如下所示: @Query(value = "id:?0", fields = {"?1","date","origin"}) List<Data> getRecord(String id,String field); @Query(value=“

我试着做一个这样的查询,从文档中检索一个特定的字段,执行查询时我没有得到运行时错误,但我没有得到我应该从查询中检索的3个字段,只有日期和来源,但没有变量,应该返回所有字段的字段都为空。 如何选择只想在查询中检索的字段

当前我的查询如下所示:

  @Query(value = "id:?0", fields = {"?1","date","origin"})
   List<Data> getRecord(String id,String field);
@Query(value=“id:?0”,字段={1”,“日期”,“来源”})
列表getRecord(字符串id,字符串字段);
简介 阅读你的评论,我发现有一点关于什么是和的困惑 .

SolrJ是Solr客户机(我个人也会添加标准和官方客户机)

SolrJ是一种API,它使Java应用程序能够轻松地与之对话 索尔。SolrJ隐藏了连接到Solr和 允许应用程序与Solr进行简单的高级交互 方法

ApacheSolr的Spring数据是更大框架Spring数据的一部分,它提供了从Spring应用程序到ApacheSolr搜索服务器的配置和访问(要在内部与Solr对话,它使用SolrJ)

到目前为止,Solr Spring数据版本。1.2.0.RELEASE依赖于SolrJ 4.7.2,它可能与Solr 6.2.0不兼容(如果您使用SolrCloud,这是肯定的)

鉴于这一适当的介绍,我建议将Solr实例和SolrJ客户端保持在同一版本上(或者至少保持在同一主版本上)

因此,对于SolrV.6.2.1,您应该使用SolrJ6.2.1,但不幸的是,最新的SolrSpring数据版本是2.1.3.RELEASE(内部依赖于SolrJ5.5.0)


org.springframework.data
弹簧数据解算器
2.1.3.1发布
你的问题 考虑到您没有收到正在查找的字段列表,simply Solr Data不支持字段列表的占位符

我建议您扩展您的存储库类,创建一个新的RepositoryImpl,使用简单而简单的SolrJ客户端添加自定义搜索,而不是使用Solr-Spring数据

@Component
public class ProductsRepositoryImpl implements ProductsRepositoryCustom {

  @Autowired
  private SolrServer   solrServer;

  public ProductsRepositoryImpl() {};

  public ProductsRepositoryImpl(SolrServer solrServer) {
    this.solrServer = solrServer;
  }

  public List<Map<String, Object>> findFields(String id, List<String> fields)
  {
    SolrQuery solrQuery = new SolrQuery("id:" + id);
    solrQuery.setFields(fields.toArray(new String[0]));
    try {
      QueryResponse response = this.solrServer.query(solrQuery);
      return response.getResults()
              .stream()
              .map(d ->
                {
                  return d.entrySet()
                          .stream()
                          .filter(e -> fields.contains(e.getKey()))
                          .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
                }).collect(Collectors.toList());
    } catch (SolrServerException e) {
      // TODO Auto-generated catch block
    }
    return Collections.emptyList();
  }

}
@组件
公共类ProductsRepositoryImpl实现ProductsRepositoryCustom{
@自动连线
专用SolrServer SolrServer;
公共产品RepositoryImpl(){};
公共产品存储impl(SolrServer SolrServer){
this.solrServer=solrServer;
}
公共列表findFields(字符串id、列表字段)
{
SolrQuery SolrQuery=新的SolrQuery(“id:+id”);
setFields(fields.toArray(新字符串[0]);
试一试{
QueryResponse response=this.solrServer.query(solrQuery);
返回响应。getResults()
.stream()
.地图(d->
{
返回d.entrySet()
.stream()
.filter(e->fields.contains(e.getKey()))
.collect(Collectors.toMap(p->p.getKey(),p->p.getValue());
}).collect(Collectors.toList());
}捕获(SolrServer异常){
//TODO自动生成的捕捉块
}
返回集合。emptyList();
}
}

是,您可以分别使用SimpleQuery对象和条件执行此操作

为要从存储库接口查询的方法创建自定义实现类,并执行以下操作

@Resource private SolrTemplate SolrTemplate;//创建一个solrtemplatebean
字符串QueryString=“*:*”;//所有搜索查询
字符串[]字段={“航班”、“酒店”、“汽车”、“自行车”};
SimpleQuery=newSimpleQuery(QueryString,newSolrPageRequest(0,10));
query.addprojectionnfields(字段);
FilterQuery fq=新的SimpleFilterQuery(新条件(“汽车”)。是(“福特”);//要生成的任何筛选器或条件
query.addFilterQuery(fq);
Page resultPage=solrTemplate.query(“CoreName”,queryString,Model.class);

您使用的是哪个版本的Solr和SolrJ?@freedev Solr v.6.2.1和SolrJ 1.2.0.release为什么要使用这么旧的SolrJ版本?@实际上我还没有检查它有多旧,我只是在更新现有项目并向其添加一些代码,只需使用当前Solr实例的SolrJ版本。还有一个问题,我遇到这个错误:
HTTP错误404访问/solr/update时出现问题。原因:未找到


由Jetty提供动力://
这是一个完全不同的问题,我强烈建议编写一个新问题,用一个完整的、最少的、可重复的问题示例。
@Component
public class ProductsRepositoryImpl implements ProductsRepositoryCustom {

  @Autowired
  private SolrServer   solrServer;

  public ProductsRepositoryImpl() {};

  public ProductsRepositoryImpl(SolrServer solrServer) {
    this.solrServer = solrServer;
  }

  public List<Map<String, Object>> findFields(String id, List<String> fields)
  {
    SolrQuery solrQuery = new SolrQuery("id:" + id);
    solrQuery.setFields(fields.toArray(new String[0]));
    try {
      QueryResponse response = this.solrServer.query(solrQuery);
      return response.getResults()
              .stream()
              .map(d ->
                {
                  return d.entrySet()
                          .stream()
                          .filter(e -> fields.contains(e.getKey()))
                          .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
                }).collect(Collectors.toList());
    } catch (SolrServerException e) {
      // TODO Auto-generated catch block
    }
    return Collections.emptyList();
  }

}
  @Resource private SolrTemplate solrTemplate; // Create a SolrTemplate Bean


String QueryString = "*:*"; // all search query
String[] fields = {"Flight", "Hotel", "Car", "Bike"};
SimpleQuery query = new SimpleQuery(QueryString , new SolrPageRequest(0,10));
query.addProjectionOnFields(fields);
FilterQuery fq = new SimpleFilterQuery(new Criteria("Car").is(“Ford”)); // any Filter or criteria to build
query.addFilterQuery(fq);
Page<SolrDocumentPojo> resultPage= solrTemplate.query("CoreName ",queryString,Model.class);