• R/O
  • HTTP
  • SSH
  • HTTPS

pybbs: Commit

無料の掲示板


Commit MetaInfo

Revision5e9a7469520b4c80ea88835d9b215b150980f098 (tree)
Time2018-01-11 10:56:00
Authoryamat0jp <yamat0jp@yaho...>
Commiteryamat0jp

Log Message

‘and or’ search

Change Summary

Incremental Difference

--- a/index.py
+++ b/index.py
@@ -318,7 +318,8 @@ class UserHandler(web.RequestHandler):
318318 class SearchHandler(web.RequestHandler):
319319 def post(self,dbname):
320320 arg = self.get_argument('word1')
321- self.word = arg
321+ self.word = arg[:]
322+ self.andor = self.get_argument('type')
322323 self.radiobox = self.get_argument('filter')
323324 rec = sorted(self.search(dbname),key=lambda x: x['number'])
324325 self.render('modules/search.htm',records=rec,word1=arg,db=dbname)
@@ -331,6 +332,7 @@ class SearchHandler(web.RequestHandler):
331332
332333 def search(self,dbname):
333334 table = self.application.db[dbname]
335+ andor = self.andor == 'OR'
334336 element = self.word.split()
335337 if len(element) == 0:
336338 element = ['']
@@ -339,18 +341,25 @@ class SearchHandler(web.RequestHandler):
339341 elm = []
340342 for i in range(3):
341343 elm.append(re.escape(element[i]))
342- if self.radiobox == 'comment':
343- for x in table.find({'$or':[{'raw':re.compile(elm[0],re.IGNORECASE)},
344- {'raw':re.compile(elm[1],re.IGNORECASE)},
345- {'raw':re.compile(elm[2],re.IGNORECASE)}
346- ]}):
344+ if self.radiobox == 'comment':
345+ query = [{'raw':re.compile(elm[0],re.IGNORECASE)},
346+ {'raw':re.compile(elm[1],re.IGNORECASE)},
347+ {'raw':re.compile(elm[2],re.IGNORECASE)}
348+ ]
349+ if andor:
350+ result = table.find({'$or':query})
351+ color = 'yellow'
352+ else:
353+ result = table.find({'$and':query})
354+ color = 'aqua'
355+ for x in result:
347356 com = ''
348357 for text in x['raw'].splitlines(True):
349358 if re.match(' ',text):
350359 text = text.replace(' ','&nbsp;',1)
351360 for i in range(3):
352361 if element[i].lower() in text.lower():
353- com = com +'<p style=background-color:yellow>'+text+'<br></p>'
362+ com = com +'<p style=background-color:'+color+'>'+text+'<br></p>'
354363 break
355364 else:
356365 com = com+'<p>'+text+'<br></p>'
Show on old repository browser