Page 1 of 1

How to add new core in broadleaf solr?

Posted: Sat Aug 09, 2014 8:57 am
by gowthamgutha
I would like to add a new solr core to my broadleaf project, add documents and create a new search service. How could I do that?

Thanks in advance. Hope you will reply as soon as possible.

Re: How to add new core in broadleaf solr?

Posted: Fri Aug 15, 2014 9:28 am
by ktisdell
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.

Re: How to add new core in broadleaf solr?

Posted: Mon Aug 25, 2014 4:58 am
by mayya
nice fourm post i really like it..:)

Re: How to add new core in broadleaf solr?

Posted: Mon Oct 13, 2014 12:20 pm
by gowthamgutha
Thank you. Nice, you could post that in Broadleaf commerce blog for future visitors.

Re: How to add new core in broadleaf solr?

Posted: Fri Oct 17, 2014 10:42 am
by gowthamgutha
Do I also need to include in this tag?

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="rebuildIndexTrigger" />
<ref bean="rebuildMyIndexTrigger" />
<!--<ref bean="purgeCartTrigger" />-->
<!--<ref bean="purgeCustomerTrigger" />-->
</list>
</property>
</bean>

Re: How to add new core in broadleaf solr?

Posted: Tue Nov 04, 2014 5:42 pm
by phillipuniverse
You only need to include the triggers that you want. Those purgeCart and purgeCustomer triggers are commented out for the time being so you can do whatever you want to with them.