Subsribe to our RSS

latest reactions

Montana Flynn
haha …
some1
Hi, Thank you for help me testing my sit …
metin2 yang
it is very nice …
Tjarko
I would'nt use cfhtmlhead for anything ; …
Sebastiaan
Hi Tjarko,Would you suggest injecting…

Use OpenDNS

mxna feeds

A Special ColdFusion Builder Event in Tampa, FLColdFusion Contract Job in Marbella, SpainColdFusion Job Opportunity in West London, United KingdomColdFusion Job Opportunity in Bethesda, MDColdFusion Job Opportunity in Springfield, MOColdFusion Job Opportunity in Seattle, WAColdFusion Builder - RefactoringColdFusion Job Opportunity in Raleigh, NCColdFusion Job Opportunity in Quincy, MAColdFusion Job Opportunity in Memphis, TNColdFusion Job Opportunity in San Antonio, TXUsing Base64 Canvas Data In jQuery To Create ColdFusion ImagesMy move from using cfhttp and rssatom.cfc to cffeed.Infinite entities, cfgrid and one cfc to handle the dataJob: ColdFusion Developer - Marbella, Spain

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2010 mximize.com.
All right reserved.

MXNA webfeed

Visit Carlos GallupaPowered by ColdFusion MX

Get SEO keywords automatically from an article or page

I just finished a nice little function to get the "best" keywords for the page displayed in every website we build with our CMS. Below is an example, what you get is a list of the words that are mostly used in the given page and therefore the best to use as META keywords or tags in your page. At least if you like to be found on the contents of your page...

<cfsavecontent variable="txt">
A nice little piece of text with at least twice the word little in the text, and off course three times the word text ;-)
</cfsavecontent>

<cffunction name="getSEOWords" access="public" output="true">
    <cfargument name="content" required="true" type="string" />
    <cfset var lsStopWords = "stop wordlist in your language (google it)" />
    <cfset list = arrayToList(listToArray(REReplace(arguments.content, "[[:space:]]{2,}"," ", "all" ), " ")) />
    <cfset var stWords = structNew() />
    <cfset var lsTop = "" />
    <cfset var aSort = arrayNew(1) />
   
    <!--- Get a unique structure of words counted --->
    <cfloop list="#list#" index="value">
        <cfif !listFindNoCase(lsStopWords, value) && !isNumeric(value)>
            <cfset value = trim(value) />
            <cfif structKeyExists(stWords, value)>
                <cfset stWords[value] = stWords[value] + 1 />
            <cfelse>
                <cfset stWords[value] = 1 />
            </cfif>
        </cfif>
    </cfloop>
   
    <!--- Order the structure with words, first keys are the words with the most counts --->
    <cfset aSort = structSort(stWords, "numeric", "desc") />
   
    <!--- Get the first 15 words from the list, if the count is more than one. --->
    <cfloop from="1" to="15" index="i">
        <cfif stWords[aSort[i]] GT 1>
            <cfset lsTop = listAppend(lsTop, aSort[i]) />
        </cfif>
    </cfloop>

    <cfreturn lsTop />
</cffunction>

<cfoutput>
    #getSEOWords(txt)#
</cfoutput>

2456 viewed | 6 opinion(s)  | del.icio.us | Digg it | Tjarko @ 13/10/09 17:19 cet


Reactions:

Darren Walker wrote.... (mail)

Instead of just judging keywords by counting, why not use the Yahoo term extractor API (http://developer.yahoo.com/search/content/V1/termExtraction.html) - Pass it your content, it will return what is judges are the best keywords. It is a clever way of introspecting your content. If the keywords returned don't match what you think the content is about, then you should probably change your content.

14 October 2009 12:22 cet  

Tjarko wrote.... (site)

Hi Darren, txns, didn't know about that API. Will look into that.

14 October 2009 13:44 cet  

Mike Appenzellar wrote.... (mail)

I tried this and got "Local variable stWords on line 17 must be grouped at the top of the function body. " is this specfic to coldfusion 9?

10 December 2009 13:56 cet  

Tjarko wrote.... (site)

hi Mike,

My bad.. the following should be

<cfset list
<cfset var list

Then it will work :-)

10 December 2009 13:58 cet  

Sebastiaan wrote.... (site)

Hi Tjarko,

Would you suggest injecting meta-tags on the fly with cfhtmlhead per page using your code above? What would else be the use for this function?

25 January 2010 15:07 cet  

Tjarko wrote.... (site)

I would'nt use cfhtmlhead for anything ;-) The way we use it, is in the OnRequestEnd.cfm were we also strip all whitespace and set the title for the page. See this article http://www.mximize.com/strip-whitespace

25 January 2010 15:13 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



The answer to the ultimate question is?? (42 ;-))




URL en mail addresses are translated for you... life sometimes is that simple!!