def search(self, query, exclude=[], force=False, limit=20):
# Fetches all document that have at least one of the terms
pubs = self.index.search(query,
search_fields=["title", "abstract"],
return_fields=["id"],
ignore=exclude)
# Unpack and convert to a set for fast lookup
pubs = set([pub_id for (pub_id,) in pubs])
# index_ids, _scores = self.index.search(query, ["title", "abstract"], limit=limit, mode="ALL")
# docs = set(self.index.get_documents(index_ids, "id"))
g = nx.DiGraph()
for u, v in self.edges:
if (u in pubs) and (v in pubs):
g.add_edge(u, v)
# print "PageRank with %d nodes." % g.number_of_nodes()
r = nx.pagerank(g, alpha=0.7)
if len(r) == 0:
return []
ids, _pg = zip(*sorted(r.items(), key=lambda (k, v): v, reverse=True))
return ids[:limit]
评论列表
文章目录