Import New SOLR from old SOLR

Source: Internet
Author: User
Tags solr

#! /Usr/bin/Python

Import SOLR

Import re

Import urllib

Import pycurl

Import cstringio

Import collections

Import operator

Import string

Import JSON

Import pysolr


Def solr_update (value ):

Pass


Def function (value ):

Value_1 = {}

Keys = value. Keys ()

T1 = value [Keys [0]

T2 = keys [0]

For II in range (LEN (KEYS)-1 ):

If t1 <value [Keys [II + 1]:

T1 = value [Keys [II + 1]

T2 = keys [II + 1]

Del value [T2]

Value_1 [T2] = T1

Return (value_1, value)



Def dict_sort (value ):

Result = {}

I = 0

While true:

AAA = function (value)

I + = 1

Result [I] = aaa [0]

If Len (AAA [1]) = 1:

Result [I] = aaa [1]

Break

Return result



Def solr_1 (value ):

Test_1 = 'HTTP: // 10.67.15.63: 8800/SOLR/collection1/select? Q = userid: '+ value +' & Wt = JSON & indent = true'

Buf = cstringio. stringio ()

C = pycurl. Curl ()

C. setopt (C. url, test_1)

C. setopt (C. writefunction, Buf. Write)

C. Perform ()

D = Buf. getvalue ()

E = D. Split ('\ n ')

For I in E:

If I. Find ('numfound ')! =-1:

Num = I. Split (":") [1]. Split (",") [0]

Num_1 = num. Split ("")

Num_2 = num_1 [0]. Split ("<") [0]

If value not in ak_list_time:

Ak_list_time [num_2] = num_1 [2]. Split ("=") [1]

Return ak_list_time


Def solr_data (value ):

Test_2 = 'HTTP: // 10.67.15.63: 8800/SOLR/collection1/select? Q = userid: '+ value +' & Wt = JSON & indent = true'

Buf = cstringio. stringio ()

C = pycurl. Curl ()

C. setopt (C. url, test_2)

C. setopt (C. writefunction, Buf. Write)

C. Perform ()

D = Buf. getvalue ()

E = JSON. Loads (d)

Solr_data = E ['response'] ['docs']

# Print solr_data

Return solr_data

# For item in E ['response'] ['docs']:

# Print item ['content']





If _ name _ = '_ main __':

Ak_list_time = {}

Dict_1 = {}

List_1 = []

A = open ('/home/mysql.txt', 'R ')

B = A. readlines ()

S = pysolr. SOLR ('HTTP: // 10.13.144.225: 8983/SOLR /')

For D in B:

K = solr_1 (d)

For KK in K. Keys ():

Dict_1 [Kk] = int (K [Kk] [1:-1])

Dd = sorted (dict_1.iteritems (), Key = Operator. itemgetter (1 ))

Print dd

For KKK in DD:

If KKK [1]! = 0:

G = solr_data (kkk [0])

For item_2 in G:

Del item_2 ['_ version _']

S. Add (g)


This article is from the "batch CT Batch Data Synchronization" blog, please be sure to keep this source http://4249964.blog.51cto.com/4239964/1536030

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.