Ejemplo n.º 1
0
 def __init__(self, context, querier, p2pquerier):
     athena.LivePage.__init__(self)
     # NOTE: At the time this comment is written, athena/LivePages are handled
     #       differently in nevow SVN. It's now possible to insantiate directly
     #       LivePage instances (which is great !), so we'll have to change
     #       the implementation for next nevow release.
     self.querier = querier
     self.p2pquerier = p2pquerier
     self.query = Query.fromContext(context)
     self.offset = self.query.offset
     self.onlyLocal = False
     self.onlyDistant = False
     # push local results once for all
     if len(inevow.IRemainingSegments(context)) < 2:
         # only store abstracts in the results table
         results = []
         for localDoc in querier.findDocuments(self.query):
             localDoc.text = makeAbstract(localDoc.text, self.query.words)
             results.append(localDoc)
         webappConfig = INodeConfiguration(context)
         p2pQuery = P2pQuery(sender=webappConfig.get_node_id(),
                             query=self.query)
         self.qid = p2pQuery.qid
         self.p2pQuery = p2pQuery
         # purge old results
         self.querier.purgeOldResults()
         provider = (NODE_LOGIN, NODE_CONFIG.get_node_id(), 'localhost', 0)
         self.querier.pushDocuments(self.qid, results, provider)
         self.results = self.querier.getQueryResults(self.query)
Ejemplo n.º 2
0
 def setUp(self):
     self.querier = P2pQuerier('0'*40, None) 
     self.query = P2pQuery(sender='http://localhost:3423',
                           client_port=3423,
                           client_host='1.2.3.4',
                           ttl=2,
                           query=Query.fromRawQuery("foo"))
Ejemplo n.º 3
0
 def testTwoWordsRestrictedQueryAndOffset(self):
     query = Query.fromRawQuery(u"hello filetype:pdf world", 12)
     self.assertEquals(query.words, u"hello world")
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, "application/pdf")
     self.assertEquals(query.offset, 12)
Ejemplo n.º 4
0
 def testBasicQueryWithSeveralWords(self):
     query = Query.fromRawQuery(u"hello world")
     self.assertEquals(query.words, u"hello world")
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, None)
     self.assertEquals(query.offset, 0)
Ejemplo n.º 5
0
 def child_download(self, context):
     docid = context.arg('docid')
     query = Query.fromRawQuery(unicode(context.arg('words'), 'utf-8'))
     docurl = self.querier.notifyDownload(docid, query.words)
     if docurl:
         return static.File(docurl)
     else:
         return Maay404()
Ejemplo n.º 6
0
 def testTwoWordsRestrictedQueryAndOffset(self):
     query = Query.fromRawQuery(u"hello filetype:pdf world", 12)
     self.assertEquals(query.words, u"hello world")
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, 'application/pdf')
     self.assertEquals(query.offset, 12)
Ejemplo n.º 7
0
 def testOneWordRestrictedQuery(self):
     query = Query.fromRawQuery(u"hello filetype:pdf")
     self.assertEquals(query.words, u"hello")
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, 'application/pdf')
     self.assertEquals(query.offset, 0)
Ejemplo n.º 8
0
 def testBasicQueryWithSeveralWords(self):
     query = Query.fromRawQuery(u"hello world")
     self.assertEquals(query.words, u"hello world")
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, None)
     self.assertEquals(query.offset, 0)
Ejemplo n.º 9
0
 def child_download(self, context):
     docid = context.arg('docid')
     query = Query.fromRawQuery(unicode(context.arg('words'), 'utf-8'))
     docurl = self.querier.notifyDownload(docid, query.words)
     if docurl:
         return static.File(docurl)
     else:
         return Maay404()
Ejemplo n.º 10
0
 def testBasicQuery(self):
     query = Query.fromRawQuery(u"hello")
     self.assertEquals(query.words, [u"hello"])
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), list)
     self.assertEquals(type(query.words[0]), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, None)
     self.assertEquals(query.offset, 0)
Ejemplo n.º 11
0
 def testBasicQuery(self):
     query = Query.fromRawQuery(u"hello")
     self.assertEquals(query.words, [u"hello"])
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), list)
     self.assertEquals(type(query.words[0]), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, None)
     self.assertEquals(query.offset, 0)
Ejemplo n.º 12
0
 def testOneWordRestrictedQuery(self):
     query = Query.fromRawQuery(u"hello filetype:pdf")
     self.assertEquals(query.words, [u"hello"])
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), list)
     self.assertEquals(type(query.words[0]), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, 'application/pdf')
     self.assertEquals(query.offset, 0)
Ejemplo n.º 13
0
 def testTwoWordsRestrictedQuery(self):
     query = Query.fromRawQuery(u"hello filetype:pdf world")
     self.assertEquals(query.words, [u"hello", u"world"])
     # excplitly check for unicode-ness ('hello' == u'hello')
     self.assertEquals(type(query.words), list)
     self.assertEquals(type(query.words[0]), unicode)
     self.assertEquals(type(query.words[1]), unicode)
     self.assertEquals(query.filename, None)
     self.assertEquals(query.filetype, 'application/pdf')
     self.assertEquals(query.offset, 0)
Ejemplo n.º 14
0
 def testMimeTypeNormalization(self):
     query = Query.fromRawQuery(u"hello filetype:pdf world", 12)
     self.assertEquals(query.filetype, 'application/pdf')
     query.filetype = 'text/x-python'
     self.assertEquals(query.filetype, 'text/x-python')
     query.filetype = ''
     self.assertEquals(query.filetype, None)
     query.filetype = 'pdf'
     self.assertEquals(query.filetype, 'application/pdf')
     query.filetype = None
     self.assertEquals(query.filetype, None)
Ejemplo n.º 15
0
 def testMimeTypeNormalization(self):
     query = Query.fromRawQuery(u"hello filetype:pdf world", 12)
     self.assertEquals(query.filetype, 'application/pdf')
     query.filetype = 'text/x-python'
     self.assertEquals(query.filetype, 'text/x-python')
     query.filetype = ''
     self.assertEquals(query.filetype, None)
     query.filetype = 'pdf'
     self.assertEquals(query.filetype, 'application/pdf')
     query.filetype = None
     self.assertEquals(query.filetype, None)
Ejemplo n.º 16
0
    def child_search(self, context):
        # query = unicode(context.arg('words'))        
        offset = int(context.arg('offset', 0))
        words = context.arg('words')
        if not words:
            query = Query.fromRawQuery('')
            return FACTORY.getLivePage(context)
        rawQuery = unicode(context.arg('words'), 'utf-8')
        query = Query.fromRawQuery(rawQuery, offset)
        localResults = self.querier.findDocuments(query)
        # self._askForPeerResults(query, context)
        resultsPage = FACTORY.clientFactory(context, self.maayId, localResults, query, offset)
        #######################
        webappConfig = IServerConfiguration(context)
        p2pQuery = P2pQuery(webappConfig.get_node_id(),
                            webappConfig.rpcserver_port,
                            query)
        self.p2pquerier.sendQuery(p2pQuery)
        #######################

        self.p2pquerier.addAnswerCallback(p2pQuery.qid, resultsPage.onNewResults)
        return resultsPage
Ejemplo n.º 17
0
    def child_search(self, context):
        # query = unicode(context.arg('words'))
        offset = int(context.arg('offset', 0))
        words = context.arg('words')
        if not words:
            query = Query.fromRawQuery('')
            return FACTORY.getLivePage(context)
        rawQuery = unicode(context.arg('words'), 'utf-8')
        query = Query.fromRawQuery(rawQuery, offset)
        localResults = self.querier.findDocuments(query)
        # self._askForPeerResults(query, context)
        resultsPage = FACTORY.clientFactory(context, self.maayId, localResults,
                                            query, offset)
        #######################
        webappConfig = IServerConfiguration(context)
        p2pQuery = P2pQuery(webappConfig.get_node_id(),
                            webappConfig.rpcserver_port, query)
        self.p2pquerier.sendQuery(p2pQuery)
        #######################

        self.p2pquerier.addAnswerCallback(p2pQuery.qid,
                                          resultsPage.onNewResults)
        return resultsPage
Ejemplo n.º 18
0
 def testComplexQueryAsKwargs(self):
     query = P2pQuery(sender='http://localhost:3423',
                      port=3423,
                      ttl=2,
                      query=Query.fromRawQuery("foo bar filetype:pdf"),
                      qid=42)
     self.assertEquals(
         query.asKwargs(), {
             'qid': 42,
             'sender': 'http://localhost:3423',
             'port': 3423,
             'ttl': 2,
             'words': 'foo bar',
             'mime_type': 'application/pdf'
         })
Ejemplo n.º 19
0
 def testComplexQueryAsKwargs(self):
     query = P2pQuery(sender='http://localhost:3423',
                      client_port = 3423,
                      client_host = '1.2.3.4',
                      ttl=2,
                      query=Query.fromRawQuery("foo bar filetype:pdf"),
                      qid=42)
     self.assertEquals(query.asKwargs(),
                       {'qid' : 42,
                        'sender' : 'http://localhost:3423',
                        'client_port' : 3423,
                        'client_host' : '1.2.3.4',
                        'ttl' : 2,
                        'words' : [u'foo', u'bar'],
                        'version' : 2,
                        'mime_type' : 'application/pdf'})
Ejemplo n.º 20
0
 def fromDict(dic):
     """dual of asKwargs"""
     if not compatible(P2pQuery._version, dic['version']):
         print "******* Query Version Mismatch ********"
         print "(we don't understand queries version %s)" % dic['version']
         raise QueryVersionMismatch(query_version=dic['version'],
                                    local_version=P2pQuery._version)
     _query = Query(' '.join(dic['words']),
                    filetype=dic['mime_type'],
                    qid=dic['qid'])
     p2pquery = P2pQuery(sender=dic['sender'],
                         client_host=dic['client_host'],
                         client_port=dic['client_port'],
                         ttl=dic['ttl'],
                         query=_query)
     return p2pquery
Ejemplo n.º 21
0
 def xmlrpc_distributedQuery(self, queryDict):
     """On node has sent a query (P2pQuerier.sendQuery)
     """
     print "MaayRPCServer distributedQuery : %s " % queryDict
     query = P2pQuery(sender=queryDict['sender'],
                      port=queryDict['port'],
                      query=Query(queryDict['words'],
                                  filetype=queryDict['mime_type']),
                      ttl=queryDict['ttl'],
                      qid=queryDict['qid'],
                      host = self._lastClient.host)
     querier = self._sessions[ANONYMOUS_AVATARID]
     querier.registerNode(query.sender, query.host, query.port)
     # schedule the query for later processing and return immediately
     # this enables the sender to query several nodes in a row
     d = reactor.callLater(.01, self.getP2pQuerier().receiveQuery, query)
     return self.nodeId
Ejemplo n.º 22
0
 def setUp(self):
     self.query = P2pQuery(sender='http://localhost:3423', # a hash in real life
                           client_port=3423,
                           client_host='1.2.3.4',
                           query=Query.fromRawQuery("foo"),
                           qid=42)
Ejemplo n.º 23
0
 def setUp(self):
     self.query = P2pQuery(
         sender='http://localhost:3423',  # should be a hash (auc)
         port=3423,
         query=Query.fromRawQuery("foo"),
         qid=42)