www.pudn.com > GOOGLE.rar > 5.pas, change:2002-04-09,size:1893b


procedure TFrmSearch.btnSearchClick(Sender : Tobject); 
var 
  SerachPhrase : TaaSearchParser; 
  RPNWalker    : TaaRPNNode; 
  Stack        : TBitSetStack; 
  BS1          : TaaBitSet; 
  BS2          : TaaBitSet; 
  i            : integer; 
begin 
  {prepare for the evaluation} 
  lbxResults.Items.Clear; 
  SearchPhrase := nil; 
  Stack := nil; 
  BS1 := nil; 
  try 
    {parse the search phrase} 
    SearchPhrase := TaaSearchPhrase.Create(edtSearchPhrase.Text); 
    RPNWalker := SearchPhrase.RPN; 
    {create the stack for evaluating the RPN expression} 
    Stack := TBitSetStack.Create; 
    while (RPNWalker <> nil) do 
      begin 
        if RPNWalker is TaaRPNWord then  
          begin 
            BS1 := TaaBitSet.Create(DocList.Count); 
            BS2 := WordIndex.Find(TaaRPNWord(RPNWalker).PhraseWord); 
            if (BS2 <> nil) then 
              BS1.Assign(BS2); 
            Stack.Push(BS1); 
          end 
        else if RPNWalker is TaaRPN_AND then 
          begin 
            BS1 := Stack.Pop; 
            BS2 := Stack.Pop; 
            BS1.AndBitSet(BS2); 
            Stack.Push(BS1); 
            BS2.Free; 
          end 
        else if RPNWalker is TaaRPN_OR then 
          begin 
            BS1 := Stack.Pop; 
            BS2 := Stack.Pop; 
            BS1.OrBitSet(BS@); 
            StackPush(BS1); 
            BS2.Free; 
          end 
        else {RPNWalker is TaaRPN_NOT} 
          begin 
            BS1 := Stack.Pop; 
            BS1.NOTBitSet; 
            Stack.Push(BS1); 
          end; 
        BS1 := nil; 
        RPNWalker := RPNWalker.Next; 
      end; 
    {display the results}       
    BS1 := Stack.Pop; 
    for i :=0 to pred(DocList.Count) do 
      begin 
        if BS1[i] then 
          lbxResult.Items.Add(DocList[i]); 
      end; 
  finally 
    BS1.Free; 
    Stack.Free; 
    SearchPhrase.Free; 
  end; 
end;