3
votes

I'm trying to filter a viewPanel using its search property. The viewPanel hasn't any categorized column.

These documents are using readers and authors fields. One problem is the fact that I'm getting some empty rows in views representing the "hidden" documents.

The filter input fields are all contained in Doc. type, and as well in Response type.

var tmpArray = new Array("");
var cTerms = 0; 
var dateFormatter = new java.text.SimpleDateFormat( "MM-dd-yyyy" ); 

if (sessionScope.compA) { 
tmpArray[cTerms++] = "(Field Comp = \"*" + sessionScope.compA + "*\")"; 
tmpArray[cTerms++] = "(Field Compania = \"*" + sessionScope.compA + "*\")"; 
/* Comp - the field from Doc. & Compania - the field from Response */
} 

if (sessionScope.numePro) { 
tmpArray[cTerms++] = "(Field NumeProiect = \"*" + sessionScope.numePro + "*\")"; 
tmpArray[cTerms++] = "(Field Proiect = \"*" + sessionScope.numePro + "*\")"; 
/* NumeProiect - the field from Doc. & Proiect - the field from Response */
} 
if (sessionScope.din && sessionScope.pana) {
    tmpArray[cTerms++] = "Field _creationDate >= " + dateFormatter.format(sessionScope.din) + " AND Field _creationDate <= " + dateFormatter.format(sessionScope.pana);
}      
qstring = tmpArray.join(" OR ").trim(); 
sessionScope.queryString = qstring; 
return qstring

But I don't get the expected results, I do get something like: the correct documents for sessionScope.compA, but if I add a value for the 2nd sessionScope.numePro which isn't contained in any documents listed by the view, the results are the same, and there should be no result.

How can I achieve this?

1
If you use OR to connect all conditions then it needs only one condition to be true to show a document.Knut Herrmann
@KnutHerrmann I tried firstly with AND, but no results are displayedFlorin M.

1 Answers

1
votes

My guess is that you just mixed up the logical connection between the ftsearch parts. The following code should work for you:

var tmpArray = new Array("");
var cTerms = 0; 
var dateFormatter = new java.text.SimpleDateFormat( "MM-dd-yyyy" ); 

if (sessionScope.compA) { 
    tmpArray[cTerms++] = "((Field Comp = \"*" + sessionScope.compA + "*\") OR " + 
                          "(Field Compania = \"*" + sessionScope.compA + "*\"))"; 
    /* Comp - the field from Doc. & Compania - the field from Response */
} 

if (sessionScope.numePro) { 
    tmpArray[cTerms++] = "((Field NumeProiect = \"*" + sessionScope.numePro + "*\") OR " + 
                          "(Field Proiect = \"*" + sessionScope.numePro + "*\"))"; 
    /* NumeProiect - the field from Doc. & Proiect - the field from Response */
} 
if (sessionScope.din && sessionScope.pana) {
    tmpArray[cTerms++] = "Field _creationDate >= " + dateFormatter.format(sessionScope.din) + 
    " AND Field _creationDate <= " + dateFormatter.format(sessionScope.pana);
}      
qstring = tmpArray.join(" AND ").trim(); 
sessionScope.queryString = qstring; 
return qstring