zhouerla 发表于 2015-7-19 08:49:54

Solr 查询的最经典使用方法

import solr
# create a connection to a solr server
s = solr.SolrConnection('http://example.org:8083/solr')
# add a document to the index
doc = dict(
id=1,
title='Lucene in Action',
author=['Erik Hatcher', 'Otis Gospodnetić'],
)
s.add(doc, commit=True)
# do a search
response = s.query('title:lucene')
for hit in response.results:
print hit['title']
c = SolrConnection('http://localhost:8983/solr')
      #c.add(id='600', name='help python',inStock=True)
      #c.add(id='80',name= 'spring',)
      c.add(id='150',
            name='helloweb-sunday',
            manu='downloadfile-sunday',
            cat='/home/spring/pro/python/sunday',
            features='download web Contents',
            price='145',
            popularity='300',
            inStock=True,
            incubationdate_dt='2014-09-28T12:42:39Z')
      c.commit()
      #pdb.set_trace()
      #c.delete('502')
      response = c.query('id:150')
      for match in response.results:
            print match['id']
            if match['id'] !=0:
                return match['id']
            else :
                return "failed search"
      return "ok"
页: [1]
查看完整版本: Solr 查询的最经典使用方法