FTSearch related to date fields confuses me

I have a Custom Control with a search screen that allows users to select any of six different search fields. I had no problem making all other fields work, with the exception of two date fields. They can fill in both the start and end dates, or just one or the other. Pretty standard stuff, but I can't figure out how to write code to make the query work, and to let it search when it includes dates.

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

Any help would be appreciated

The idea for this screen was taken from this video: XPages View Control - Add full-text search - http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPagesViewControlAddFullTextSearch.htm

+3
source
5

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
+1

,

FIELD DeliveredDate >= "xx/yy/zz"

, :

FIELD DeliveredDate >= [xx/yy/zz]

, , :

FIELD DeliveredDate >= xx/yy/zz
+1

( ) mm/dd/yyyy, ,

[deliverdatemin] >= 1/1/2012 [deliverdatemax] <= 1/30/2012

An easy way to find out which request you are creating is to use the following code snippet to cause an error with the generated request

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

Or you can just do print () to display the request on the server console

0
source
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")

or

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

0
source

All Articles