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


Python SolrClient.query方法代碼示例

本文整理匯總了Python中SolrClient.SolrClient.query方法的典型用法代碼示例。如果您正苦於以下問題:Python SolrClient.query方法的具體用法?Python SolrClient.query怎麽用?Python SolrClient.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SolrClient.SolrClient的用法示例。


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

示例1: test_solr_to_solr_reindex_and_resume_reverse

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_solr_to_solr_reindex_and_resume_reverse(self):
     """
     Only reindexes half of the collection on the first time. Then goes back and does a resume to make sure it works. 
     """
     self._index_docs(50000, self.colls[0])
     solr = SolrClient(test_config["SOLR_SERVER"][0], auth=test_config["SOLR_CREDENTIALS"])
     reindexer = Reindexer(
         source=solr, source_coll="source_coll", dest=solr, dest_coll="dest_coll", date_field="date"
     )
     # Make sure only source has data
     self.assertEqual(len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs), 50000)
     self.assertEqual(len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs), 0)
     # This gets somehwat of a mid point date in the range.
     midpoint = datetime.datetime.now() - datetime.timedelta(days=((self._end_date - self._start_date).days / 2))
     # Reindex approximately half of the data by restricting FQ
     reindexer.reindex(fq=["date:[{} TO *]".format(midpoint.isoformat() + "Z")])
     sleep(10)
     # Make sure we have at least 20% of the data.
     dest_count = len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs)
     s_count = len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs)
     self.assertTrue(s_count > dest_count > s_count * 0.20)
     reindexer.resume()
     sleep(10)
     # Make sure countc match up after reindex
     self.assertEqual(
         len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs),
         len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs),
     )
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:30,代碼來源:test_reindexer.py

示例2: test_solr_to_solr_reindexer_per_shard

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_solr_to_solr_reindexer_per_shard(self):
     self._index_docs(50000, self.colls[0])
     solr = SolrClient(test_config["SOLR_SERVER"][0], auth=test_config["SOLR_CREDENTIALS"])
     reindexer = Reindexer(
         source=solr, source_coll="source_coll", dest=solr, dest_coll="dest_coll", per_shard=True, date_field="date"
     )
     # Make sure only source has data
     self.assertEqual(len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs), 50000)
     self.assertEqual(len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs), 0)
     reindexer.reindex()
     # sloppy check over here, will improve later
     self.assertEqual(
         len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs),
         len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs),
     )
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:17,代碼來源:test_reindexer.py

示例3: test_solr_to_solr_resume_checkonly

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_solr_to_solr_resume_checkonly(self):
     """
     Checks the date_range_query generation function. Since it's pretty simple, running all the tests as one
     """
     self._index_docs(50000, self.colls[0])
     solr = SolrClient(test_config["SOLR_SERVER"][0], devel=True, auth=test_config["SOLR_CREDENTIALS"])
     reindexer = Reindexer(
         source=solr, source_coll="source_coll", dest=solr, dest_coll="dest_coll", date_field="date"
     )
     # Make sure only source has data
     self.assertEqual(len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs), 50000)
     self.assertEqual(len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs), 0)
     reindexer.resume(check=True)
     # Makes sure nothing got indexed
     self.assertEqual(len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs), 50000)
     self.assertEqual(len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs), 0)
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:18,代碼來源:test_reindexer.py

示例4: test_solr_to_solr_resume_basic

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_solr_to_solr_resume_basic(self):
     """
     Checks the date_range_query generation function. Since it's pretty simple, running all the tests as one
     """
     self._index_docs(50000, self.colls[0])
     solr = SolrClient(test_config["SOLR_SERVER"][0], auth=test_config["SOLR_CREDENTIALS"])
     reindexer = Reindexer(
         source=solr, source_coll="source_coll", dest=solr, dest_coll="dest_coll", date_field="date"
     )
     # Make sure only source has datae
     self.assertEqual(len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs), 50000)
     self.assertEqual(len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs), 0)
     reindexer.resume()
     sleep(10)
     # Make sure countc match up after reindex
     self.assertEqual(
         len(solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs),
         len(solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs),
     )
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:21,代碼來源:test_reindexer.py

示例5: read_all

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
def read_all():

    client = SolrClient('http://localhost:8983/solr')

    res = client.query('test', {
        'q' : '*:*'
    })

    res = json.loads(res.get_json())
    docs = res['response']['docs']

    for doc in docs:
        print (doc)
開發者ID:ZackBotkin,項目名稱:stock-project,代碼行數:15,代碼來源:indexer.py

示例6: test_index_multiproc

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_index_multiproc(self):
     index = IndexQ(test_config['indexqbase'], 'testq')
     solr = SolrClient(test_config['SOLR_SERVER'], devel=True, auth=test_config['SOLR_CREDENTIALS'])
     solr.delete_doc_by_id(test_config['SOLR_COLLECTION'],'*')
     buff = []
     files = []
     for doc in self.docs:
         files.append(index.add(doc, finalize=True))
     index.index(solr,test_config['SOLR_COLLECTION'],threads=10)
     solr.commit(test_config['SOLR_COLLECTION'],openSearcher=True)
     for doc in self.docs:
         res = solr.query(test_config['SOLR_COLLECTION'],{'q':'id:{}'.format(doc['id'])})
         self.assertTrue(res.get_results_count()==1)
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:15,代碼來源:test_indexq.py

示例7: test_solr_to_solr_with_date

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_solr_to_solr_with_date(self):
     self._index_docs(50000, self.colls[0])
     solr = SolrClient(test_config["SOLR_SERVER"][0], devel=True, auth=test_config["SOLR_CREDENTIALS"])
     reindexer = Reindexer(
         source=solr, source_coll="source_coll", dest=solr, dest_coll="dest_coll", date_field="index_date"
     )
     reindexer.reindex()
     try:
         self.assertTrue(solr.transport._action_log[1]["params"]["params"]["sort"] == "index_date asc, id desc")
     except KeyError:
         self.assertTrue(solr.transport._action_log[2]["params"]["params"]["sort"] == "index_date asc, id desc")
     self.assertEqual(
         solr.query(self.colls[0], {"q": "*:*", "rows": 10000000}).docs.sort(key=lambda x: x["id"]),
         solr.query(self.colls[1], {"q": "*:*", "rows": 10000000}).docs.sort(key=lambda x: x["id"]),
     )
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:17,代碼來源:test_reindexer.py

示例8: computeScores1

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
def computeScores1(type, query, output_file):
    solr = SolrClient('http://localhost:8983/solr')

    res = solr.query(query['index'], {
        'q': '*:*',
        'wt': 'json',
        'indent': True,
        'rows': 1000,
    })

    docs = res.data['response']['docs']

    with open(output_file, "wb") as outF:
        a = csv.writer(outF, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
        a.writerow(["type", "x-coordinate", "y-coordinate", "Similarity_score"])

        for doc in docs:
            for key in doc:
                if key in ["id", "_version_"]:
                    continue
                try:
                    doc[key] = doc[key][0].encode("ascii", "ignore")
                except:
                    doc[key] = str(doc[key][0]).decode("unicode_escape").encode("ascii", "ignore")

        doc_tuples = itertools.combinations(docs, 2)
        for raw1, raw2 in doc_tuples:

            doc1 = raw1.copy()
            doc2 = raw2.copy()

            if "Name" in doc1:
                row_cosine_distance = [type, doc1["Name"], doc2["Name"]]
            else:
                row_cosine_distance = [type, doc1["name"], doc2["name"]]

            v1 = Vector(row_cosine_distance[0], doc1)
            v2 = Vector(row_cosine_distance[1], doc2)

            row_cosine_distance.append(v1.cosTheta(v2))

            a.writerow(row_cosine_distance)
開發者ID:jdramani,項目名稱:599-2,代碼行數:44,代碼來源:cosine_similarity.py

示例9: get

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
    def get(self):

        term = self.get_argument('term')

        client = SolrClient('http://localhost:8983/solr')
        res = client.query('stocks', {
            #'q' : 'symbol:%s' % '*'
            'q' : term
        })

        res = json.loads(res.get_json())
        docs = res['response']['docs']

        formatted = []

        for doc in docs:
            formatted.append({
                'name' : doc['name'],
                'symbol' : doc['symbol'],
                'sector' : doc['sector'],
                'open' : doc['open']
            })

        self.write(json.dumps(formatted))
開發者ID:ZackBotkin,項目名稱:stock-project,代碼行數:26,代碼來源:handlers.py

示例10: SolrClient

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
#!/usr/bin/env python

from __future__ import division
import collections
import json
import os
from SolrClient import SolrClient
import sys
from tika import detector

solr = SolrClient('http://localhost:8983/solr')
walk_n = sum(len(files) for root, dirs, files in os.walk(sys.argv[1]))
walk_i = 0
entities = collections.defaultdict(lambda: [])
for root, dirs, files in os.walk(sys.argv[1]):
    for file in files:
        path = root + '/' + file
        mime = detector.from_file(path)
        for val in solr.query('collection1', {'q': 'id:' + file}).data['response']['docs'][0].values():
            if type(val) is list:
                entities[mime].extend(val)
        walk_i += 1
        print str(walk_i * 100 // walk_n) + '%\r',
with open('classification-path.json', 'w') as f:
    json.dump({k: collections.Counter(v) for k, v in entities.iteritems()}, f)
開發者ID:usc-cs599-group5,項目名稱:eval-polar,代碼行數:27,代碼來源:classification-path.py

示例11: SolrClient

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
'''
Create a playlist manually by entering songs one at a time
and searching solr for the particular song
There is also create_playlist_from_queue.py that has you put the songs on the queue
(from a playlist or whatever) and creates a playlist from the queue 
'''
from SolrClient import SolrClient
from config import ec_uri

solr = SolrClient(ec_uri+':8983/solr')
collection = 'sonos_companion'

track_title = input("\nwhat is the title of the track that you are looking for? ")
s = 'title:' + ' AND title:'.join(track_title.split())
result = solr.query(collection, {'q':s, 'rows':10, 'fl':['score', 'id', 'uri', 'title', 'artist', 'album'], 'sort':'score desc'}) 
tracks = result.docs
count = result.get_results_count()
if count==0:
    print("Didn't find any tracks\n")
elif count==1:
    track = tracks[0]
    try:
        print('id: ' + track['id'])
        print('artist: ' + track['artist'])
        print('album: ' + track['album'])
        print('song: ' + track['title'])
        print('uri: ' + track['uri'])
    except Exception as e:
        print(e)
    print('------------------------------------------------------------------------------------------------')
else:    
開發者ID:slzatz,項目名稱:sonos-companion,代碼行數:33,代碼來源:find_solr_track.py

示例12: SolrClient

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
#!/usr/bin/env python

from __future__ import division
import json
import os
from SolrClient import SolrClient
import sys
from tika import detector

solr = SolrClient('http://localhost:8983/solr')
walk_n = sum(len(files) for root, dirs, files in os.walk(sys.argv[1]))
walk_i = 0
ratios = {}
for root, dirs, files in os.walk(sys.argv[1]):
    for file in files:
        path = root + '/' + file
        file_size = os.stat(path).st_size
        if file_size == 0: continue
        mime = detector.from_file(path)
        sum, n = ratios.get(mime, (0, 0))
        ratios[mime] = sum + len(json.dumps(solr.query('collection1', {'q': 'id:' + file}).data['response']['docs'])) / file_size, n + 1
        walk_i += 1
        print str(walk_i * 100 // walk_n) + '%\r',
with open('size-diversity.json', 'w') as f:
    json.dump({mime: sum / n for mime, (sum, n) in ratios.iteritems()}, f)
開發者ID:usc-cs599-group5,項目名稱:eval-polar,代碼行數:27,代碼來源:size-diversity.py

示例13: test_access_without_auth

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
 def test_access_without_auth(self):
     if not test_config['SOLR_CREDENTIALS'][0]:
         return
     solr = SolrClient(test_config['SOLR_SERVER'],devel=True)
     with self.assertRaises(ConnectionError) as cm:
         solr.query('SolrClient_unittest',{'q':'not_gonna_happen'})
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:8,代碼來源:test_client.py

示例14: ClientTestIndexing

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
class ClientTestIndexing(unittest.TestCase):
    #High Level Client Tests
    
    @classmethod
    def setUpClass(self):
        self.solr = SolrClient(test_config['SOLR_SERVER'][0], devel=True, auth=test_config['SOLR_CREDENTIALS'])
        self.rand_docs = RandomTestData()
        self.docs = self.rand_docs.get_docs(50)
        
        for field in test_config['collections']['copy_fields']:
            try:
                self.solr.schema.delete_copy_field(test_config['SOLR_COLLECTION'],field)
            except:
                pass
        for field in test_config['collections']['fields']:
            try:
                self.solr.schema.create_field(test_config['SOLR_COLLECTION'],field)
            except:
                pass
                
    def setUp(self):
        self.delete_docs()
        self.commit()
    
    def delete_docs(self):
        self.solr.delete_doc_by_id(test_config['SOLR_COLLECTION'],'*')
        self.commit()
        
    def commit(self):
        self.solr.commit(test_config['SOLR_COLLECTION'],openSearcher=True)
        sleep(5)
    
    @unittest.skip("Skipping for now")
    def test_access_without_auth(self):
        if not test_config['SOLR_CREDENTIALS'][0]:
            return
        solr = SolrClient(test_config['SOLR_SERVER'],devel=True)
        with self.assertRaises(ConnectionError) as cm:
            solr.query('SolrClient_unittest',{'q':'not_gonna_happen'})
            
    
    def test_indexing_json(self):
        self.docs = self.rand_docs.get_docs(53)
        self.solr.index_json(test_config['SOLR_COLLECTION'],json.dumps(self.docs))
        self.commit()
        sleep(5)
        for doc in self.docs:
            logging.debug("Checking {}".format(doc['id']))
            self.assertEqual(self.solr.query(test_config['SOLR_COLLECTION'],{'q':'id:{}'.format(doc['id'])}).get_num_found(),1)
        self.delete_docs()
        self.commit()
    
    def test_indexing_conn_log(self):
        self.docs = self.rand_docs.get_docs(53)
        self.solr.index_json(test_config['SOLR_COLLECTION'],json.dumps(self.docs))
        self.commit()
        sleep(5)
        for doc in self.docs:
            logging.debug("Checking {}".format(doc['id']))
            self.assertEqual(self.solr.query(test_config['SOLR_COLLECTION'],{'q':'id:{}'.format(doc['id'])}).get_num_found(),1)
        logging.info(self.solr.transport._action_log)
        self.delete_docs()
        self.commit()
    
    def test_index_json_file(self):
        self.docs = self.rand_docs.get_docs(55)
        with open('temp_file.json','w') as f:
            json.dump(self.docs,f)
        r = self.solr.stream_file(test_config['SOLR_COLLECTION'],'temp_file.json')
        self.commit()
        r = self.solr.query(test_config['SOLR_COLLECTION'],{'q':'*:*'})
        self.assertEqual(r.get_num_found(),len(self.docs))
        self.delete_docs()
        self.commit()
        try:
            os.remove('temp_file.json.gz')
            os.remove('temp_file.json')
        except:
            pass
            
    
    def test_stream_file_gzip_file(self):
        self.docs = self.rand_docs.get_docs(60)
        with gzip.open('temp_file.json.gz','wb') as f:
            f.write(json.dumps(self.docs).encode('utf-8'))
        r = self.solr.stream_file(test_config['SOLR_COLLECTION'],'temp_file.json.gz')
        self.commit()
        r = self.solr.query(test_config['SOLR_COLLECTION'],{'q':'*:*'})
        self.assertEqual(r.get_num_found(),len(self.docs))
        self.delete_docs()
        self.commit()
        try:
            os.remove('temp_file.json.gz')
            os.remove('temp_file.json')
        except:
            pass
            
    @unittest.skip("Don't test remote indexing in travis")
    def test_index_json_file(self):
        self.docs = self.rand_docs.get_docs(61)
#.........這裏部分代碼省略.........
開發者ID:cyberj0g,項目名稱:SolrClient,代碼行數:103,代碼來源:test_client.py

示例15: print

# 需要導入模塊: from SolrClient import SolrClient [as 別名]
# 或者: from SolrClient.SolrClient import query [as 別名]
                    if uri.startswith('pndrradio'):
                        meta = meta_format_pandora.format(title=station[0], service=station[2])
                        master.play_uri(uri, meta, station[0]) # station[0] is the title of the station
                    elif uri.startswith('x-sonosapi-stream'):
                        uri = uri.replace('&', '&') # need to escape '&' in radio URIs
                        meta = meta_format_radio.format(title=station[0], service=station[2])
                        master.play_uri(uri, meta, station[0]) # station[0] is the title of the station
                else:
                    print("{} radio is not a preset station.".format(task['station']))

        elif action in ('play','add') and task.get('trackinfo'): 

            #The query below only searches title and artist fields so you don't get every song on After the Gold Rush
            #result = cloudsearchdomain.search(query=task['trackinfo'], queryOptions='{"fields":["title", "artist"]}')
            s = 'artist:' + ' artist:'.join(task['trackinfo'].split()) + ' title:' + ' title:'.join(task['trackinfo'].split())
            result = solr.query(collection, {'q':s, 'rows':1}) #..'rows':25 ...}, queryOptions='{"fields":["title", "artist"]}')

            if result.get_results_count():
                track = result.data['response']['docs'][0]
                try:
                    print('artist: ' + track.get('artist', ['No artist']))
                    print('album: ' + track.get('album', ['No album']))
                    print('song: ' + track.get('title', ['No title']))
                except Exception as e:
                    print("Unicode error")
                uri = track.get('uri', [''])
                print('uri: ' + uri)
                print("---------------------------------------------------------------")

                if 'amz' in uri:
                    i = uri.find('amz')
開發者ID:slzatz,項目名稱:sonos-companion,代碼行數:33,代碼來源:echo_check_solr.py


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