Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created June 27, 2013 21:13
Show Gist options
  • Save stevewithington/5880459 to your computer and use it in GitHub Desktop.
Save stevewithington/5880459 to your computer and use it in GitHub Desktop.
Mura CMS : Another custom search example. I would not necessarily recommend using this for production purposes, although it should work. Search in general is quite complicated ... hence why we have such companies as Google, Yahoo, Ask, etc. ... so if you truly want a custom search interface, you may actually want to consider using one of the cus…
<!--- First, you could copy the file located under /{SiteID}/includes/display_objects/dsp_search_results.cfm
and then paste it under either /{SiteID}/includes/display_objects/custom/dsp_search_results.cfm
OR under /{SiteID}/includes/themes/{ThemeName}/display_objects/dsp_search_results.cfm
and then change the line of code that sets the variables.rsNewSearch to this --->
<cfset variables.rsNewSearch = variables.$.getContentRenderer().getCustomSearch()>
<!--- Then, place this in your Site's contentRenderer.cfc --->
<cffunction name="getCustomSearch">
<cfscript>
var local = {};
local.feed=$.getBean('feed');
local.feed.setMaxItems(0); // 0=unlimited
// SORTING :: you could have another field on your search form to filter on these fields
local.feed.setSortBy('menuTitle'); // lastUpdate, releaseDate, displayStart, menuTitle, rating, comments, created, orderno, random
local.feed.setSortDirection('asc'); // asc, desc
// allow for categoryid via url
if ( Len(variables.$.event('categoryid')) and IsValid('uuid', variables.$.event('categoryid')) ) {
local.feed.setCategoryID(variables.$.event('categoryid'));
}
// allow for tag via url
if ( Len(variables.$.event('tag')) ) {
local.feed.addParam(
relationship='AND'
,field='tcontenttags.tag'
,dataType='varchar'
,criteria=URLDecode(variables.$.event('tag'))
);
}
// Create a grouping
if ( Len(Trim(variables.$.event('keywords'))) ) {
local.feed.addParam(relationship='andOpenGrouping');
local.delims = ' ^,'; // loop over words separated by either a space OR a comma
for ( local.x=1; local.x <= ListLen(local.delims, '^'); local.x++ ) {
local.delim = ListGetAt(local.delims, local.x, '^');
// let's loop over the keywords...
for ( local.i=1; local.i <= ListLen(variables.$.event('keywords'), '#local.delim#'); local.i++ ) {
local.keyword = ListGetAt(variables.$.event('keywords'), local.i, '#local.delim#');
//keyword = replaceNoCase(keyword, '+', ' ', 'ALL');
local.feed.addParam(
relationship='OR'
,field='tcontent.title'
,dataType='varchar'
,criteria=Trim(local.keyword)
,condition='CONTAINS'
);
local.feed.addParam(
relationship='OR'
,field='tcontent.menuTitle'
,dataType='varchar'
,criteria=Trim(local.keyword)
,condition='CONTAINS'
);
local.feed.addParam(
relationship='OR'
,field='tcontent.metaKeywords'
,dataType='varchar'
,criteria=Trim(local.keyword)
,condition='CONTAINS'
);
local.feed.addParam(
relationship='OR'
,field='tcontent.summary'
,dataType='varchar'
,criteria=Trim(local.keyword)
,condition='CONTAINS'
);
local.feed.addParam(
relationship='OR'
,field='tcontent.credits'
,dataType='varchar'
,criteria=Trim(local.keyword)
,condition='CONTAINS'
);
local.feed.addParam(
relationship='OR'
,field='tcontent.body'
,dataType='varchar'
,criteria=Trim(local.keyword)
,condition='CONTAINS'
);
// could add more fields and/or extended attributes to search on here
};
};
local.feed.addParam(relationship='closeGrouping');
}
return local.feed.getQuery();
</cfscript>
</cffunction>
@stevewithington
Copy link
Author

A related Gist can be found at https://gist.github.com/stevewithington/3866582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment