Ignore:
Timestamp:
06/02/07 17:22:18 (13 years ago)
Author:
lawrence
Message:

This should fix the error reported in ticket:641 and Andrew's email (crash on era).
Will be uploaded on glue to test shortly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgSearch.py

    r2097 r2113  
    8686            self.serverSessionID=response._resultId 
    8787            self.hits=response.Hits 
    88             self.documents=response._documents 
     88            self.documents=response.Documents.Document 
    8989        else: 
    9090            self.hits=response.Hits 
     
    9898        #create a request object 
    9999        request=doPresentRequest() 
    100         request._documents=[document,] 
    101         request._format='original' 
    102         try: 
    103             searchResult=self.server.doPresent(request) 
    104         except Exception,e: 
    105             raise Exception,e 
     100        #get an instance of the Documents holder class 
     101        DocList=request.new_documents() 
     102        request.Documents=DocList 
     103        DocList.Document=[document,] 
     104        request.Format='original' 
     105        #try: 
     106        searchResult=self.server.doPresent(request) 
     107        #except Exception,e: 
     108        #   raise Exception,e 
    106109        if searchResult._status: 
    107             result=searchResult._documents[0] 
     110            result=searchResult.Documents.Document[0] 
    108111        else: 
    109112            result=searchResult._statusMessage 
     
    112115    def getAllDocs(self,format='original'):             
    113116        ''' Parse the list of documents, and retrieve them directly ''' 
    114         docs=[] 
    115         self.status=[] 
    116          
    117         if self.documents is None: return [] 
    118          
     117         
     118        if self.documents is None: return [] 
     119        if self.logger: itime=time.time() 
     120          
    119121        #create a request object 
    120122        request=doPresentRequest() 
    121         if self.logger: itime=time.time() 
    122          
    123         request.Documents=self.documents 
     123        #get an instance of the Documents holder class 
     124        DocList=request.new_documents() 
     125        request.Documents=DocList 
     126        DocList.Document=self.documents 
    124127        request.Format=format 
    125         result=self.server.doPresent(request)     
     128         
     129        result=self.server.doPresent(request) 
    126130        if result._status: 
    127             docs=result._documents._document 
    128          
     131            docs=result.Documents.Document 
     132        else: 
     133            docs=[] 
     134         
    129135        if self.logger: 
    130136            etime=time.time()-itime 
    131137            self.logger.info('Document Load [n=%s] took [%ss]'%(len(self.documents._document),etime)) 
    132         #self.docs=docs 
    133         #return self.docs 
    134         #removed self.docs reference Jan 31st, can't see why we had it ... 
    135         #nb returning a complete copy of the list didn't fix the problems with repeated calls 
     138 
    136139        return docs 
    137140             
     
    175178        #so we know that the following call is the problem ... 
    176179        responses=self.getAllDocs(format) 
    177         filenames=self.documents.Document 
     180        filenames=self.documents 
    178181        i=len(filenames) 
    179182        j=len(responses) 
     
    194197        ''' Test fundamental search capability ''' 
    195198        term='temperature' 
    196         s=ndgSearch(tracefile) 
     199        s=ndgSearch() 
    197200        howmany=10 
    198201        docs=s.search(term,start=1,howmany=howmany) 
    199202        print 'Asked for ',howmany,' documents (there were %s hits):'%s.hits 
    200         print s.documents.Document 
     203        print s.documents 
    201204        
    202205    def testgetLabelledDocs(self): 
    203206        ''' Test returning of labelled documents ''' 
    204         term='neodc' 
     207        term='CD97' 
    205208        s=ndgSearch() 
    206209        r=s.search(term) 
    207210        print s.status 
     211        print s.documents 
    208212        output=s.getLabelledDocs() 
    209213         
     
    216220        output=s.getLabelledDocs() 
    217221        self.assertEqual(len(output),0) 
     222         
     223    def testGetDoc(self): 
     224        ''' Test obtaining a specific document which had better exist ''' 
     225        doc='noc.soton.ac.uk__DIF__NOCSDAT100.xml' 
     226        s=ndgSearch() 
     227        r=s.getDoc(doc) 
    218228         
    219229    def testSequence(self): 
    220230        ''' Tests that repeated searches work and can support zero responses in the middle ''' 
    221231        # this was a bug we found and needed a test case for 
    222         s=ndgSearch(tracefile=sys.stdout) 
    223         term='neodc' 
     232        s=ndgSearch() 
     233        term='CD97' # hopefully just get a couple of hits for now. 
    224234        r=s.search(term) 
    225235        print s.hits 
    226         #if we uncomment this it breaks, if not it doesn't ... 
    227         #output=s.getLabelledDocs()  
    228         #this fails as well, and we've isolated the dependency in the previous call to 
    229         #be on this one: 
    230         res=s.getAllDocs() 
    231         #del(output) doesn't work ... 
     236        #if we uncomment this it used to break, and not if uncommented, now it seems ok... 
     237        output=s.getLabelledDocs()  
     238        #this failed as well, and we isolated the dependency in the previous call to this one. 
     239        #res=s.getAllDocs() 
    232240        term='xpabnl' 
    233241        r=s.search(term) 
    234242        print s.hits 
    235243        print 'Hopefully this is also zero: if not, expect the Sequence test to fail:',s.hits 
    236         #output=s.getLabelledDocs() 
    237         #self.assertEqual(len(output),0) 
     244 
    238245         
    239246 
Note: See TracChangeset for help on using the changeset viewer.