first steps for georestricted search results
This commit is contained in:
@@ -19,6 +19,7 @@ from rest_framework.decorators import api_view, permission_classes, action
|
||||
from rest_framework.filters import OrderingFilter
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
|
||||
import requests
|
||||
|
||||
from history.models import HistorySync
|
||||
@@ -28,7 +29,7 @@ from products.models import Product, CategoryTag
|
||||
from products.serializers import ProductSerializer, TagFilterSerializer, SearchResultSerializer
|
||||
from companies.models import Company
|
||||
from stats.models import StatsLog
|
||||
from back_latienda.permissions import IsCreator, IsSiteAdmin, ReadOnly
|
||||
from back_latienda.permissions import IsCreator, IsSiteAdmin
|
||||
from .utils import extract_search_filters, ranked_product_search, product_loader, get_related_products
|
||||
from utils.tag_serializers import TaggitSerializer
|
||||
from utils.tag_filters import ProductTagFilter, ProductOrderFilter
|
||||
@@ -125,8 +126,8 @@ def product_search(request):
|
||||
|
||||
Params:
|
||||
- q: used for search [MANDATORY]
|
||||
- limit: max number of returned instances [OPTIONAL]
|
||||
- offset: where to start counting results [OPTIONAL]
|
||||
- limit: max number of returned instances
|
||||
- offset: where to start counting results
|
||||
- shipping_cost: true/false
|
||||
- discount: true/false
|
||||
- category: string
|
||||
@@ -134,6 +135,7 @@ def product_search(request):
|
||||
- order: string (newest/oldest)
|
||||
- price_min: int
|
||||
- price_max: int
|
||||
- geo: {'longitude': 23.23, 'latitude': 23432.23423}
|
||||
|
||||
In the response:
|
||||
- filters
|
||||
@@ -158,11 +160,16 @@ def product_search(request):
|
||||
discount = request.GET.get('discount', None)
|
||||
if discount is not None:
|
||||
if discount == 'true':
|
||||
discount = True
|
||||
discount = True
|
||||
elif discount == 'false':
|
||||
discount = False
|
||||
discount = False
|
||||
else:
|
||||
discount = None
|
||||
discount = None
|
||||
geo = request.GET.get('geo', None)
|
||||
if geo is not None:
|
||||
coordinates = (geo.get('longitude'), geo.get('latitude'))
|
||||
else:
|
||||
coordinates = None
|
||||
category = request.GET.get('category', None)
|
||||
tags = request.GET.get('tags', None)
|
||||
price_min = request.GET.get('price_min', None)
|
||||
@@ -195,7 +202,7 @@ def product_search(request):
|
||||
# split query string into single words
|
||||
chunks = q.split(' ')
|
||||
for chunk in chunks:
|
||||
product_set, min_price, max_price = ranked_product_search(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
||||
product_set, min_price, max_price, georesult = ranked_product_search(chunk, shipping_cost, discount, category, tags, price_min, price_max, coordinates)
|
||||
# update price values
|
||||
if product_set:
|
||||
if prices['min'] is None or min_price['price__min'] < prices['min']:
|
||||
|
||||
Reference in New Issue
Block a user