0

I am using vectors to perform multi-column search functionality in XPages. Its working but not efficiently. In filter column value property I am using below code:

try {
    var vtr:java.util.Vector = new java.util.Vector();
    var t1 = sessionScope.searchfirstName;
    var t2 = sessionScope.searchlastname;
    var t3 = sessionScope.searchemail;
    var t4 = sessionScope.searchcountry;
    var t5 = sessionScope.searchcompany;

    @If(t1 !=null,vtr.addElement(t1),vtr.addElement(""));   
    @If(t2 !=null,vtr.addElement(t2),vtr.addElement(""));
    @If(t3 !=null,vtr.addElement(t3),vtr.addElement(""));
    @If(t4 !=null,vtr.addElement(t4),vtr.addElement(""));
    @If(t5 !=null,vtr.addElement(t5),vtr.addElement(""));

    return vtr;
} catch(e) {
}

When I am performing search operation, it will work for some values not for all. Like if I search for "Raj" as first name it will show me result but if I search for "Yadav" as last name then it will show me 0 result.

Naveen
  • 6,786
  • 10
  • 37
  • 85
Raj
  • 264
  • 1
  • 3
  • 18
  • vtr.addElement(t1?t1:"") is shorter. But you will need to keep ifs to format key values according to view columns - as stwissel explains. – Frantisek Kossuth Jun 04 '13 at 15:15

1 Answers1

1

I presume you use the Vector to search a view. In Notes the view search requires "ascending filled" keys (besides all columns need to be sorted). So when your second element in the Vector is not null the first one can't be null either. Notes will search the first key, then on the result with the second and so on until the key is empty. So when you only search with the second key your result will be empty. This is a core Notes capability and not specific to XPages. You could use a ft search with field names against the view instead.

Update:
So what could you do? The following code is off my head, so you might need to fix typos:

try {
    var vtr:java.util.Vector = new java.util.Vector();
    var t1 = sessionScope.searchfirstName;
    var t2 = sessionScope.searchlastname;
    var t3 = sessionScope.searchemail;
    var t4 = sessionScope.searchcountry;
    var t5 = sessionScope.searchcompany;

    var resultArray = [];
    if (t1) { resultArray.push("[FirstName] = " + t1); };
    if (t2) { resultArray.push("[LastName] = " + t2); };
    if (t3) { resultArray.push("[eMail] = " + t3); };
    if (t4) { resultArray.push("[Country] = " + t4); };
    if (t5) { resultArray.push("[Company] = " + t5); };

    return @Implode(resultArray, " AND ");

} catch(e) {
   print(e.message);
}

Then you do a NotesView.FTSearch(....)

Advantage for this method: your view can be sorted in any way, you can search for fields that are not even shown in the view. Disadvantage: you need a FTIndex and it is a little more work since you can't use the view control with the resulting DocumentCollection - you need a RepeatControl

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Yes. All the columns are ascending. When I am searching using second or third or fourth key, sometimes it gives result but not correct one. – Raj Jun 04 '13 at 11:19
  • Not the column sorting up or down is important here. They key is important. Search requires all elements of the Vector to be non null. The scenario with null, "Yadav" is an unsupported search - results can be anything. In short: Null is not a valid search key. Neither is "". – stwissel Jun 04 '13 at 14:50
  • Thank you @stwissel. You are genius. I used your technique to put the keys in array and then using Search property to obtain desired result in view Panel. Thank you once again. – Raj Jun 05 '13 at 16:49