dmFile Boosting for FarCry Solr Pro Search

Overview

FarCry Solr Pro plugin pro provides various configuration and customization of the search result including document elevation and boosting. However, we wanted to make it easier for contributors to use these features at the stage of managing contents. This tutorial page will list the steps of implementing document boosting for File objects. 

STEP 1 : File Content Type

  1. Extend dmFile.cfc to project level. - This will allow us to add new properties or methods for the file content type.
  2. Add new property called 'boostValue' to store specific boosting value for the file object. Note that it's getting the options from 'getBoostOptions' from 'solrProDocumentBoost' content type. These boost options can be configured at webtop config > Solr Pro Plugin > Document Boost Values.
  3. Add two new methods 'getBoostValueForFile' and 'AfterSave' to index boost value to solr pro when object is saved. - This means you don't need   to do indexing process every time they make changes on the contents.
  4. The dmFile.cfc should look like this, e.g :
For example, within an extended ./myproject/packages/system/dmFile.cfc
<cfcomponent extends="farcry.core.packages.types.dmFile" displayname="File">
	<cfproperty ftSeq="120" ftFieldset="Document Boosting" ftLabel="Boost Value" ftType="list" type="string" name="boostValue" 
		ftListData="getBoostOptions" ftListDataTypename="solrProDocumentBoost" 
		default="0"
		ftHint="Choose a boost value.<br /> The result will be high-lighted according to this boosting value." 
		hint="Stored as string because the FarCry compare fails when there are decimals." />
	<cffunction name="getBoostValueForFile" access="public" output="false" returntype="string">
		<cfargument name="documentId" required="true" type="uuid" />
		
		<cfset var q = "" />
		<cfquery name="q" datasource="#application.dsn#">
			select boostValue from dmFile where objectid = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.documentId#" />;
		</cfquery>
		
		<cfif q.recordCount>
			<cfreturn q.boostValue[1] />
		<cfelse>
			<cfreturn "" />
		</cfif>
	</cffunction>
	<cffunction name="AfterSave" access="public" output="false" returntype="struct" hint="Called from setData and createData and run after the object has been saved.">
		<cfargument name="stProperties" required="yes" type="struct" hint="A structure containing the contents of the properties that were saved to the object.">
		
		<!--- index the record being boosted --->
		<cfset var oContentType = application.fapi.getContentType("solrProContentType") />
		<cfset oContentType.addRecordToIndex(objectid = stProperties.objectid) />
		
		<cfreturn super.afterSave(argumentCollection = arguments) />
	</cffunction>
</cfcomponent>

Remember to do an updateapp after adding dmFile.cfc and COAPI deploy for the new property.

STEP 2 : solrProContentType.cfc

Contents(File in this case) need to be indexed to solr pro for search and if there are any search index value changes (eg. boosting value or elevation), index needs to be updated. 'addRecordToIndex' method in solr pro adds individual content data to the search collection and It needs to be amended to check the new property, 'boostingValue' in dmFile and do indexing process. 

  1. Extend solrProContentType.cfc in your project. eg.  ./myproject/packages/type/solrProContentType.cfc
  2. Copy the 'addRecordToIndex' function from ./plugins/farcrysolrpro/packages/types/solrProContentType.cfc
  3. Configure the document boost value getting part in the function as below : 
Configure 'addRecordToIndex' function.
<!--- check if this record has a file level boost --->
<cfset oFile = application.fapi.getContentType("dmFIle")>
<cfset var docBoost = oFile.getBoostValueForFile(documentId = stRecord.objectid)>
<!--- check if this record has a document level boost configured at solr pro --->
<cfif isNumeric(docBoost) AND docBoost eq 0>
	<cfset var docBoost = arguments.oDocumentBoost.getBoostValueForDocument(documentId = stRecord.objectid) />
</cfif>
<!--- if there was no boost for the specific document, grab the default specified for the content type --->
<cfif not isNumeric(docBoost)>
	<cfset docBoost = arguments.stContentType.defaultDocBoost />
</cfif>

STEP 3 : Search Results

Now, notice the position of the file in result page, which will be placed 'higher' than before if you boosted the file. In addition, you can modify search result page(displaySolrSearchResult.cfm) to see the boosted files in high-lighted mode. e.g :