Support Forum

Next Page

Page: 1 2

Previous Page

Thread: Search on Extended Attributes

Created on: 04/23/09 04:51 AM

Replies: 33

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

Search on Extended Attributes
04/23/09 4:51 AM

I'm working on a site in which the primary content type is a subtype that I set up using the class extension manager. I noticed that the site search doesn't search against content that is in those extended fields. Before I build a customized search component, I just wanted to check with you guys if there's a built-in way to do this.
Also -- is there an API method that simply returns a recordset of all the content nodes in the site (including extended attributes as additional columns)?
Thanks.

________________
objectivebias.com

Link | Top | Bottom

matt





Joined: 04/26/08

Posts: 2639

RE: Search on Extended Attributes
04/23/09 3:12 PM

Unfortunately the site search does not search extended attributes. However, I just added the ability to use extended attributes in local indexes (5.1.162).

So now you could create a custom search that uses the feed Manager api.

<cfset feed=application.feedManager.read('')>
<cfset feed.setSiteID(request.siteid)>

<cfset feed.addAdvancedParam(relationship='openGrouping')>

<cfset feed.addAdvancedParam(field='tcontent.menutitle', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.title', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.summary', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.body', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<!--- IF YOU DO NOT SPECIFY A TABLE IN YOUR FIELD ARGUMENT IT WILL BE TREATED AS AN EXTENDED ATTRIBUTE --->
<cfset feed.addAdvancedParam( relationship='OR', field='CUSTOM_ATTRIBUTE', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<!--- If a tag has been submitted filter for that tag --->
<cfif structKeyExists(request,"tag") and len(request.tag)>
<cfset feed.addAdvancedParam(relationship='AND', field='tcontenttags.tag', criteria=request.tag, condition='EQ', dataType='varchar')>
</cfif>

<cfset feed.addAdvancedParam(relationship='closeGrouping')>

<!--- If a the searchSectionID is defined filter for content that have it in their path --->
<cfif structKeyExists(request,"searchSectionID") and len(request.searchSectionID)>
<cfset feed.addAdvancedParam(relationship='AND', field='tcontent.path', criteria=request.searchSectionID, condition='CONTAINS', dataType='varchar')>
</cfif>

<!-- Only return records that have not be excluded from the search.
<cfset feed.addAdvancedParam(relationship='AND', field='tcontent.searchExlcude', criteria=0, condition='EQ', dataType='numeric')>

<cfset rs=application.feedManager.getFeed(feed)>

<cfdump var="#rs#">

Does that make sense?
* Last updated by: matt on 4/24/2009 @ 8:16 AM *

=================================
Matt Levine
Team Mura
Blue River Interactive Group

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
04/24/09 4:53 AM

Yep -- makes sense. Thanks a lot for adding that feature and for the code sample. I'll get back to you if I run into any issues. Thanks again!

________________
objectivebias.com

Link | Top | Bottom

matt





Joined: 04/26/08

Posts: 2639

RE: Search on Extended Attributes
04/24/09 8:15 AM

In the previous code I forgot about an important step in building query logic. The ability to group parameters like (this=a or that=d) and active=1. I just added that in.

You can now create logic groupings by

<cfset feed.addAdvancedParam(relationship='openGrouping')>

<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.title', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.summary', criteria=request.keywords, condition='CONTAINS', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='closeGrouping')>

It's in 5.1.165. If you already updated to 5.1.162 all you need to do is update the following files.

http://svn.blueriver.com/mura/trunk/www/requirements/mura/queryParam.cfc
http://svn.blueriver.com/mura/trunk/www/requirements/mura/content/feed/feedGateway.cfc

=================================
Matt Levine
Team Mura
Blue River Interactive Group

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
05/09/09 12:40 PM

Hi,
I was playing with this and I found a bug in version 5.1.257.
In feedGateway.cfc lines 381 and 382 there are a couple of cfsqltype="varchar" which should be changed to cfsqltype="cf_sql_varchar"

________________
objectivebias.com

Link | Top | Bottom

matt





Joined: 04/26/08

Posts: 2639

RE: Search on Extended Attributes
05/09/09 1:32 PM

Got it. Thanks..

=================================
Matt Levine
Team Mura
Blue River Interactive Group

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
05/09/09 5:30 PM

How would I set up query logic like this

where
(this=a AND that=b) AND (foo=C OR bar=D)

Thanks,
Tony

________________
objectivebias.com

Link | Top | Bottom

matt





Joined: 04/26/08

Posts: 2639

RE: Search on Extended Attributes
05/10/09 11:38 AM

At this point you can only does that kind if logic with the api. The feed UI has not caught up yet.

The code might look something like this:

<cfset feed.addAdvancedParam(relationship='openGrouping')>

<cfset feed.addAdvancedParam(relationship='AND', field='THIS', criteria='A', condition='EQ', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='OR', field='THAT', criteria='B', condition='EQ', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='closeGrouping')>

<cfset feed.addAdvancedParam(relationship='openGrouping')>

<cfset feed.addAdvancedParam(relationship='AND', field='FOO', criteria='C', condition='EQ', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='OR', field='BAR', criteria='D', condition='EQ', dataType='varchar')>

<cfset feed.addAdvancedParam(relationship='closeGrouping')>

* Last updated by: matt on 5/10/2009 @ 11:39 AM *

=================================
Matt Levine
Team Mura
Blue River Interactive Group

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
05/26/09 4:16 PM

Hi Matt,
Yeah, I was referring to doing it with the API. I'm still having trouble though. Any time I try to use the relationship="openGrouping" or relationship="closeGrouping" to group my query logic, I get SQL errors. So I'm probably not completely grokking how to correctly do this. (I'm using the latest Mura version from SVN as of May 25).
Basically, I'm putting together an event calendar, where an "Event" is an subtype of page with extended attributes and I'm trying to put together a search plugin for it. So here is what I've got:

<cfset feed=application.feedManager.read('') />
<cfset feed.setSiteID(request.siteid) />
<cfif len(request.categoryID)>
	<cfset feed.setCategoryID(request.categoryID) />
</cfif>
<cfset feed.setSortBy('displayStart') />
<cfset feed.setSortDirection("asc") />
<cfset feed.addAdvancedParam(relationship="AND", field='tcontent.subType', criteria="Event", dataType='varchar') />

<cfif len(request.keywords)>
	<cfset feed.addAdvancedParam(relationship='openGrouping')>
	<cfloop list="#request.keywords#" index="keyword">
		<cfset feed.addAdvancedParam(relationship="OR", field='tcontent.title', criteria=keyword, condition='CONTAINS', dataType='varchar')>
		<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.body', criteria=keyword, condition='CONTAINS', dataType='varchar')>
		<cfset feed.addAdvancedParam(relationship='OR', field='tcontent.summary', criteria=keyword, condition='CONTAINS', dataType='varchar')>
	 	<cfset feed.addAdvancedParam(relationship='OR', field='venue', criteria=keyword, condition='CONTAINS', dataType='varchar')>
		<cfset feed.addAdvancedParam(relationship='OR', field='address1', criteria=keyword, condition='CONTAINS', dataType='varchar')>
		<cfset feed.addAdvancedParam(relationship='OR', field='address2', criteria=keyword, condition='CONTAINS', dataType='varchar')>
		<cfset feed.addAdvancedParam(relationship='OR', field='city', criteria=keyword, condition='CONTAINS', dataType='varchar')>
	</cfloop>
	<cfset feed.addAdvancedParam(relationship="closeGrouping") />
</cfif>
<cfif len(request.eventTitle)>
	<cfset feed.addAdvancedParam(relationship="AND", field='tcontent.title',criteria=request.eventTitle,condition='contains',datatype="varchar") />
</cfif>
<cfif len(request.venue)>
	<cfset feed.addAdvancedParam(relationship="AND", field='venue',criteria=request.venue,condition='contains',datatype="varchar") />
</cfif>
<cfif len(request.zipCode) and not len(request.zipDistance)>
	<cfset feed.addAdvancedParam(relationship="AND", field='zip',criteria=request.zipCode,condition='equals',datatype="varchar") />
</cfif>
<cfif len(request.zipCode) and len(request.zipDistance)>
	<cfset zipCodes = getZipCodesByDistance(request.zipCode,request.zipDistance)>
	<cfset feed.addAdvancedParam(field='zip',criteria=preserveSingleQuotes(zipCodes),condition='in',datatype="varchar") />
</cfif>

<cfset rs=application.feedManager.getFeed(feed)>

Basically, the "keywords" field in the search form can take a comma-delimited list of keywords and I want to loop through that list and get all Events where any of the keywords appear in any of the Events' attributes (including extended ones). I then want to be able to further filter the search via field-specific search filters, if any of those fields were filled out (title, venue, zip code, distance from zip code).
If I type in, for example, "music, sports" in the keyword field, I get an SQL error and here is a snippet of the generated SQL:

...AND tcontent.siteid = 'njgg' and ( tcontent.subType = 'Event' ( tcontent.title like '%sports%' OR tcontent.body like '%sports%'...

As you can see, the problem is that there is no 'AND' between 'Event' and the opening parenthesis, and I'm not sure how to correct that. (putting another grouping around the 'Event' criteria doesn't help).
So at this point, I'm stumped. Any help you (or anyone) could offer would be much appreciated.
Thanks.

________________
objectivebias.com

Link | Top | Bottom

matt





Joined: 04/26/08

Posts: 2639

RE: Search on Extended Attributes
05/26/09 5:04 PM

I think that was an omission on my part. Try updating these two files:

http://svn.blueriver.com/mura/trunk/www/requirements/mura/queryParam.cfc
http://svn.blueriver.com/mura/trunk/www/requirements/mura/content/feed/feedGateway.cfc

And then make one change to your code

<cfset feed.addAdvancedParam(relationship='andOpenGrouping')>

There are now three ways to start a logic grouping.

openGrouping = "("
andOpenGrouping = "and ("
orOpenGrouping = "or ("

I also added the following relationship options:
(
and (
or (
)


So you can also use this instead;

<cfset feed.addAdvancedParam(relationship='and (')>

---  stuff ---

<cfset feed.addAdvancedParam(relationship=')')>

I think that might make more sense to alot of people, but for some reason it looks weird to me.
* Last updated by: matt on 5/26/2009 @ 5:05 PM *

=================================
Matt Levine
Team Mura
Blue River Interactive Group

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
05/26/09 5:35 PM

That fixed it! Thanks, Matt, for the quick response.

________________
objectivebias.com

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
05/28/09 10:16 PM

Okay, now I'm having trouble with condition="in"

As part of the event search, I have it so people can search within a given radius of a zip code. I use a web service call wrapped in a function to return a comma-delimited list of zip codes after passing in a zip code and a distance:

<cfset zipCodes = getZipCodesByDistance(request.zipCode,request.zipDistance)>

I then use this code to filter for events whose zip codes fall within the returned list:

<cfset feed.addAdvancedParam(field='zip',criteria=zipCodes,condition='in',datatype="varchar") />

However, it doesn't work and the generated query looks like
...and tclassextendattributes.name= 'zip' and tclassextenddata.attributeValue in ( '07188,07304,07420' )
Which doesn't work because the whole list is surrounded by one set of single quotes instead of each individual zip code. I know it uses cfqueryparam behind the scenes, so I dug into the Mura code and found what I think is bug. In feedGateway.cfc, lines 206 and 217, there are a couple of places where it says

iif(param.getCriteria() eq 'IN'
which I think should be
iif(param.getCondition() eq 'in'
because 'IN' would be a condition, not a criteria. This code sets up the list="true" or "false" within the cfqueryparam tag, so I thought that was the problem. But even after making that change and reloading the application, it still doesn't work for me and it gives me the same generated query. Any ideas?

________________
objectivebias.com

Link | Top | Bottom

matt





Joined: 04/26/08

Posts: 2639

RE: Search on Extended Attributes
05/29/09 6:38 PM

Can you try the latest version and see it it works now?

http://svn.blueriver.com/mura/trunk/www/requirements/mura/content/feed/feedGateway.cfc

=================================
Matt Levine
Team Mura
Blue River Interactive Group

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
05/29/09 7:28 PM

Yep, looks like things are good now. Thanks again!

________________
objectivebias.com

Link | Top | Bottom

DAVlDFON



DAVlDFON's Gravatar

Joined: 05/23/08

Posts: 258

RE: Search on Extended Attributes
07/31/09 10:49 AM

I have read through this numerous times as well as other related post but I am still not quite following on how to implement this.
Could either Matt or Tonyg ( or anyone who does understand) post a more step by step walk through of implementing the custom search on extended attributes? i.e where to save what files and tying in a custom search form?
It would be very much appreciated. This is a powerful option that I am sure others who are not as strong in coldfusion like myself could take advantage of.

Thanks so much

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
08/05/09 11:54 AM

@DAVIDFON
Sorry for not responding sooner. I think a little tutorial on the basics on how to do this would be a good subject for me to blog about. I'll try to get that done in the next couple of days and give you a heads up.

________________
objectivebias.com

Link | Top | Bottom

DAVlDFON



DAVlDFON's Gravatar

Joined: 05/23/08

Posts: 258

RE: Search on Extended Attributes
08/05/09 11:57 AM

Thanks Tony! Much appreciated. I look forward tot he post!

Link | Top | Bottom

DAVlDFON



DAVlDFON's Gravatar

Joined: 05/23/08

Posts: 258

RE: Search on Extended Attributes
08/17/09 2:32 PM

Tony,

Checking to see if you had time yet to make a post on this. Or provide a link to your blog - I can subscribe to RSS.

Thanks!

David

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
08/17/09 9:41 PM

Hi David,
I'm really sorry. I actually did start writing it, but I've been SUPER busy with other stuff lately. I'll try to get something up to at least get you started very soon. My blog is at:

http://www.objectivebias.com/blog

________________
objectivebias.com

Link | Top | Bottom

tonyg



tonyg's Gravatar

Joined: 05/09/08

Posts: 131

RE: Search on Extended Attributes
08/22/09 9:02 PM

David,
I finally got the blog post up. It's a pretty simple example, but hopefully enough for you to expand on.

http://www.objectivebias.com/blog/entry/searching-on-extended-attributes-in-mura-cms-using-the-feed-api

________________
objectivebias.com

Link | Top | Bottom

Next Page

Page: 1 2

Previous Page

New Post

Please login to post a response.