当前位置: 首页>>代码示例>>Python>>正文


Python SolrConnection.select方法代码示例

本文整理汇总了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')
开发者ID:airjukebox,项目名称:airjukebox-server,代码行数:44,代码来源:playback.py

示例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
开发者ID:airjukebox,项目名称:airjukebox-server,代码行数:16,代码来源:requests.py

示例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)
开发者ID:airjukebox,项目名称:airjukebox-server,代码行数:21,代码来源:channels.py

示例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")
开发者ID:airjukebox,项目名称:airjukebox-server,代码行数:22,代码来源:channels.py

示例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')
开发者ID:airjukebox,项目名称:airjukebox-server,代码行数:64,代码来源:requests.py


注:本文中的solr.SolrConnection.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。