My hunch is that you will need to use the full text search to find the
product_id and its description and then further process the results to
display only what you want. For example

<cfset keyword=#search_query#>
<cfloop query="qresults">
<cfscript>
    offset=25;
    delim1='<span class="highlight">';
   delim2='</span>';
 //find the key word and offset characters before and after
    pos=findnocase(keyword,qresults.product_desc);
    if(pos GT 0){
   pos_start=max(1,pos-offset);
     pos_end =pos + len(keyword)+offset;

     if(len(qresults.product_desc) LE pos_end){
          pos_end=len(qresults.product_desc);
     }
     //selected part + add a space so the "left" function will never fail
     //strip characters till we find a space
      show_text=mid(qresults.product_desc,pos_start,pos_end-pos_start+1) & "
";
     while(left(show_text,1) is not ' '){
         show_text=right(show_text,len(show_text)-1);
     }
   show_text=trim(show_text);
   //prepend a space so "right" will never fail
     show_text=" " & show_text;
     while(right(show_text,1) is not ' '){
         show_text=left(show_text,len(show_text)-1);
     }
   show_text=trim(show_text);
    show_text=replacenocase(show_text,keyword,delim1 & keyword &
delim2,"ALL");
  }
  else{
   show_text=delim1 & keyword & delim2 & " not found.";
  }

</cfscript>

{whatever you want to do with the text}
</cfloop>


I have put up an example of this at:
http://www.vawter.com/utilities/highlight.cfm
This simple example doesn't look for multiple keywords or multiple instances
of a keyword but could be modified to do so.

If there is any interest I could write either a custom tag or udf to do
this.

HTH

Don



Don Vawter
www.cyberroomies.com
[EMAIL PROTECTED]

----- Original Message -----
From: "Michael Lugassy" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Monday, September 03, 2001 9:05 AM
Subject: OT: SQL Filtered SELECT


> I use a SQL Full Text query that finds search_query in Product_desc,
> Something like this:
>
> SELECT Product_id, Product_desc
> FROM Products WHERE CONTAINS(Product_desc,'#search_query#')
>
> What if I don't want to select the complete Product_Desc field, but only
> portions of it?
> By only portions I mean - Text that is most relevent to the search
> query. Overall - I want to output 3-4 sentences that have as much
> keywords (from the search_query) As possible, just like Google does to
> its search results. I.e: a search for "science fiction" will yield:
>
> ..THE ULTIMATE |SCIENCE FICTION| WEB GUIDE..
> ...ALMOST SIX THOUSAND LINKS TO WEB |SCIENCE FICTION|...
> ...Here you can find definitions and RESOURCES of |"Science Fiction"|
> ...
>
> Help, anyone?
>
> Michael.
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to