From 088758e67b6c461d76432f9b6468f629e7be50fa Mon Sep 17 00:00:00 2001 From: lzjqsdd Date: Sat, 7 May 2016 00:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=89=8D=E7=AB=AF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ml/Search.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ml/Search.py b/ml/Search.py index ce74d4e..d53fbc9 100644 --- a/ml/Search.py +++ b/ml/Search.py @@ -41,7 +41,7 @@ class Search: #'与'查询:先分词,再合并倒排记录,不考虑权重,返回文档号 - def QueryPhrase(self,searchPhrase,ishow = True): + def QueryPhrase(self,searchPhrase,isshow = True): words = jieba.cut(searchPhrase.decode('utf-8'),cut_all=False) cut = Cut() result = set(range(1,100000)) @@ -56,16 +56,16 @@ class Search: for rec in record: re.add(int(rec)) result = result & re - print result - if ishow: - if len(result) == 0: - print 'Not Exists Record!' - else: - for rst in result: - line = cut.getRow(int(rst),Global.cutnews_origin_dir,Global.filesize) - data = json.loads(line) - print data['title'],'\n',data['time'],'\n',data['content'],'\n' - return result + if len(result) == 0: + print 'Not Exists Record!' + newslist=list() + for rst in result: + line = cut.getRow(int(rst),Global.cutnews_origin_dir,Global.filesize) + data = json.loads(line) + if isshow: + print data['title'],'\n',data['time'],'\n',data['content'],'\n' + newslist.append(data) + return newslist #返回热点新闻 def QueryHotNews(self): @@ -75,6 +75,6 @@ class Search: def QueryByTime(self): pass -search = Search() +#search = Search() +#search.QueryPhrase(sys.argv[1]) #search.QueryPhrase(sys.argv[1]) -search.QueryPhrase(sys.argv[1])