本文整理汇总了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'))
示例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
示例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
示例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__)
示例5: testUnavailableSchema
def testUnavailableSchema(self):
provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
search = Search()
search.manager = SolrConnectionManager()
self.assertEqual(search.buildQuery('foo'), {})
self.assertEqual(search.buildQuery(name='foo'), {})
示例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)')
#.........这里部分代码省略.........
示例7: testUnavailableSchema
def testUnavailableSchema(self):
search = Search()
search.manager = SolrConnectionManager()
self.assertEqual(search.buildQueryAndParameters('foo'), ({}, {}))
self.assertEqual(search.buildQueryAndParameters(name='foo'), ({}, {}))