> > leider hab ich dazu gar nichts gefunden und wäre froh wenn 
> > ich mir einen
> > Teil der "Handarbeit" ersparen könnte.
> 
> Ich hab irgendwo sowas noch in classic ASP rumliegen... Würde 
> das helfen?
> 

Ob gewünscht oder nicht... Ich hab's jetzt gefunden und poste es... :-)

Features: AND OR NOT "text zitat" (Klammerung)
Beispiel: (IE AND NOT "Internet Explorer") OR something OR "whatever you
like"

Zusätzlich kann ein Standardoperator angegeben werden....
Damit man weiss ob folgendes: Alpha Omega
Alpha OR Omega
Oder
Alpha AND Omega
bedeutet...

Achja... Die Felder in denen gesuch werden soll kann man natürlich auch
angeben...

So... Here we go....

===================================================

<% option explicit %>
<%
  dim fields
  fields = split("firstname,lastname,CV",",")
  
  dim res
  res = parse(Request("searchStr"),fields,"AND")
%>
<html><body>
<form method="POST">
  <input name="searchStr" value="<%=Server.HTMLEncode( Request("searchStr")
)%>">
  <input type=submit>
</form>
<b>SELECT * FROM table WHERE</b> <%=res%>
</body></html>

<%
function parse(ByVal searchString,fields,defaultOperator)
  dim tokens,i,inString,char,tok,where,wasStr
  searchString = searchString & " "
  tokens = Array()
  inString=false
  tok = ""
  for i = 1 to len(searchString)
    char = mid(searchString,i,1)
    
    select case char
    case """"
      inString = not inString
      if (tok<>"") then tokens=arrayAdd(tokens,tok,not inString) : tok = ""
    case "(",")"
        if not inString then
          if (tok<>"") then tokens=arrayAdd(tokens,tok,false) : tok = ""
          tokens = arrayAdd(tokens,char,false)
        else
          tok = tok & char
        end if
    case else
          if inString or char<>" " then
            tok = tok & char
          else
            if tok<>"" then tokens=arrayAdd(tokens,tok,false) : tok = ""
          end if
    end select
  next
  
  where="" : wasStr = false
  for each tok in tokens
    select case tok
      case "(",")","AND","OR","NOT"
        where = where & " " & tok & " "
        wasStr = false
      case else
        if wasStr then where = where & " " & defaultOperator & " "
        
        where = where & " (" & join(fields," LIKE " & tok & " OR ") & " LIKE
" & tok & ") "
        
        wasStr = true
    end select
  next
  parse = where
end function

function arrayAdd(arr,ByVal str,isString)
  dim newArr()
  dim i
  redim newArr(ubound(arr)+1)
  for i = 0 to ubound(arr)
    newArr(i) = arr(i)
  next
  
  if not isString and (ucase(str)="AND" or ucase(str)="OR" _
          or ucase(str)="NOT" or str="(" or str=")") then
    str = ucase(str)
  else
    str = "'%" & replace(str,"'","''") & "%'"
  end if
  
  newArr(ubound(newArr)) = str
  arrayAdd = newArr
end function
%>



Gruss,

Claudius

_______________________________________________
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

Antwort per Email an