示例#1
0
 def test_get_connection(self):
     conn = solr.get_connection()
     conn = solr.get_connection()
     self.mock_solr.assert_called_once_with('http://localhost:8983/solr',
                                            http_user=None,
                                            http_pass=None)
     assert conn == self.mock_solr.return_value
 def test_get_connection(self):
     conn = solr.get_connection()
     conn = solr.get_connection()
     self.mock_solr.assert_called_once_with(
         'http://localhost:8983/solr',
         http_user=None,
         http_pass=None)
     assert conn == self.mock_solr.return_value
示例#3
0
    def setup(self):
        h.skip_if_stubbed_solr()

        super(TestSearch, self).setup()
        h.load_fixture('cra')

        ourdict = {'_id': 'myspecialid', 'cofog1_ws': 'foobar'}

        self.solr = solr.get_connection()
        self.solr.add(**ourdict)
        self.solr.commit()

        solr.build_index(dataset_name='cra')
示例#4
0
文件: api.py 项目: rgrp/openspending
 def search(self):
     solrargs = dict(request.params)
     rows = min(1000, request.params.get('rows', 10))
     q = request.params.get('q', '*:*')
     solrargs['q'] = amend_query(q)
     solrargs['rows'] = rows
     solrargs['wt'] = 'json'
     if 'callback' in solrargs and not 'json.wrf' in solrargs:
         solrargs['json.wrf'] = solrargs['callback']
     if not 'sort' in solrargs:
         solrargs['sort'] = 'score desc,amount desc'
     query = solr.get_connection().raw_query(**solrargs)
     response.content_type = 'application/json'
     return query
示例#5
0
    def setup(self):
        h.skip_if_stubbed_solr()

        super(TestSearch, self).setup()
        h.load_fixture('cra')

        ourdict = {
            '_id': 'myspecialid',
            'cofog1_ws': 'foobar'
        }

        self.solr = solr.get_connection()
        self.solr.add(**ourdict)
        self.solr.commit()

        solr.build_index(dataset_name='cra')
示例#6
0
    def search(self):
        solrargs = dict(request.params)
        rows = min(1000, int(request.params.get('rows', 10)))
        q = request.params.get('q', '*:*')
        solrargs['q'] = q
        solrargs['rows'] = rows
        solrargs['wt'] = 'json'

        datasets = model.Dataset.all_by_account(c.account)
        fq = ' OR '.join(map(lambda d: '+dataset:"%s"' % d.name, datasets))
        solrargs['fq'] = '(%s)' % fq

        if 'callback' in solrargs and not 'json.wrf' in solrargs:
            solrargs['json.wrf'] = solrargs['callback']
        if not 'sort' in solrargs:
            solrargs['sort'] = 'score desc,amount desc'
        try:
            query = solr.get_connection().raw_query(**solrargs)
        except solr.SolrException, se:
            response.status_int = se.httpcode
            return se.body
示例#7
0
    def search(self):
        solrargs = dict(request.params)
        rows = min(1000, int(request.params.get('rows', 10)))
        q = request.params.get('q', '*:*')
        solrargs['q'] = q
        solrargs['rows'] = rows
        solrargs['wt'] = 'json'

        datasets = model.Dataset.all_by_account(c.account)
        fq =  ' OR '.join(map(lambda d: '+dataset:"%s"' % d.name, datasets))
        solrargs['fq'] = '(%s)' % fq

        if 'callback' in solrargs and not 'json.wrf' in solrargs:
            solrargs['json.wrf'] = solrargs['callback']
        if not 'sort' in solrargs:
            solrargs['sort'] = 'score desc,amount desc'
        try:
            query = solr.get_connection().raw_query(**solrargs)
        except solr.SolrException, se:
            response.status_int = se.httpcode
            return se.body
示例#8
0
    def command(self):
        super(SolrCommand, self).command()

        if len(self.args) < 1:
            SolrCommand.parser.print_help()
            return 1

        cmd = self.args[0]

        from openspending.lib import solr_util as solr

        if cmd == 'load':
            solr.build_index(self.args[1])
        elif cmd == 'delete':
            solr.drop_index(self.args[1])
        elif cmd == 'optimize':
            solr.optimize()
        elif cmd == 'clean':
            s = solr.get_connection()
            s.delete_query('*:*')
            s.commit()
        else:
            raise self.BadCommand("Subcommand '%s' not recognized " \
                                  "by 'solr' command!" % cmd)
示例#9
0
def skip_if_stubbed_solr():
    if type(_solr.get_connection()) == _solr._Stub:
        skip("Not running test with stubbed Solr.")
示例#10
0
def clean_solr():
    '''Clean all entries from Solr.'''
    s = _solr.get_connection()
    s.delete_query('*:*')
    s.commit()
示例#11
0
def clean():
    s = solr.get_connection()
    s.delete_query('*:*')
    s.commit()
    return 0
示例#12
0
def clean_solr():
    '''Clean all entries from Solr.'''
    s = solr.get_connection()
    s.delete_query('*:*')
    s.commit()
示例#13
0
 def query(self):
     data = solr.get_connection().raw_query(**_build_query(self.params))
     return json.loads(data)
示例#14
0
def skip_if_stubbed_solr():
    from openspending.lib.solr_util import get_connection, _Stub
    if type(get_connection()) == _Stub:
        skip("Not running test with stubbed Solr.")
示例#15
0
 def query(self):
     data = solr.get_connection().raw_query(**_build_query(self.params))
     return json.loads(data)
示例#16
0
def optimize():
    solr.get_connection().optimize()
    return 0
示例#17
0
def clean_solr():
    """Clean all entries from Solr."""
    s = solr.get_connection()
    s.delete_query("*:*")
    s.commit()
示例#18
0
 def _query(self, **kwargs):
     kwargs.update({'wt': 'json'})
     data = solr.get_connection().raw_query(**kwargs)
     return json.loads(data)
示例#19
0
def optimize():
    solr.get_connection().optimize()
    return 0
示例#20
0
def clean():
    s = solr.get_connection()
    s.delete_query('*:*')
    s.commit()
    return 0
示例#21
0
def skip_if_stubbed_solr():
    if type(_solr.get_connection()) == _solr._Stub:
        skip("Not running test with stubbed Solr.")
示例#22
0
 def _query(self, **kwargs):
     kwargs.update({'wt': 'json'})
     data = solr.get_connection().raw_query(**kwargs)
     return json.loads(data)
示例#23
0
def clean_solr():
    '''Clean all entries from Solr.'''
    from openspending.lib.solr_util import get_connection
    solr = get_connection()
    solr.delete_query('*:*')
    solr.commit()