Examples: FTSearch method (Database - Java)

  1. This agent searches the current database for the phrase specified in the agent's comment if the database is full-text indexed. Every document, up to a maximum of 100 documents containing the phrase is placed into a document collection.
    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
              session.getAgentContext();
          // (Your code goes here) 
          Agent agent = agentContext.getCurrentAgent();
          Database db = agentContext.getCurrentDatabase();
          String title = db.getTitle();
          if (db.isFTIndexed()) {
            DocumentCollection dc = db.FTSearch
            (agent.getComment(), 100);
            int matches = dc.getCount();
            System.out.println
            ("FTSearch of \"" +  title + "\" found " +
               matches + " document(s) with " + 
               agent.getComment()); }
          else
            System.out.println
              ("Database \"" + title + 
               "\" is not full-text indexed");
          
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This code fragment collects all documents containing both the words "red" and "blue."
    DocumentCollection dc = db.FTSearch("red & blue", 100);
  3. This code fragment collects all documents containing either the word "red" or "blue" in descending order by creation date.
    DocumentCollection dc = db.FTSearch("red | blue", 100,   Database.FT_DATE_DES, 0);
  4. This code fragment collects all documents that do not contain the word "red" or "blue" in descending order by creation date.
    DocumentCollection dc = db.FTSearch("not (red | blue)", 100,Database.FT_DATE_DES, 0);