2014-01-31 52 views
0

我正在從兩個日期提取會議:獲取當月的所有會議。有沒有什麼辦法可以向Notes數據庫詢問查詢

假設我在指定的時間內約有45次會議。我的網絡服務花費了很多時間。 這是我正在做它現在:

  1. 我取在日曆視圖中的所有文件。

  2. 檢查開始的所有文檔日期和結束日期。

  3. 如果任何會議在指定的時間內落在我構建一個數組,我將返回該數組。

這是正確的嗎?

回答

0

這是正確的,但是當您擁有大量文檔時性能不是很高。基本上你會創建一個視圖,第一列是會議(開始)日期,排序。在LotusScript中,您可以訪問視圖,設置與開始日期相匹配的第一個會議的「光標」,然後逐步瀏覽視圖,直到到達結束日期之後的某個日期。

閱讀關於view的GetDocumentByKey方法。更多在這裏:http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_LOCATING_DOCUMENTS_WITHIN_A_VIEW_OR_FOLDER.html

嗯......思考一個litlle進一步,如果你有一個開始日期但沒有匹配的會議會發生什麼......所以請參閱FTSearch()方法。

3

這種方式是正確的,但效率很低。更好地利用NotesDatabase-類,並創建一個查詢與搜索 - 的方法來使用: 這裏用LotusScript一個例子(因爲你沒有指定語言)

Dim ses as New NotesSession 
Dim db as NotesDatabase 
Dim dc as NotesDocumentCollection 
Dim strQuery as String 


Set db = ses.CurrentDatabase 
strQuery = {Form = "Appointment" & _ 
(StartDate >= [01.01.2014] & StartDate < [01.02.2014]) | _ 
(EndDate >= [01.01.2014] & EndDate < [01.02.2014])} 
Set dc = db.Search(strQuery , Nothing, 0) 
'- Cycle through this collection... 

當然,你需要通過動態調整strQuery從今天的日期開始構建它......但是這將比你的版本更具性能。

+2

如果對每個術語的第二個條件使用'<'而不是'<=',則可以使查詢公式更容易計算,並跳至下個月的第一個位置(而不需要計算出本月的最後)。 –

+0

非常好的評論!我用這個建議改進了我的答案! –

0

如果您使用Notes/Domino 9.0或更高版本,則應使用內置日曆類。這些可以從LotusScript或Java中獲得。這裏有一個使用Java的例子。給定一個數據庫對象和日期範圍,它打印範圍內的所有條目:

private static void printRange(Database database, DateTime start, DateTime end) throws NotesException { 

    // Get the calendar object from the database 
    NotesCalendar calendar = database.getParent().getCalendar(database); 
    if (calendar != null) { 

     // Get a list of calendar entries 
     Vector<NotesCalendarEntry> entries = calendar.getEntries(start, end); 
     if (entries != null) { 

      // For each entry ... 
      Iterator<NotesCalendarEntry> iterator = entries.iterator(); 
      while (iterator.hasNext()) { 
       NotesCalendarEntry entry = iterator.next(); 

       // Read the iCalendar representation 
       String icalendar = entry.read(); 

       // Get the Notes UNID 
       Document doc = entry.getAsDocument(); 
       String unid = doc.getUniversalID(); 

       // Print UNID and iCalendar to console 
       System.out.println("Entry UNID: " + unid); 
       System.out.println(icalendar); 
      } 
     } 
    } 
} 

的NotesCalendar和NotesCalendarEntry接口處於lotus.domino中包。如果您使用的是LotusScript,則有相同名稱和相同方法的類。

一對夫婦關於上述代碼警告:

  1. 它不處理重複條目的細微差別。您可以在同一時間範圍內有多個重複條目實例。在Notes中,這些條目可能具有相同的UNID。你應該重複測試你的代碼,以確保你瞭解細微差別。
  2. 該示例不會像原本那樣回收Document,NotesCalendarEntry和NotesCalendar對象。爲了簡單起見,我忽略了這一點,但如果您使用的是Notes Java類,那麼您肯定需要正確使用recycle()。它將會挽救頭痛。
相關問題