class EventSearcher(object): def search(self, query): data = None try: q = self.parser.parse(query) result = self.searcher.search(q) data = [ {"title": res["title"], "description": res["description"], "id": res["id"], "date": res['date'] } for res in result ] finally: # better to close on __del__? self.searcher.close() return data def __init__(self): index = open_dir("search/index") self.searcher = index.searcher() self.parser = MultifieldParser(["title", "description", "date"], index.schema) self.parser.add_plugin(DateParserPlugin())
class EventSearcher(object): def search(self, query): data = None try: q = self.parser.parse(query) result = self.searcher.search(q) data = [{ "title": res["title"], "description": res["description"], "id": res["id"], "date": res['date'] } for res in result] finally: # better to close on __del__? self.searcher.close() return data def __init__(self): index = open_dir("search/index") self.searcher = index.searcher() self.parser = MultifieldParser(["title", "description", "date"], index.schema) self.parser.add_plugin(DateParserPlugin())
def buildQueryParser(self): # Set numerical scoring parameters CoordinateDescentScorer.baselineScoreWeight = self.baselineScoreWeight CoordinateDescentScorer.pageRankWeight = self.pageRankWeight CoordinateDescentScorer.pageRankScalingWeight = self.pageRankScalingWeight # Build parser keywordsQueryParser = MultifieldParser(['content','title', 'description', 'keywords', 'headers', 'yqlKeywords', 'expandedYqlKeywords'], self.indexSchema, fieldboosts=self.weights, group=OrGroup) keywordsQueryParser.add_plugin(PlusMinusPlugin) return keywordsQueryParser
def buildQueryParser(self): headersQueryParser = MultifieldParser(['content', 'headers'], schema=self.indexSchema, group=OrGroup) headersQueryParser.add_plugin(PlusMinusPlugin) return headersQueryParser
def buildQueryParser(self): descriptionQueryParser = MultifieldParser(['content', 'description'], schema=self.indexSchema, group=OrGroup) descriptionQueryParser.add_plugin(PlusMinusPlugin) return descriptionQueryParser
def buildQueryParser(self): keywordsQueryParser = MultifieldParser(["content", "keywords"], schema=self.indexSchema, group=OrGroup) keywordsQueryParser.add_plugin(PlusMinusPlugin) return keywordsQueryParser
def buildQueryParser(self): titleQueryParser = MultifieldParser(['content', 'title'], schema=self.indexSchema, group=OrGroup) titleQueryParser.add_plugin(PlusMinusPlugin) return titleQueryParser
def buildQueryParser(self): expandedYahooKeywordsQueryParser = MultifieldParser(['content', 'expandedYqlKeywords'], schema=self.indexSchema, group=OrGroup) expandedYahooKeywordsQueryParser.add_plugin(PlusMinusPlugin) return expandedYahooKeywordsQueryParser