4

通貨、国など、複数のコアを備えた Apache solr を使用しています。Spring Data Solr を使用すると、1 つのコアから情報を取得できます。「通貨」コアに対してクエリを実行するこの XML 構成を取得しました。「国」コアに対してクエリを実行したい場合、これをどのように設定できますか?

<!-- Enable Solr repositories and configure repository base package -->
<solr:repositories base-package="com.acme.repository" solr-template-ref="solrCurrencyTemplate"/>

<solr:solr-server id="solrCurrencyServer" url="http://localhost:8983/solr/currency"/>

<bean id="solrCurrencyTemplate" class="org.springframework.data.solr.core.SolrTemplate">
    <constructor-arg ref="solrCurrencyServer" />
</bean>

リポジトリを次のように定義します

@Repository
public interface CurrencyRepository extends SolrCrudRepository<Currency, String> {

}

そして私のサービスから私はこれを行うことができます

@Override
public List<Currency> getCurrencies() {
    Page<Currency> currencies = (Page<Currency>) currencyRepository.findAll();
    return currencies.getContent();
}

@SolrDocument(solrCoreName = "currency")も使用してみましたが、これは機能しません。

@SolrDocument(solrCoreName = "currency")
public class Currency {
    public static final String FIELD_CURRENCY_NAME = "currency_name";
    public static final String FIELD_CURRENCY_CODE = "currency_code";
    public static final String FIELD_DECIMALS = "decimals";

    @Id
    @Field(value = FIELD_CURRENCY_CODE)
    private String currencyCode;

    //currency_name,decimals
    @Field(value = FIELD_CURRENCY_NAME)
    private String currencyName;

    @Field(value = FIELD_DECIMALS)
    private String decimals;

...
...
...
}

私はこれについてできるだけ早く助けが必要です...そうでなければ、RestTemplateソリューションに戻る必要があります:-(

誰かが助けてくれることを願っています。ありがとうGM

4

5 に答える 5

9

共有したいと思いますが、最近は複数のコアの構成に多くの時間を費やしています。xml ではなく、java で行いました。

spring @configuration の一部として、以下を追加します。

@Bean(name="solrCore1Template")
public SolrTemplate solrCore1Template() throws Exception {
    EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(getCoreContainer(), "core1");
    return new SolrTemplate(embeddedSolrServer);
}

@Bean(name="solrCore2Template")
public SolrTemplate solrCore2Template() throws Exception {   
    EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(getCoreContainer(), "core2");
    return new SolrTemplate(embeddedSolrServer);
}

@Bean
@Scope
public CoreContainer getCoreContainer() throws FileNotFoundException{
    String dir = <path_to_solr_home>;
    System.setProperty("solr.solr.home", dir);
    CoreContainer.Initializer initializer = new CoreContainer.Initializer();
    return initializer.initialize();
}

各テンプレートを使用するには、サービス クラスで次のように使用します。

@Resource
private SolrTemplate solrCore1Template;

組み込みサーバーは、以下のコードを使用して HTTP に置き換えることができます。

HttpSolrServer httpSolrServer = new HttpSolrServer(getSolrURL());
return new SolrTemplate(httpSolrServer, "core1");

お役に立てれば。質問に対する返信が非常に遅いことは承知しています。

于 2014-02-18T09:06:56.697 に答える
4

名前空間構成によるマルチコア サポートは、残念ながら未解決の問題です。コアごとに個別の SolrTemplate を用意し、リポジトリを手動で作成する必要があります。

@Autowired 
@Qualifier("solrCurrencyTemplate")
private SolrTemplate solrCurrencyTemplate;

@Autowired
@Qualifier("solrCountryTemplate")
private SolrTemplate solrCountryTemplate;

//...

CurrencyRepository currencyRepo = new SolrRepositoryFactory(this.solrCurrencyTemplate)
  .getRepository(CurrencyRepository.class);

CountryRepository countryRepo = new SolrRepositoryFactory(this.solrCountryTemplate)
  .getRepository(CountryRepository.class);
于 2013-05-31T20:55:54.710 に答える
1

Spring Data Solr 1.1.0.RC1 では、複数のコアが Christoph Strobl の説明どおりに動作し@EnableSolrRepositoriesます。set による XML 構成でも機能しますmulticore-support="true"

<solr:repositories base-package="your.solr.repo.package" repository-impl-postfix="Impl" multicore-support="true"/>

<solr:solr-server id="solrServer" url="${solr.server.base.connection.url}" />

<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
    <constructor-arg index="0" ref="solrServer" />
</bean>
于 2014-01-31T22:50:00.377 に答える
1
<solr:solr-server id="solrServer" timeout="1000" maxConnections="1000" url="${solr.server.1},${solr.server.2}"/>

<bean id="solrServerFactory" class="org.springframework.data.solr.server.support.MulticoreSolrServerFactory">
    <constructor-arg ref="solrServer" />
    <constructor-arg name="cores">
        <list>
            <value>${solr.index.customer}</value>
            <value>${solr.index.task}</value>
        </list>
    </constructor-arg>
</bean>

<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
    <constructor-arg ref="solrServerFactory" />
</bean>

<solr:repositories base-package="com.deve.pig.solr" multicore-support="true" solr-template-ref="solrTemplate" />
于 2014-08-29T07:20:12.000 に答える