def get_search_results(self, request, query): if settings.WSHOP_GUIDE_FETCH_RESULTS: try: response = requests.get( settings.WSHOP_GUIDE_API_URL, timeout=settings.WSHOP_GUIDE_TIMEOUT_LIMIT, params={"q": query} ) json = response.json() if "results" in json: results = json["results"]["hits"]["hits"] for result in results: title = result["fields"]["title"][0] link = result["fields"]["link"] + ".html" url = manipulate_query_string(link, highlight=query) yield SearchResult( text=_("Guide: %s") % title, url=url, is_action=True, relevance=0, target="_blank", ) except RequestException: # Catch timeout or network errors so as not to break the search pass else: url = manipulate_query_string(settings.WSHOP_GUIDE_LINK_URL, q=query) yield SearchResult( text=_("Search guide for: \"%s\"") % query, url=url, is_action=True, relevance=0, target="_blank" )
def get_search_results(self, request, query): if not self.check_demo_optin(request): return for word in query.split(): if word: yield SearchResult(word, url="https://google.com/?q=%s" % word) yield SearchResult(word[::-1], url="https://google.com/?q=%s" % word[::-1]) yield SearchResult("Create test: %s" % query, url="about:blank", icon="fa fa-plus", is_action=True)
def get_search_results(self, request, query): minimum_query_length = 3 if len(query) >= minimum_query_length: users = get_user_model().objects.filter( Q(username__icontains=query) | Q(email=query)) for i, user in enumerate(users[:10]): relevance = 100 - i yield SearchResult(text=six.text_type(user), url=get_model_url(user), category=_("Contacts"), relevance=relevance)
def get_search_results(self, request, query): shop = request.shop minimum_query_length = 3 skus_seen = set() if len(query) >= minimum_query_length: pk_counter = Counter() pk_counter.update( Product.objects.filter(sku__startswith=query).values_list( "pk", flat=True)) name_q = Q() for part in split_query(query, minimum_query_length): name_q &= Q(name__icontains=part) pk_counter.update( Product._parler_meta.root_model.objects.filter( name_q).values_list("master_id", flat=True)) pks = [pk for (pk, count) in pk_counter.most_common(10)] for product in Product.objects.filter( pk__in=pks, shop_products__shop_id=shop.id): relevance = 100 - pk_counter.get(product.pk, 0) skus_seen.add(product.sku.lower()) yield SearchResult(text=force_text(product), url=get_model_url(product, shop=request.shop), category=_("Products"), relevance=relevance) if len(query) >= minimum_query_length: url = reverse("wshop_admin:shop_product.new") if " " in query: yield SearchResult( text=_("Create Product Called \"%s\"") % query, url=manipulate_query_string(url, name=query), is_action=True) else: if query.lower() not in skus_seen: yield SearchResult( text=_("Create Product with SKU \"%s\"") % query, url=manipulate_query_string(url, sku=query), is_action=True)
def get_search_results(self, request, query): minimum_query_length = 3 if len(query) >= minimum_query_length: categories = Category.objects.filter( Q(translations__name__icontains=query) | Q(identifier__icontains=query)).distinct().order_by( "tree_id", "lft") for i, category in enumerate(categories[:10]): relevance = 100 - i yield SearchResult(text=six.text_type(category), url=get_model_url(category), category=self.category, relevance=relevance)
def get_search_results(self, request, query): minimum_query_length = 3 if len(query) >= minimum_query_length: orders = Order.objects.filter( Q(identifier__istartswith=query) | Q(reference_number__istartswith=query) | Q(email__icontains=query) | Q(phone__icontains=query)).order_by("-id")[:15] for i, order in enumerate(orders): relevance = 100 - i yield SearchResult(text=six.text_type(order), url=get_model_url(order), category=_("Orders"), relevance=relevance)
def get_search_results(self, request, query): minimum_query_length = 3 if len(query) >= minimum_query_length: filters = Q(Q(name__icontains=query) | Q(email=query)) # show only contacts which the shop has access if settings.WSHOP_ENABLE_MULTIPLE_SHOPS and settings.WSHOP_MANAGE_CONTACTS_PER_SHOP: filters &= Q(shops=request.shop) contacts = Contact.objects.filter(filters) for i, contact in enumerate(contacts[:10]): relevance = 100 - i yield SearchResult(text=six.text_type(contact), url=get_model_url(contact), category=_("Contacts"), relevance=relevance)
def get_search_results(self, request, query): if not settings.WSHOP_ENABLE_MULTIPLE_SHOPS: return minimum_query_length = 3 if len(query) >= minimum_query_length: shops = Shop.objects.get_for_user( request.user).filter(translations__name__icontains=query) for i, shop in enumerate(shops[:10]): relevance = 100 - i yield SearchResult( text=(_('Set "{}" as the active shop')).format(shop.name), url=get_model_url(shop, "select"), category=( _("Available Shops [currently active: {}]")).format( request.shop.name), relevance=relevance)
def get_search_results(request, query): fuzzer = FuzzyMatcher(query) normal_results = [] menu_entry_results = [] for module in get_modules(): normal_results.extend(module.get_search_results(request, query) or ()) for menu_entry in module.get_menu_entries(request) or (): texts = (menu_entry.get_search_query_texts() or ()) if any(fuzzer.test(text) for text in texts): menu_entry_results.append( SearchResult(text=menu_entry.text, url=menu_entry.url, icon=menu_entry.icon, category=menu_entry.category, relevance=90, is_action=True)) results = sorted(chain(normal_results, menu_entry_results), key=lambda r: r.relevance, reverse=True) return results
def get_search_results(self, request, query): return [SearchResult(text=query, url="/OK", target="_blank")]