Postby ktisdell » Fri Aug 15, 2014 9:28 am
You can definitely add a new core and use it in Broadleaf. The short answer, though, is that it's like adding a completely new / custom piece of functionality. In other words, there is nothing out of the box with Broadleaf that will use your new core. So, you will have to provide custom code for indexing to this new core, for issuing queries against this core, and a controller and UI to allow customer interaction. The longer answer is that it depends what you are trying to do. Are you using a stand alone Solr server or an embedded one? For your new core, do you also need a separate reindex core? Are you load balancing your Solr servers?
Assuming you are using a stand-alone Solr server, not load balanced, at a minimum, you'll probably need to configure the following:
1. Create a new Solr core in your Solr server (see Solr documentation)
2. Create a new component to index your Solr server. Have a look at Broadleaf's SolrIndexServiceImpl as a reference. This will typically have a service or DAO injected to read the data that needs to be indexed. It will also require a reference to your Solr client.
3. Configure a Solr client. If you are using a reindex core, then you'll have to configure several clients (HttpSolrServer). If you don't need a reindex core (e.g. you plan to reindex in the active core), then you only need 1 of these.
<bean id="mySolrAdminServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.url.admin}"/>
</bean>
<bean id="mySolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.url.primary}"/>
</bean>
<bean id="mySolrReindexServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.url.reindex}"/>
</bean>
4. Inject your Solr client(s) into a component to hold and share them (see Broadleaf's SolrContext).
5. Create a service to issue queries to Solr (see Broadleaf SolrSearchServiceImpl).
6. Configure a Spring cron job to reindex as necessary
<bean id="rebuildMyIndexJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="myIndexService" />
<property name="targetMethod" value="rebuildIndex" />
</bean>
<bean id="rebuildMyIndexTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="rebuildMyIndexJobDetail" />
<property name="cronExpression" value="${my.reindex.full.cron.exp}" />
</bean>
7. Build a controller and inject your custom search service and invoke it as required
8. Build a UI (HTML templates) that interact with the controller.