3

ユーザーが検索する最大 6 つの異なるフィールドのいずれかを選択できる検索画面を備えたカスタム コントロールがあります。2 つの日付フィールドを除いて、他のすべてのフィールドを問題なく動作させることができました。開始日と終了日の両方を入力することも、どちらか一方だけを入力することもできます。かなり標準的なものですが、クエリを機能させるコードを記述して、日付が含まれる場合に検索を実行させる方法がわかりません。

var tmpArray = new Array("");
var cTerms = 0;
if(requestScope.cmbSendTo != null & requestScope.cmbSendTo != "") {
    a = @Right(requestScope.cmbSendTo, "(");
    b = @Left(a,3);
tmpArray[cTerms++] = "(FIELD Mnemonic = \"" + b + "\")";
}
if(requestScope.edtFrom != & requestScope.edtFrom != "") {
tmpArray[cTerms++] = "(FIELD From = \"" + requestScope.edtFrom + "\")";
}
//**************************************************************************
if(requestScope.edtDateRangeFrom != null & requestScope.edtDateRangeFrom != "") {
tmpArray[cTerms++] = "(FIELD DeliveredDate >= \"" + requestScope.edtDateRangeFrom + "\")";
}
if(requestScope.edtDateRangeTo != null & requestScope.edtDateRangeTo != "") {
tmpArray[cTerms++] = "(FIELD DeliveredDate <= \"" + requestScope.edtDateRangeTo + "\")";
}
//**************************************************************************
if(requestScope.edtOriginal != null & requestScope.edtOriginal != "") {
tmpArray[cTerms++] = "(FIELD SourceFilename = \"" + requestScope.edtOriginal + "\")";
}
if(requestScope.edtCaptiva != null & requestScope.edtCaptiva != "") {
tmpArray[cTerms++] = "(FIELD Filename = \"" + requestScope.edtCaptiva + "\")";
}
qstring = tmpArray.join(" AND ").trim();
requestScope.queryString = qstring;
return qstring

任意の支援をいただければ幸いです

この画面の背後にあるアイデアは、次のビデオから引用されています: XPages ビュー コントロール - 全文検索の追加 - http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPagesViewControlAddFullTextSearch.htm

4

5 に答える 5

1

私が正しく読んでいる場合、あなたのクエリは次のように解決されています

FIELD DeliveredDate >= "xx/yy/zz"

私の最初の本能は、代わりにこれが必要だということでした。

FIELD DeliveredDate >= [xx/yy/zz]

ただし、ドキュメントには、角かっこや引用符は必要ないことが示されているため、次のようになります。

FIELD DeliveredDate >= xx/yy/zz
于 2012-04-28T17:56:01.067 に答える
1

if(requestScope.edtFrom != & requestScope.edtFrom != "") {は完全ではありません。テストする部分がありません。nullチェックがないため、次のようになります。

if(requestScope.edtFrom != null & requestScope.edtFrom != "") {

さらに、クエリに期待するものを返すように日付をフォーマットする必要があります(例:MM / dd / yyyy)。inputTextコントロールのフォーマットは、視覚的なフォーマットにのみ適用され、実際のコンテンツのフォーマットには適用されません。

最後に、日付の前後の引用符を削除する必要があります。

コードに基づく次のコード例は、フォーマットせずに日付を返し、正しいフォーマットで日付を返します。

<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="computedField1"></xp:eventHandler>
</xp:button>

<xp:inputText id="edtDateRangeFrom" value="#{requestScope.edtDateRangeFrom}">
    <xp:this.converter>
        <xp:convertDateTime type="date"></xp:convertDateTime>
    </xp:this.converter>
    <xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText>

<xp:text escape="true" id="computedField1">
    <xp:this.value><![CDATA[#{javascript:var tmpArray = new Array("");
    var cTerms = 0;
    if(requestScope.edtDateRangeFrom != null & requestScope.edtDateRangeFrom != "") {
        tmpArray[cTerms++] = "(FIELD DeliveredDate >= \"" + requestScope.edtDateRangeFrom + "\")";
        var dateFormatter = new java.text.SimpleDateFormat( "MM/dd/yyyy" );
        var formattedDate = dateFormatter.format( requestScope.edtDateRangeFrom );
        tmpArray[cTerms++] = "(FIELD DeliveredDate >= " + formattedDate + ")";
    }

    qstring = tmpArray.join(" AND ").trim();
    requestScope.queryString = qstring;

    return qstring}]]>
    </xp:this.value>
</xp:text>

2番目の部分があなたが探しているフォーマットである場合、それは以下を返します:

(FIELD DeliveredDate >= "Fri Apr 27 12:00:00 CEST 2012")
AND (FIELD DeliveredDate >= 04/27/2012)

これらすべての更新を含むコードは次のとおりです。

var tmpArray = new Array("");
var cTerms = 0;
var dateFormatter = new java.text.SimpleDateFormat( "MM/dd/yyyy" );
var formattedDate = "";
if(requestScope.cmbSendTo != null & requestScope.cmbSendTo != "") {
    a = @Right(requestScope.cmbSendTo, "(");
    b = @Left(a,3);
tmpArray[cTerms++] = "(FIELD Mnemonic = \"" + b + "\")";
}
if(requestScope.edtFrom != null & requestScope.edtFrom != "") {
tmpArray[cTerms++] = "(FIELD From = \"" + requestScope.edtFrom + "\")";
}

if(requestScope.edtDateRangeFrom != null & requestScope.edtDateRangeFrom != "") {
    formattedDate = dateFormatter.format( requestScope.edtDateRangeFrom );
    tmpArray[cTerms++] = "(FIELD DeliveredDate >= " + formattedDate + ")";
} 
if(requestScope.edtDateRangeTo != null & requestScope.edtDateRangeTo != "") {
    formattedDate = dateFormatter.format( requestScope.edtDateRangeTo );
    tmpArray[cTerms++] = "(FIELD DeliveredDate <= " + formattedDate + ")";
}


if(requestScope.edtOriginal != null & requestScope.edtOriginal != "") {
tmpArray[cTerms++] = "(FIELD SourceFilename = \"" + requestScope.edtOriginal + "\")";
}
if(requestScope.edtCaptiva != null & requestScope.edtCaptiva != "") {
tmpArray[cTerms++] = "(FIELD Filename = \"" + requestScope.edtCaptiva + "\")";
}
qstring = tmpArray.join(" AND ").trim();
requestScope.queryString = qstring; // this just displays the query
return qstring // this is what sets the search property
于 2012-04-28T19:26:31.543 に答える
0

ここで作成されているクエリを再確認してください。おそらく、それを画面に印刷するか、デバッガーから取得します。クエリ内に問題が発生する可能性があります。その正確なクエリを取得して、フルテキストインデックスが作成されたデータベースの検索ウィンドウに貼り付けることができるはずです。

また、メモのクエリ構文について説明しているこのドキュメントを参照してください。トラブルシューティングに役立つ場合があります。ただし、コードに問題はありませんでした。

http://www.loganmachinists.com/help/help8_client.nsf/f4b82fbb75e942a6852566ac0037f284/0e044d2c0639c979852572fe00687f29?OpenDocument

于 2012-04-28T15:54:16.350 に答える
0
As of my concern The best way to handle the date field is that converting our date value for one specific format using NotesDateTime., Because this is the best date conversion for xpage.

Dim dateTime As New NotesDateTime( "date String" )

また

Dim dateTime As New NotesDateTime( NotedateTime.getDtaeOnly() )

于 2012-05-02T08:14:58.957 に答える
0

日付は常に (私の経験では) mm/dd/yyyy の形式で記述する必要があるため、たとえば

[deliverdatemin] >= 1/1/2012 および [deliverdatemax] <= 1/30/2012

生成しているクエリを見つける簡単な方法は、次のコードを使用して、生成されたクエリでエラーをスローすることです。

//youre own code  
throw new java.lang.exception(queryvariable);

または、単純に print() を実行して、サーバーコンソールにクエリを表示することもできます

于 2012-04-28T17:52:42.027 に答える