Examples: FTSearch and clear methods

  1. This agent full-text searches the "Transportation" view on the word "bicycle." The agent then puts the documents in the filtered view into the "Two-wheeled vehicles" folder. The agent then clears the view and puts the documents of the unfiltered view into the "Vehicles" folder.

    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
            session.getAgentContext();
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          View view = db.getView("Transportation");
          db.updateFTIndex(true);
          int count = view.FTSearch("bicycle");
          // View is filtered
          if (count == 0)
            System.out.println("No bicycles found");
          else {
            System.out.println(count + " bicycle(s) found");
            Document tmpdoc;
            Document doc = view.getFirstDocument();
            while (doc != null) {
              doc.putInFolder("Two-wheeled vehicles");
              tmpdoc = view.getNextDocument(doc);
              doc.recycle();
              doc = tmpdoc;
            }
          }
          // Clear the full-text search
          view.clear();
          // View is no longer filtered
          Document doc = view.getFirstDocument();
          while (doc != null) {
            doc.putInFolder("Vehicles");
            tmpdoc = view.getNextDocument(doc);
            doc.recycle();
            doc = tmpdoc;
          }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent full-text searches the "By Category" view on a word or words supplied by the user as the agent comment. The agent then prints the number of documents located and the value of the Subject item of each document in the filtered view.

    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
            session.getAgentContext();
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Agent agent = agentContext.getCurrentAgent();
          String searchString = agent.getComment();
          View view = db.getView("By Category");
          db.updateFTIndex(true);
          int count = view.FTSearch(searchString, 0);
          if (count == 0)
            System.out.println("Nothing found");
          else {
            System.out.println(count + " found");
            Document tmpdoc;
            Document doc = view.getFirstDocument();
            while (doc != null) {
              System.out.println(doc.getItemValueString("Subject"));
              tmpdoc = view.getNextDocument(doc);
              doc.recycle();
              doc = tmpdoc;
            }
          }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }