0

マルチコアをサポートするリポジトリを使用して solr で春のデータをセットアップするための詳細で完全な説明はありますか?

4

1 に答える 1

4

spring-data-solr に使用する必要がある唯一の依存関係は

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-solr</artifactId>
    <version>1.5.2.RELEASE</version>
</dependency>

solrj 依存関係をダウンロードします。これは、以降のバージョンの solrj でオーバーライドしてはなりません。また、これから作業する EmbeddedSolrServer よりも HttpSolrServer を使用することを常にお勧めします。

Configuration クラスは次のようになります。

@Configuration
@EnableSolrRepositories(value = "com.package.",multicoreSupport = true)
public class SolrConfig
{
    @Bean
    public SolrServer solrServer() throws Exception
    {
        HttpSolrServerFactoryBean f = new HttpSolrServerFactoryBean();
        f.setUrl("http://localhost:8983/solr");
        f.afterPropertiesSet();
        return f.getSolrServer();
    }

    @Bean
    public SolrTemplate solrTemplate(SolrServer solrServer) throws Exception
    {
        return new SolrTemplate(solrServer());
    }
}

ドキュメント エンティティには、それらが属するコアに関する情報が含まれている必要があります。

@SolrDocument(solrCoreName = "core1")
public class Document1
{
    @Id
    @Field
    private String id;

    /**other attributes**/
}

他のドキュメントは

@SolrDocument(solrCoreName = "core2")
public class Document2
{
    @Id
    @Field
    private String id;

    /**other attributes**/
}

最良の部分は、すでに完了していることです。昔ながらの方法でリポジトリを設定するだけでうまくいきます

public interface SolrCore1Repository extends SolrCrudRepository<Document1,String>
{
    // optional code
}

他のレポは次のようになります

public interface SolrCore2Repository extends SolrCrudRepository<Document2,String>
{
    // optional code
}

指定された URL で solr が実行され、pojo に従ってフィールドが設定されたら、完了です。

于 2016-02-13T11:54:19.950 に答える