涉及日期字段的FTSearch令我困惑

时间:2012-04-28 14:41:52

标签: lotus-notes xpages xpages-ssjs

我的自定义控件带有搜索屏幕,可让用户选择最多六个不同的字段进行搜索。除了两个日期字段之外,我没有遇到所有其他字段的工作。他们可以填写开始和结束日期或只填写其中一个。非常标准的东西,但我无法弄清楚如何编写代码使查询工作,并让它在涉及日期时进行搜索。

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

5 个答案:

答案 0 :(得分:1)

如果我正确阅读,您的查询将解析为

FIELD DeliveredDate >= "xx/yy/zz"

我的第一直觉是你需要这个:

FIELD DeliveredDate >= [xx/yy/zz]

但是文档表明你不需要括号或引号,所以:

FIELD DeliveredDate >= xx/yy/zz

答案 1 :(得分:1)

if(requestScope.edtFrom != & requestScope.edtFrom != "") {行未完成。你错过了要测试的部分。我认为它缺乏空检查,因此应该是:

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>

如果第二部分是您要查找的格式,它将返回以下内容:

(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

答案 2 :(得分:0)

仔细检查此处创建的查询。也许将其打印到屏幕或从调试器中获取它。您可能会在查询中看到问题,我相信您应该能够获取该确切的查询并将其粘贴到已经全文索引的数据库的搜索窗口中。

另外,看看这个涵盖笔记查询语法的文档,它可以帮助您排除故障。我的代码中没有看到任何错误。

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

答案 3 :(得分:0)

日期应始终(根据我的经验)以mm / dd / yyyy格式编写,例如

[deliverdatemin]&gt; = 1/1/2012和[deliverdatemax]&lt; = 1/30/2012

找出要生成的查询的简单方法是使用以下代码来生成生成的查询错误

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

或者您可以简单地执行print()以在serverconsole上显示查询

答案 4 :(得分: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())