This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 10, 2011, 8:43 PM
14 Posts

FTSearch: problem getting a subset of the results

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.1
  • Role: Developer
  • Tags: FTSearch subset slice()
  • Replies: 5
Hi, all,
 
I'm using FTSearch on a database so large it often finds more than 500 documents.  The collection is always sorted correctly, by date.
 
The client wants to display a maximum of 500 documents.  Say the number of records returned by the search is 700; if I set the maxreturn to 500, the documents returned are not the first 500, they are the collection of 700 with 200 documents culled out.
 
The clients want to see the literal first 500 in the collection.  So I tried setting the maxreturn to 0, which returned the entire collection, then using .slice(0,500) to display the first 500 documents.  But the result was the same: 200 random documents not displaying.  If I set the maxreturn or .slice to 200, it culls the collection even more.
 
Here's my slice code:
 
return getArray(entries).slice(0,500)
 
Any ideas greatly appreciated.
 
Sally
Aug 11, 2011, 8:55 AM
261 Posts
Re: FTSearch: problem getting a subset of the results
Hello Sally,
 
What you could do:
  • let the FTSearch return all documents.
  • process the resulting NotesDocumentCollection: copy the values you need to an array of (Javascript) objects.
  • sort that array the way you want (e.g. by date).
  • slice the array to 500 entries.
  • display the results using the array.
This technique is also described in this blog post: http://dontpanic82.blogspot.com/2011/01/xpages-small-update-to-search-interface.html
 
Mark
Aug 11, 2011, 11:48 AM
129 Posts
Re: FTSearch: problem getting a subset of the results
I haven't used the subtract method of NotesDocumentCollection, so I'm not sure if this works, but it might be worth a try.
 
// After the collection is built... 
var removeCount = collection.getCount()  - 500;
if( removeCount <= 0 ){ return collection; } 
 
// Trim the collection to 500 documents 
for( var i = 0; i <= removeCount; i++ ){
   collection.subtract( collection.getLastDocument().getNodeID() );
 
return collection; 
Aug 11, 2011, 7:31 PM
14 Posts
Re: FTSearch: problem getting a subset of the results
Hiya, Tommy,
 
Thanks for the suggestion.  I couldn't get it to work, though.  It's probably me... I'm very flat-footed with the code.
 
Here is what I tried:
 
if(parseCriteria(asearch)){

        entries.FTSearch(asearch, maxreturn);
        resultNum = entries.getCount();
        var removeCount = entries.getCount()  - 500;
        sessionScope.resultDesc = "Alliance Search Results: "+resultNum+" results found.";
        sessionScope.searchString = asearch;
 
        if (resultNum > 0) {
            viewScope.unidCollection = getUnidCollection(entries);            
      if (resultNum >= topResults){
                viewScope.tooManyResults = true;
                /*
                viewScope.ResultDisplay = '<font color="red">*Your search has yielded ' +resultNum +' results.*</font><br><br>' +
                'We have listed the most recent 500 results for this search.  If you wish to view other records for this search, '+
                'please go ' +
                '<a href="AllianceSearchBuilder.xsp"><font color="blue">BACK</a></font> ' +
                'and revise the search for a more accurate result set.<br><br><br>';          
                */
            }
            
            if (resultNum < topResults) {
            viewScope.ResultDisplay = resultNum+" results<br>";
                }
 
           // Trim the collection to 500 documents
            for( var i = 0; i <= removeCount; i++ ){
             entries.subtract( entries.getLastDocument().getNodeID() );
            }
 
            return getArray(entries);                
        }else{
            viewScope.ResultDisplay = '<!-- SEARCH RESULTS TOP INFO DISPLAY --><table width="100%" cellpadding="10" cellspacing="0"><tr><td>' +
            '<font size="2">No Result Found from your Search Criteria.</font></td></tr></table><!-- END SEARCH RESULTS -->';        
        }    
    }else{
        viewScope.ResultDisplay = '<!-- SEARCH RESULTS TOP INFO DISPLAY --><table width="100%" cellpadding="10" cellspacing="0"><tr><td>' +
        '<font size="2">There was ERROR with Search Criteria.</font></td></tr></table><!-- END SEARCH RESULTS -->'+asearch;            
    }
Aug 12, 2011, 5:24 AM
129 Posts
Re: FTSearch: problem getting a subset of the results
My example code was for a NotesDocumentCollection, but it looks like you have a NotesViewEntryCollection.
 
Try this instead when filtering the collection: 
for( var i = 0; i <= removeCount; i++ ){
  entries.subtract( entries.getLastEntry() );
Aug 12, 2011, 4:24 PM
14 Posts
Re: FTSearch: problem getting a subset of the results
 
Yes, that didn't throw an error, and it returned only 500 records, but they still weren't the top 500; random records throughout were missing.  The same results as using slice().
 
I've read a lot in the forums about the sorting of FTSearch being a problem, but mine are sorting just fine.  I think I'll need to try the making-a-duplicate-array-and-slicing-that approach.
 
Apparently all the quirks with FTSearch are being fixed in 8.5.3.
 
THANKS for your help!
 
Sally

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal