質問編集履歴
4
質問の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -209,6 +209,40 @@
|
|
209
209
|
print('query')
|
210
210
|
print(query)
|
211
211
|
|
212
|
+
・呼び出し元
|
213
|
+
solrquery = SolrQuery()
|
214
|
+
query = solrquery.createPoiSearchQuary(req_data)↑上記の関数
|
215
|
+
res = SolrAccess.execute(query, CORE10)↓下記のexecute
|
216
|
+
|
217
|
+
def execute(query:str, core:str, data:dict= {}):
|
218
|
+
# 送信先のURL(開発環境疎通確認用)
|
219
|
+
#url = 'http://solr-dev.dev-financial-nsw.com/solr/zennrin/select?indent=true&q.op=OR&q=*%3A*'
|
220
|
+
|
221
|
+
# 送信先のURL(開発環境用)
|
222
|
+
url = URL.format(core) + query
|
223
|
+
|
224
|
+
# Basic認証の情報(開発環境用)
|
225
|
+
user = USER
|
226
|
+
password = PASS
|
227
|
+
|
228
|
+
# Basic認証用の文字列を作成.
|
229
|
+
basic_user_and_pasword = base64.b64encode('{}:{}'.format(user, password).encode('utf-8'))
|
230
|
+
|
231
|
+
# Basic認証付きの、POSTリクエストを作成する.
|
232
|
+
request = urllib.request.Request(url,
|
233
|
+
headers={
|
234
|
+
"Authorization": "Basic " + basic_user_and_pasword.decode('utf-8') ,
|
235
|
+
"Content-Type" : "application/json",
|
236
|
+
},
|
237
|
+
method='POST', data=json.dumps(data).encode('utf-8'))
|
238
|
+
|
239
|
+
# 送信して、レスポンスを受け取る.
|
240
|
+
con = urllib.request.urlopen(request)
|
241
|
+
|
242
|
+
res = simplejson.load(con)
|
243
|
+
|
244
|
+
return res
|
245
|
+
|
212
246
|
```
|
213
247
|
|
214
248
|
```ここに言語を入力
|
@@ -229,8 +263,3 @@
|
|
229
263
|
raise HTTPError(req.full_url, code, msg, hdrs, fp)
|
230
264
|
urllib.error.HTTPError: HTTP Error 400: Bad Request
|
231
265
|
```
|
232
|
-
|
233
|
-
```ここに言語を入力
|
234
|
-
・urlは直接入力して、成功
|
235
|
-
http://solr-dev.dev-financial-nsw.com/solr/zennrin/select?q=name:ディズニーランド^40.0 OR genre_name_array:ディズニーランド^300.0 OR yomi:ディズニーランド^60.0 OR name_morph_sym:ディズニーランド^20.0 OR name_bigram:ディズニーランド^10.0 OR yomi_morph:ディズニーランド^10.0 OR yomi_bigram:ディズニーランド^10.0 _val_:"mul(pow(0.5,div(geodist(), 1)),37140)"&q.op=OR&indent=true&fl=*,score,distance:geodist()&sort=score desc,uniquekey asc&sfield=geo_p_wgs&pt=35.73016903373604,139.74800272437313&d=2&fq={!geofilt}
|
236
|
-
```
|
3
質問の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -229,3 +229,8 @@
|
|
229
229
|
raise HTTPError(req.full_url, code, msg, hdrs, fp)
|
230
230
|
urllib.error.HTTPError: HTTP Error 400: Bad Request
|
231
231
|
```
|
232
|
+
|
233
|
+
```ここに言語を入力
|
234
|
+
・urlは直接入力して、成功
|
235
|
+
http://solr-dev.dev-financial-nsw.com/solr/zennrin/select?q=name:ディズニーランド^40.0 OR genre_name_array:ディズニーランド^300.0 OR yomi:ディズニーランド^60.0 OR name_morph_sym:ディズニーランド^20.0 OR name_bigram:ディズニーランド^10.0 OR yomi_morph:ディズニーランド^10.0 OR yomi_bigram:ディズニーランド^10.0 _val_:"mul(pow(0.5,div(geodist(), 1)),37140)"&q.op=OR&indent=true&fl=*,score,distance:geodist()&sort=score desc,uniquekey asc&sfield=geo_p_wgs&pt=35.73016903373604,139.74800272437313&d=2&fq={!geofilt}
|
236
|
+
```
|
2
質問の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,3 +14,218 @@
|
|
14
14
|
エラーになります。
|
15
15
|
一般的に上記の方法で何か間違った方法があり、何かおかしい点は、
|
16
16
|
ありますか。
|
17
|
+
|
18
|
+
|
19
|
+
```ここに言語を入力
|
20
|
+
・POSTMANのパラメータ
|
21
|
+
{
|
22
|
+
"rsc":"z_poi",
|
23
|
+
"keyword":"ディズニーランド",
|
24
|
+
"sortType":1,
|
25
|
+
"longitude":140,
|
26
|
+
"latitude":135,
|
27
|
+
"rangetype":1,
|
28
|
+
"polygon":[
|
29
|
+
{
|
30
|
+
"latitude": 140,
|
31
|
+
"longitude": 138
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"latitude": 145,
|
35
|
+
"longitude": 145
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"latitude": 139,
|
39
|
+
"longitude": 145
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"latitude": 138,
|
43
|
+
"longitude": 139
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"latitude": 140,
|
47
|
+
"longitude": 138
|
48
|
+
}
|
49
|
+
],
|
50
|
+
"pos":1,
|
51
|
+
"num":20
|
52
|
+
}
|
53
|
+
|
54
|
+
・solrquery.py
|
55
|
+
import urllib.parse
|
56
|
+
from janus.azazel.azazel import Azazel
|
57
|
+
|
58
|
+
class SolrQuery:
|
59
|
+
|
60
|
+
def __init__(self) -> None:
|
61
|
+
self._logger = Azazel()
|
62
|
+
|
63
|
+
def createPoiSearchQuary(self, req_data):
|
64
|
+
print('req_data')
|
65
|
+
print(req_data)
|
66
|
+
self._logger.writeLogDebug("SolrQuery::createPoiSearchQuery start")
|
67
|
+
# フリーワード【keyword】、ジャンル【genre】に以下の特殊文字が入ってる場合、その前に『/』マークを付ける。
|
68
|
+
if not req_data.get('keyword') is None:
|
69
|
+
print('test1')
|
70
|
+
req_data['keyword'] = SolrQuery.escapeword(req_data.get('keyword'))
|
71
|
+
if not req_data.get('genre') is None:
|
72
|
+
print('test2')
|
73
|
+
req_data['genre'] = SolrQuery.escapeword(req_data.get('genre'))
|
74
|
+
|
75
|
+
keywordlist = 1
|
76
|
+
# keywordlist = req_data.get('keyword').split(' ')
|
77
|
+
|
78
|
+
if keywordlist > 1:
|
79
|
+
#q1の式作成
|
80
|
+
q1 = ''
|
81
|
+
count = 0
|
82
|
+
for kword in keywordlist:
|
83
|
+
#重みづけ処理
|
84
|
+
kword = SolrQuery.waitplus(kword)
|
85
|
+
if count > 0:
|
86
|
+
q1 += 'AND ' + kword
|
87
|
+
else:
|
88
|
+
q1 += kword
|
89
|
+
count += 1
|
90
|
+
q1 = '(' + q1 + ')'
|
91
|
+
else:
|
92
|
+
kword = req_data.get('keyword')
|
93
|
+
kword = SolrQuery.waitplus(kword)
|
94
|
+
q1 = kword
|
95
|
+
self._logger.writeLogDebug('q1: {}'.format(q1))
|
96
|
+
#q2の式作成
|
97
|
+
q2 = ''
|
98
|
+
if not req_data.get('genre') is None:
|
99
|
+
genrelist = req_data.get('genre').split(',')
|
100
|
+
count = 0
|
101
|
+
for gword in genrelist:
|
102
|
+
if count > 0:
|
103
|
+
q2 += ' OR (fq_genre_key_array:' + gword + ')'
|
104
|
+
else:
|
105
|
+
q2 += '(fq_genre_key_array:' + gword + ')'
|
106
|
+
count += 1
|
107
|
+
q2 = ' AND (' + q2 + ')^=1'
|
108
|
+
q2 = str(q2).replace("[","").replace("]","").replace("/","")
|
109
|
+
q2 = ''
|
110
|
+
print('q2')
|
111
|
+
print(q2)
|
112
|
+
|
113
|
+
#q3の式作成
|
114
|
+
q3 = ''
|
115
|
+
if not req_data.get('area') is None:
|
116
|
+
arealist = req_data.get('area').split(' ')
|
117
|
+
for area in arealist:
|
118
|
+
if len(req_data.get('area')) == 2:
|
119
|
+
q3 += '(prefcode:' + area + ')'
|
120
|
+
else:
|
121
|
+
q3 += 'OR (prefcode:' + area[0:1] + ' AND ' + area[2:4] + ')'
|
122
|
+
q3 = ' AND (' + q3 + ')^=1'
|
123
|
+
|
124
|
+
# q = '(' + q1 + q2 + q3 + ')'
|
125
|
+
q = q1 + q2 + q3
|
126
|
+
print('q')
|
127
|
+
print(q)
|
128
|
+
|
129
|
+
#置換前 置換後 後で作成
|
130
|
+
|
131
|
+
#q4の式作成
|
132
|
+
q4 = ''
|
133
|
+
req_sort = req_data.get('sort')
|
134
|
+
req_rangetype = req_data.get('rangetype')
|
135
|
+
print('test10')
|
136
|
+
print(req_sort,req_rangetype)
|
137
|
+
#検索パラメータ設定
|
138
|
+
if req_data.get('radius') is None:
|
139
|
+
req_data['radius'] = 10000
|
140
|
+
|
141
|
+
if req_sort == 1 or req_sort == 2:
|
142
|
+
if req_sort == 1 and req_rangetype == 1:
|
143
|
+
print('test5')
|
144
|
+
# q4 = '_val_:"mul(pow(0.5,div(geodist(),' + str(req_data.get('radius')) + ' / 1000 / 2)),37140)"'
|
145
|
+
q4 = '_val_:mul(pow(0.5,div(geodist(), 1)),37140)'
|
146
|
+
elif req_sort == 1 and req_rangetype == 2:
|
147
|
+
# q4 = '_val_:"mul(pow(0.5,div(geodist(),' + str(req_data.get('radius')) + ' / 1000 / 2)),37140)"'
|
148
|
+
q4 = '_val_:mul(pow(0.5,div(geodist(), 1)),37140)'
|
149
|
+
elif req_sort == 2 and req_rangetype == 1:
|
150
|
+
# q4 = '_val_:"mul(pow(0.5,div(geodist(),' + str(req_data.get('radius')) + ' / 1000 / 2)),37140)"'
|
151
|
+
q4 = '_val_:mul(pow(0.5,div(geodist(), 1)),37140)'
|
152
|
+
elif req_sort == 2 and req_rangetype == 2:
|
153
|
+
# q4 = '_val_:"mul(pow(0.5,div(geodist(),' + str(req_data.get('radius')) + ' / 1000 / 2)),37140)"'
|
154
|
+
q4 = '_val_:mul(pow(0.5,div(geodist(), 1)),37140)'
|
155
|
+
print('q4')
|
156
|
+
print(q4)
|
157
|
+
|
158
|
+
amp = '&'
|
159
|
+
|
160
|
+
d = '&d=' + urllib.parse.quote(str(req_data.get('radius') // 1000))
|
161
|
+
# d = 'd=' + urllib.parse.quote(str(req_data.get('radius') // 1000))
|
162
|
+
print('d')
|
163
|
+
print(d)
|
164
|
+
fl = amp + 'fl=' + urllib.parse.quote('*,score,distance:geodist()') if not req_data.get('lonlat') is None else ''
|
165
|
+
print('fl')
|
166
|
+
print(req_data.get('lonlat'))
|
167
|
+
print(fl)
|
168
|
+
fq = amp + 'fq=' + urllib.parse.quote('{!geofilt}') if not req_data.get('lonlat') is None else ''
|
169
|
+
print('fq')
|
170
|
+
print(fq)
|
171
|
+
# indent = 'indent=' + urllib.parse.quote('true')
|
172
|
+
indent = amp +'indent=' + urllib.parse.quote('true')
|
173
|
+
print('indent')
|
174
|
+
print(indent)
|
175
|
+
pt = amp + 'pt=' + urllib.parse.quote(str(SolrQuery.ptset(req_data.get('lonlat')))) if not req_data.get('lonlat') is None else ''
|
176
|
+
print('pt')
|
177
|
+
print(pt)
|
178
|
+
qop = amp + 'q.op=' + urllib.parse.quote('OR')
|
179
|
+
print('qop')
|
180
|
+
print(qop)
|
181
|
+
# q = amp + 'q=' + urllib.parse.quote(q + ' ' + q4)
|
182
|
+
q = 'q=' + urllib.parse.quote(q + ' ' + q4)
|
183
|
+
print('q')
|
184
|
+
print(q)
|
185
|
+
sfield = amp + 'sfield=' + urllib.parse.quote('geo_p_wgs')
|
186
|
+
print('sfield')
|
187
|
+
print(sfield)
|
188
|
+
sort = amp + 'sort=' + urllib.parse.quote('score desc,uniquekey asc') if not req_data.get('lonlat') is None else ''
|
189
|
+
print('sort')
|
190
|
+
print(sort)
|
191
|
+
if req_sort == 3:
|
192
|
+
sort = amp + 'sort=' + urllib.parse.quote('yomi desc,uniquekey asc') if not req_data.get('lonlat') is None else ''
|
193
|
+
fl = amp + 'fl=' + urllib.parse.quote('*,score') if not req_data.get('lonlat') is None else ''
|
194
|
+
|
195
|
+
deftype = amp + 'deftype=' + urllib.parse.quote('edimax')
|
196
|
+
print('deftype')
|
197
|
+
print(deftype)
|
198
|
+
start = amp + 'start=' + urllib.parse.quote(str(req_data.get('pos'))) if not req_data.get('pos') is None else ''
|
199
|
+
print('start')
|
200
|
+
print(start)
|
201
|
+
|
202
|
+
rows = amp + 'rows=' + urllib.parse.quote(str(req_data.get('num'))) if not req_data.get('num') is None else ''
|
203
|
+
print('rows')
|
204
|
+
print(rows)
|
205
|
+
# query = indent + qop + q + sfield + sort + deftype + start + rows + d
|
206
|
+
# query = indent + qop + q + sfield + sort + deftype + start + rows + d + fl + fq + pt
|
207
|
+
# query = q + qop + indent + fl + sort + sfield + pt + fq + deftype + start + rows + d
|
208
|
+
query = q + qop + indent + fl + sort + sfield + pt + fq
|
209
|
+
print('query')
|
210
|
+
print(query)
|
211
|
+
|
212
|
+
```
|
213
|
+
|
214
|
+
```ここに言語を入力
|
215
|
+
・エラーの内容
|
216
|
+
nus\solrAccess\solraccess.py", line 71, in execute
|
217
|
+
con = urllib.request.urlopen(request)
|
218
|
+
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 216, in urlopen
|
219
|
+
return opener.open(url, data, timeout)
|
220
|
+
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 525, in open
|
221
|
+
response = meth(req, response)
|
222
|
+
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 634, in http_response
|
223
|
+
response = self.parent.error(
|
224
|
+
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 563, in error
|
225
|
+
return self._call_chain(*args)
|
226
|
+
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 496, in _call_chain
|
227
|
+
result = func(*args)
|
228
|
+
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 643, in http_error_default
|
229
|
+
raise HTTPError(req.full_url, code, msg, hdrs, fp)
|
230
|
+
urllib.error.HTTPError: HTTP Error 400: Bad Request
|
231
|
+
```
|
1
質問の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
q4の複雑な文字列に対して、httpリクエストを行う場合に、
|
8
8
|
urllib.parse.quoteにより、日本語でも可能になると、
|
9
9
|
分かりました。
|
10
|
-
|
10
|
+
上記のq4を変換すると、リクエストとして、下記のように、
|
11
11
|
文字コードに変換されます。
|
12
12
|
_val_%3A%22mul%28pow%280.5%2Cdiv%28geodist%28%29%2C%201%29%29%2C37140%29%22
|
13
13
|
しかし、solrという検索エンジンに、リクエストを送ると、
|