def _recommend_me_result(self, recommender_agent, result_list): pkgs = [] for item in result_list['data']: pkgs.append(item['package_name']) if self.subcategory: self.query = xapian.Query(xapian.Query.OP_AND, get_query_for_pkgnames(pkgs), self.subcategory.query) else: self.query = get_query_for_pkgnames(pkgs) self.emit("needs-refresh")
def _on_show_exhibits(self, exhibit_banner, exhibit): pkgs = exhibit.package_names.split(",") if len(pkgs) == 1: app = Application("", pkgs[0]) self.emit("application-activated", app) else: query = get_query_for_pkgnames(pkgs) title = exhibit.title_translated untranslated_name = exhibit.package_names # create a temp query cat = Category(untranslated_name, title, None, query, flags=['nonapps-visible']) self.emit("category-selected", cat)
def _ceibal_get_docs(self): """ return the database docids for the given category """ enq = AppEnquire(self.db._aptcache, self.db) app_filter = AppFilter(self.db, self.db._aptcache) app_filter.set_available_only(True) #app_filter.set_not_installed_only(True) p = "http://apt.ceibal.edu.uy/recommendations/list.json" data = json.load(urllib2.urlopen(p)) query = get_query_for_pkgnames(data['packages']) enq.set_query(query, limit=20, filter=app_filter, sortmode=0, nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE, nonblocking_load=False) return enq.get_documents()
def _recommend_app_result(self, recommender_agent, result_list): pkgs = [] for item in result_list['data']: pkgs.append(item['package_name']) self.query = get_query_for_pkgnames(pkgs) self.emit("needs-refresh")
def get_query_list_from_search_entry(self, search_term, category_query=None): """ get xapian.Query from a search term string and a limit the search to the given category """ def _add_category_to_query(query): """ helper that adds the current category to the query""" if not category_query: return query return xapian.Query(xapian.Query.OP_AND, category_query, query) # empty query returns a query that matches nothing (for performance # reasons) if search_term == "" and category_query is None: return SearchQuery(xapian.Query()) # we cheat and return a match-all query for single letter searches if len(search_term) < 2: return SearchQuery(_add_category_to_query(xapian.Query(""))) # check if there is a ":" in the search, if so, it means the user # is using a xapian prefix like "pkg:" or "mime:" and in this case # we do not want to alter the search term (as application is in the # greylist but a common mime-type prefix) if not ":" in search_term: # filter query by greylist (to avoid overly generic search terms) orig_search_term = search_term for item in self.SEARCH_GREYLIST_STR.split(";"): (search_term, n) = re.subn('\\b%s\\b' % item, '', search_term) if n: LOG.debug("greylist changed search term: '%s'" % search_term) # restore query if it was just greylist words if search_term == '': LOG.debug("grey-list replaced all terms, restoring") search_term = orig_search_term # we have to strip the leading and trailing whitespaces to avoid having # different results for e.g. 'font ' and 'font' (LP: #506419) search_term = search_term.strip() # get a pkg query if "," in search_term: pkg_query = get_query_for_pkgnames(search_term.split(",")) else: pkg_query = xapian.Query() for term in search_term.split(): pkg_query = xapian.Query(xapian.Query.OP_OR, xapian.Query("XP" + term), pkg_query) pkg_query = _add_category_to_query(pkg_query) # get a search query if not ':' in search_term: # ie, not a mimetype query # we need this to work around xapian oddness search_term = search_term.replace('-', '_') fuzzy_query = self.xapian_parser.parse_query( search_term, xapian.QueryParser.FLAG_PARTIAL | xapian.QueryParser.FLAG_BOOLEAN) # if the query size goes out of hand, omit the FLAG_PARTIAL # (LP: #634449) if fuzzy_query.get_length() > 1000: fuzzy_query = self.xapian_parser.parse_query( search_term, xapian.QueryParser.FLAG_BOOLEAN) # now add categories fuzzy_query = _add_category_to_query(fuzzy_query) return SearchQuery([pkg_query, fuzzy_query])
def get_query_list_from_search_entry(self, search_term, category_query=None): """ get xapian.Query from a search term string and a limit the search to the given category """ def _add_category_to_query(query): """ helper that adds the current category to the query""" if not category_query: return query return xapian.Query(xapian.Query.OP_AND, category_query, query) # empty query returns a query that matches nothing (for performance # reasons) if search_term == "" and category_query is None: return SearchQuery(xapian.Query()) # we cheat and return a match-all query for single letter searches if len(search_term) < 2: return SearchQuery(_add_category_to_query(xapian.Query(""))) # check if there is a ":" in the search, if so, it means the user # is using a xapian prefix like "pkg:" or "mime:" and in this case # we do not want to alter the search term (as application is in the # greylist but a common mime-type prefix) if not ":" in search_term: # filter query by greylist (to avoid overly generic search terms) orig_search_term = search_term for item in self.SEARCH_GREYLIST_STR.split(";"): (search_term, n) = re.subn('\\b%s\\b' % item, '', search_term) if n: self._logger.debug("greylist changed search term: '%s'" % search_term) # restore query if it was just greylist words if search_term == '': self._logger.debug("grey-list replaced all terms, restoring") search_term = orig_search_term # we have to strip the leading and trailing whitespaces to avoid having # different results for e.g. 'font ' and 'font' (LP: #506419) search_term = search_term.strip() # get a pkg query if "," in search_term: pkg_query = get_query_for_pkgnames(search_term.split(",")) else: pkg_query = xapian.Query() for term in search_term.split(): pkg_query = xapian.Query(xapian.Query.OP_OR, xapian.Query("XP"+term), pkg_query) pkg_query = _add_category_to_query(pkg_query) # get a search query if not ':' in search_term: # ie, not a mimetype query # we need this to work around xapian oddness search_term = search_term.replace('-','_') fuzzy_query = self.xapian_parser.parse_query(search_term, xapian.QueryParser.FLAG_PARTIAL| xapian.QueryParser.FLAG_BOOLEAN) # if the query size goes out of hand, omit the FLAG_PARTIAL # (LP: #634449) if fuzzy_query.get_length() > 1000: fuzzy_query = self.xapian_parser.parse_query(search_term, xapian.QueryParser.FLAG_BOOLEAN) # now add categories fuzzy_query = _add_category_to_query(fuzzy_query) return SearchQuery([pkg_query,fuzzy_query])