本文整理汇总了Python中solr.SolrConnection.select方法的典型用法代码示例。如果您正苦于以下问题:Python SolrConnection.select方法的具体用法?Python SolrConnection.select怎么用?Python SolrConnection.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solr.SolrConnection
的用法示例。
在下文中一共展示了SolrConnection.select方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import select [as 别名]
def index(self):
# Build up a Solr query
filters = []
filters.append('type:request')
filters.append('channel_id:%s' % self.channel_id)
# Make the request to Solr
solr = SolrConnection(settings.SOLR_URL)
response = solr.select(q = ' AND '.join(filters), rows = 0, fields = '', facet = 'true', facet_field = 'request_track_id', facet_mincount = 1, facet_limit = 10, facet_sort = 'count')
results = []
for track_id in response.facet_counts['facet_fields']['request_track_id'].keys():
source_id = 'grooveshark'
# Build up a Solr query
filters = []
filters.append('type:track')
filters.append('request_source_id:%s' % source_id)
filters.append('request_track_id:%s' % track_id)
# Make the request to Solr
track_response = solr.select(q = ' AND '.join(filters), fields = 'track_artist, track_album, track_title')
if len(track_response.results) == 1:
results.append({
'track_artist': track_response.results[0]['track_artist'],
'track_album': track_response.results[0]['track_album'],
'track_title': track_response.results[0]['track_title'],
'request_source_id': source_id,
'request_track_id': track_id,
'votes': response.facet_counts['facet_fields']['request_track_id'][track_id],
})
results = sorted(results, key = lambda result : -result['votes'])
cherrypy.response.headers['Content-Type'] = 'application/json; charset=utf-8'
return json.dumps({'playlist': results}, ensure_ascii=False, indent=4).encode('utf-8')
示例2: __init__
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import select [as 别名]
def __init__(self, channel_id):
self.channel_id = channel_id
# Build up a Solr query
filters = []
filters.append('type:request')
filters.append('channel_id:%s' % channel_id)
# Make the request to Solr
solr = SolrConnection(settings.SOLR_URL)
response = solr.select(q = ' AND '.join(filters), rows = 10, fields = 'datetime, id', sort = 'datetime', sort_order = 'asc')
self.requests = response.results
示例3: __init__
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import select [as 别名]
def __init__(self):
# Build up a Solr query
filters = []
filters.append("type:channel")
# Make the request to Solr
solr = SolrConnection(settings.SOLR_URL)
response = solr.select(
q=" AND ".join(filters), rows=10, fields="datetime, channel_id", sort="channel_id", sort_order="asc"
)
# Restore the persisted channels
for doc in response.results:
channel_id = doc["channel_id"]
# Create the channel in the URL hierarchy
self.__dict__[channel_id] = ChannelResource.Channel(channel_id)
示例4: search
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import select [as 别名]
def search(self, **kwargs):
# Extract the search parameters
pos = kwargs["pos"]
# Build up a Solr query
filters = []
filters.append("type:channel")
filters.append("{!geofilt pt=%s sfield=channel_location d=0.1}" % pos)
# Make the request to Solr
solr = SolrConnection(settings.SOLR_URL)
response = solr.select(
q=" AND ".join(filters), rows=10, fields="datetime, channel_id", sort="channel_id", sort_order="asc"
)
cherrypy.response.headers["Content-Type"] = "application/json; charset=utf-8"
return json.dumps(
[{"channel": {"name": doc["channel_id"]}} for doc in response.results], ensure_ascii=False, indent=4
).encode("utf-8")
示例5: submit
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import select [as 别名]
def submit(self, **kwargs):
# Grab the user and request details
json_data = json.loads(kwargs['json'])
user_id = json_data['userid']
channel_id = self.channel_id
requests = json_data['requests']
# Create a local representation of the requests
tracks = []
for request in requests:
source_id = request['sourceid']
track_id = request['trackid']
# Build up a Solr query
filters = []
filters.append('type:track')
filters.append('request_source_id:%s' % source_id)
filters.append('request_track_id:%s' % track_id)
# Make the request to Solr
solr = SolrConnection(settings.SOLR_URL)
response = solr.select(q = ' AND '.join(filters), fields = 'track_artist, track_album, track_title')
if len(response.results) == 1:
track = {
'id': 'request_%s_%s_%s' % (source_id, track_id, user_id),
'type': 'request',
'channel_id': channel_id,
'track_artist': response.results[0]['track_artist'],
'track_album': response.results[0]['track_album'],
'track_title': response.results[0]['track_title'],
'request_user_id': user_id,
'request_source_id': source_id,
'request_track_id': track_id
}
tracks.append(track)
# Create the request in the search engine
solr = SolrConnection(settings.SOLR_URL)
solr.add_many(tracks)
solr.commit()
solr.close()
# Log the request to the database
db = psycopg2.connect(database='airjukebox')
cr = db.cursor()
for track in tracks:
cr.execute('insert into tbrequests (userid, locationid, sourceid, trackid) values (%(request_user_id)s, %(channel_id)s, %(request_source_id)s, %(request_track_id)s)', track)
db.commit()
cherrypy.response.headers['Content-Type'] = 'application/json; charset=utf-8'
return json.dumps(tracks, ensure_ascii=False, indent=4).encode('utf-8')