This tutorial has moved to http://discourse.farcrycore.org/t/document-boosting-for-farcry-solr-pro-search/72/last |
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. |
<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. |
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.
<!--- 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> |
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 :