當前位置: 首頁>>代碼示例>>Python>>正文


Python search.Search類代碼示例

本文整理匯總了Python中collective.solr.search.Search的典型用法代碼示例。如果您正苦於以下問題:Python Search類的具體用法?Python Search怎麽用?Python Search使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Search類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SearchTests

class SearchTests(TestCase):

    def setUp(self):
        provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
        self.mngr = SolrConnectionManager()
        self.mngr.setHost(active=True)
        self.conn = self.mngr.getConnection()
        self.search = Search()
        self.search.manager = self.mngr

    def tearDown(self):
        self.mngr.closeConnection()
        self.mngr.setHost(active=False)

    def testSimpleSearch(self):
        schema = getData('schema.xml')
        search = getData('search_response.txt')
        request = getData('search_request.txt')
        output = fakehttp(self.conn, schema, search)    # fake responses
        query = self.search.buildQuery(id='[* TO *]')
        results = self.search(query, rows=10, wt='xml', indent='on').results()
        normalize = lambda x: sorted(x.split('&'))      # sort request params
        self.assertEqual(normalize(output.get(skip=1)), normalize(request))
        self.assertEqual(results.numFound, '1')
        self.assertEqual(len(results), 1)
        match = results[0]
        self.assertEqual(match.id, '500')
        self.assertEqual(match.name, 'python test doc')
        self.assertEqual(match.popularity, 0)
        self.assertEqual(match.sku, '500')
        self.assertEqual(match.timestamp,
            DateTime('2008-02-29 16:11:46.998 GMT'))
開發者ID:andrgrau,項目名稱:collective.solr,代碼行數:32,代碼來源:test_query.py

示例2: setUp

 def setUp(self):
     provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
     self.mngr = SolrConnectionManager()
     self.mngr.setHost(active=True)
     self.conn = self.mngr.getConnection()
     self.search = Search()
     self.search.manager = self.mngr
開發者ID:andrgrau,項目名稱:collective.solr,代碼行數:7,代碼來源:test_query.py

示例3: setUp

 def setUp(self):
     self.mngr = SolrConnectionManager()
     self.mngr.setHost(active=True)
     conn = self.mngr.getConnection()
     fakehttp(conn, getData('schema.xml'))   # fake schema response
     self.mngr.getSchema()                   # read and cache the schema
     self.search = Search()
     self.search.manager = self.mngr
開發者ID:FHNW,項目名稱:collective.solr,代碼行數:8,代碼來源:test_query.py

示例4: setUp

    def setUp(self):
        provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
        self.mngr = SolrConnectionManager()
        self.mngr.setHost(active=True)
        conn = self.mngr.getConnection()
        fakehttp(conn, getData('plone_schema.xml')) # fake schema response
        self.mngr.getSchema()                       # read and cache the schema
        self.search = Search()
        self.search.manager = self.mngr

        # Patch buildQuery method
        self.search.buildQuery = buildQuery.__get__(self.search,
                                                    self.search.__class__)
開發者ID:jean,項目名稱:ftw.solr,代碼行數:13,代碼來源:test_query.py

示例5: testUnavailableSchema

 def testUnavailableSchema(self):
     provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
     search = Search()
     search.manager = SolrConnectionManager()
     self.assertEqual(search.buildQuery('foo'), {})
     self.assertEqual(search.buildQuery(name='foo'), {})
開發者ID:andrgrau,項目名稱:collective.solr,代碼行數:6,代碼來源:test_query.py

示例6: QueryTests

class QueryTests(TestCase):

    def setUp(self):
        provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
        self.mngr = SolrConnectionManager()
        self.mngr.setHost(active=True)
        conn = self.mngr.getConnection()
        fakehttp(conn, getData('schema.xml'))   # fake schema response
        self.mngr.getSchema()                   # read and cache the schema
        self.search = Search()
        self.search.manager = self.mngr

    def tearDown(self):
        self.mngr.closeConnection()
        self.mngr.setHost(active=False)

    def bq(self, *args, **kw):
        query = self.search.buildQuery(*args, **kw)
        return ' '.join(sorted(query.values()))

    def testSimpleQueries(self):
        bq = self.bq
        self.assertEqual(bq('foo'), '+foo')
        self.assertEqual(bq('foo*'), '+foo*')
        self.assertEqual(bq('foo!'), '+foo\\!')
        self.assertEqual(bq('(foo)'), '+foo')
        self.assertEqual(bq('(foo...'), '+foo...')
        self.assertEqual(bq('foo bar'), '+(foo bar)')
        self.assertEqual(bq('[email protected]'), '[email protected]')
        self.assertEqual(bq(name='foo'), '+name:foo')
        self.assertEqual(bq(name='foo*'), '+name:foo*')
        self.assertEqual(bq(name='foo bar'), '+name:(foo bar)')
        self.assertEqual(bq(name='[email protected]'), '+name:[email protected]')
        self.assertEqual(bq(name=' '), '') # Whitespace is removed
        self.assertEqual(bq(name=''), '')

    def testMultiValueQueries(self):
        bq = self.bq
        self.assertEqual(bq(('foo', 'bar')), '+(foo OR bar)')
        self.assertEqual(bq(('foo', 'bar*')), '+(foo OR bar*)')
        self.assertEqual(bq(('foo bar', 'hmm')), '+("foo bar" OR hmm)')
        self.assertEqual(bq(('foø bar', 'hmm')), '+("fo\xc3\xb8 bar" OR hmm)')
        self.assertEqual(bq(('"foo bar"', 'hmm')), '+("foo bar" OR hmm)')
        self.assertEqual(bq(name=['foo', 'bar']), '+name:(foo OR bar)')
        self.assertEqual(bq(name=['foo', 'bar*']), '+name:(foo OR bar*)')
        self.assertEqual(bq(name=['foo bar', 'hmm']), '+name:("foo bar" OR hmm)')

    def testMultiArgumentQueries(self):
        bq = self.bq
        self.assertEqual(bq('foo', name='bar'), '+foo +name:bar')
        self.assertEqual(bq('foo', name=('bar', 'hmm')),
            '+foo +name:(bar OR hmm)')
        self.assertEqual(bq('foo', name=('foo bar', 'hmm')),
            '+foo +name:("foo bar" OR hmm)')
        self.assertEqual(bq(name='foo', cat='bar'), '+cat:bar +name:foo')
        self.assertEqual(bq(name='foo', cat=['bar', 'hmm']),
            '+cat:(bar OR hmm) +name:foo')
        self.assertEqual(bq(name='foo', cat=['foo bar', 'hmm']),
            '+cat:("foo bar" OR hmm) +name:foo')
        self.assertEqual(bq('foo', name=' '), '+foo')

        # empty value for a name should return no results like in ZCatalog, so
        # empty query is returned
        self.assertEqual(bq('foo', name=''), '')

    def testInvalidArguments(self):
        bq = self.bq
        self.assertEqual(bq(title='foo'), '')
        self.assertEqual(bq(title='foo', name='bar'), '+name:bar')
        self.assertEqual(bq('bar', title='foo'), '+bar')

    def testUnicodeArguments(self):
        bq = self.bq
        self.assertEqual(bq(u'foo'), '+foo')
        self.assertEqual(bq(u'foø'), '+fo\xc3\xb8')
        self.assertEqual(bq(u'[email protected]'), '[email protected]')
        self.assertEqual(bq(name=['foo', u'bar']), '+name:(foo OR bar)')
        self.assertEqual(bq(name=['foo', u'bär']), '+name:(foo OR b\xc3\xa4r)')
        self.assertEqual(bq(name='foo', cat=(u'bar', 'hmm')), '+cat:(bar OR hmm) +name:foo')
        self.assertEqual(bq(name='foo', cat=(u'bär', 'hmm')), '+cat:(b\xc3\xa4r OR hmm) +name:foo')
        self.assertEqual(bq(name=u'[email protected]', cat='spammer'), '+cat:spammer +name:[email protected]')

    def testQuotedQueries(self):
        bq = self.bq
        self.assertEqual(bq('"foo"'), '+"foo"')
        self.assertEqual(bq('foo'), '+foo')
        self.assertEqual(bq('"foo*"'), '+"foo\*"')
        self.assertEqual(bq('foo*'), '+foo*')
        self.assertEqual(bq('"+foo"'), '+"\+foo"')
        self.assertEqual(bq('+foo'), '+foo')
        self.assertEqual(bq('"foo bar"'), '+"foo bar"')
        self.assertEqual(bq('foo bar'), '+(foo bar)')
        self.assertEqual(bq('"foo bar?"'), '+"foo bar\?"')
        self.assertEqual(bq('foo bar?'), '+(foo bar?)')
        self.assertEqual(bq('-foo +bar'), '+(-foo +bar)')
        self.assertEqual(bq('"-foo +bar"'), '+"\-foo \+bar"')
        self.assertEqual(bq('foo-bar'), '+"foo\\-bar"')
        self.assertEqual(bq('"foo-bar"'), '+"foo\-bar"')
        self.assertEqual(bq(name='"foo"'), '+name:"foo"')
        self.assertEqual(bq(name='"foo bar'), '+name:(\\"foo bar)')
#.........這裏部分代碼省略.........
開發者ID:andrgrau,項目名稱:collective.solr,代碼行數:101,代碼來源:test_query.py

示例7: testUnavailableSchema

 def testUnavailableSchema(self):
     search = Search()
     search.manager = SolrConnectionManager()
     self.assertEqual(search.buildQueryAndParameters('foo'), ({}, {}))
     self.assertEqual(search.buildQueryAndParameters(name='foo'), ({}, {}))
開發者ID:FHNW,項目名稱:collective.solr,代碼行數:5,代碼來源:test_query.py


注:本文中的collective.solr.search.Search類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。