Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional search #565

Closed
wants to merge 75 commits into from
Closed

Conversation

artursmet
Copy link
Contributor

Closes #291

@@ -29,12 +30,16 @@ django-selectable==0.9.0
django-storages==1.5.1
django-versatileimagefield==1.6
django-webpack-loader==0.3.3
Django==1.10.1 # via django-absolute, django-emailit, django-model-utils, django-payments, django-prices, jsonfield
Django==1.9.10 # via django-absolute, django-emailit, django-haystack, django-model-utils, django-payments, django-prices, jsonfield
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 1.9?

@@ -290,3 +292,12 @@
'IGNORE': [
r'.+\.hot-update\.js',
r'.+\.map']}}


HAYSTACK_CONNECTIONS = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this configurable using env and default to using whoosh?



class ProductVariantIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please not use a single document field for search? It does not what which field is which so it'll treat the product name, variant name and description as a single value. None of the metrics like term/field factor or term position make any sense in that setup.

@artursmet
Copy link
Contributor Author

artursmet commented Oct 7, 2016

@patrys This is In progress pull request, all these problems, you've mentioned will be fixed. Django 1.9 because django-haystack now doesn't support 1.10. I only wanted to open it to have CI builds running :)

@patrys
Copy link
Member

patrys commented Oct 7, 2016

I know it's in progress but I'm afraid requiring 1.9 may become a blocker.

@codecov-io
Copy link

codecov-io commented Oct 7, 2016

Current coverage is 58.26% (diff: 37.51%)

Merging #565 into master will decrease coverage by 5.30%

@@             master       #565   diff @@
==========================================
  Files            91        105     +14   
  Lines          4156       5219   +1063   
  Methods           0          0           
  Messages          0          0           
  Branches        440        615    +175   
==========================================
+ Hits           2642       3041    +399   
- Misses         1424       2063    +639   
- Partials         90        115     +25   

Powered by Codecov. Last update 4408761...dbc6aa2

@artursmet
Copy link
Contributor Author

Implementation is finished and ready for review

@artursmet
Copy link
Contributor Author

We'll be able to merge this as soon as Haystack will support Django 1.10 (django-haystack/django-haystack#1445)

@weronka weronka force-pushed the add-optional-search branch 4 times, most recently from 65e5971 to 480c850 Compare October 26, 2016 08:56
@@ -48,3 +48,24 @@ Environment variables

``SECRET_KEY``
Controls `Django's secret key <https://docs.djangoproject.com/en/1.10/ref/settings/#secret-key>`_ setting.

``ENABLE_ELASTICSEARCH``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a separate variable for that? Why would I set ELASTICSEARCH_URL and ELASTICSEARCH_INDEX_NAME if I did not intend to use Elasticsearch?


.. code-block:: bash

$ pip install elasticsearch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add this to our requirements. It needs to run out of the box on Heroku.

HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': os.environ.get('ELASTICSEARCH_URL',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also handle BONSAI_URL and SEARCHBOX_URL (these are Heroku add-ons that provide Elasticsearch).

var $menuToggle = $('.menu-toggle')
var $closeMenu = $('#close-menu')
var $openMenu = $('#open-menu')
function openMenu(a) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can come up with a more descriptive name than a 😉

$openMenu.addClass('hide')
$closeMenu.removeClass('hide')
$menuToggle.addClass('fixed')
if ( $windowWidth > 990 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space inside the parentheses is not needed.

$closeMenu.click(function() {
closeMenu()
})
if ($windowWidth < 991) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of hardcoding the pixel values all around the place. Could we define some constants for break points and use those later in code?

Also how do we handle resizing the window?

@weronka
Copy link
Contributor

weronka commented Oct 26, 2016

before

before
after

after2

@@ -37,3 +37,6 @@ requests>=1.2.0
satchless>=1.1.2,<1.2a0
unidecode
uwsgi>=2.0.0
django-haystack==2.5.0
Whoosh==2.7.4
elasticsearch==2.4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is meant to be sorted :)

return Product

def index_queryset(self, using=None):
qs = self.get_model().objects.get_available_products()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to index all products and reimplement availability checks at search time (but only when searching the site and not the dashboard).

logger = logging.getLogger(__name__)


def update_object(instance, using='default'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gain anything from having a "generic" solution like this? Why not have explicit update_product, update_user etc.?

from ..userprofile.models import User


def search_for_model(request, models):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name suggests it would search for a single model.

raise Http404("No such page!")
else:
page = form.no_query_found()
return {'page': page, 'query': form.cleaned_data['q']}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning a tuple or a namedtuple?

'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': os.environ.get('ELASTICSEARCH_URL',
'http://127.0.0.1:9200/'),
'INDEX_NAME': os.environ.get('ELASTICSEARCH_INDEX_NAME', 'saleor')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think storefront would be a more reasonable default index name. I'd take descriptive database names over branded ones.

'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

``ELASTICSEARCH_URL``
Contains URL address to the elasticsearch cluster. Defaults to ``http://127.0.0.1:9200/``.

``BONSAI_URL``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data indexing
-------------

Saleor uses `django-haystack <http://haystacksearch.org/>`_ to provide search engine, please refer to haystack documentation to get familiar with implementation details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"[...] to provide search, [...]" and "Haystack" instead of "django-haystack" and "haystack"

@@ -1,6 +1,8 @@
from __future__ import unicode_literals

import ast
from urlparse import urlparse

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path is also a platform import.

from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please isort this.

@patrys
Copy link
Member

patrys commented Oct 27, 2016

@weronka

Is it possible to make sidebar start below the navbar?

Can we replace |< icon with a full breadcrumb trail for now? (ie. "Products ⟩ Kirby, Clark and Green ▼")



@staff_member_required
def dashboard_search(request):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this live in dashboard/search/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep all search related views inside one app

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus is inconsistent with the rest of Saleor.

@artursmet artursmet force-pushed the add-optional-search branch 2 times, most recently from bac3e02 to 32d9101 Compare October 27, 2016 13:56
@artursmet
Copy link
Contributor Author

@patrys We no longer depend on Django 1.9, django-haystack 2.5.1 supports new Django versions.

@artursmet artursmet force-pushed the add-optional-search branch 2 times, most recently from 5e628f6 to 189b46a Compare October 31, 2016 09:36
@weronka
Copy link
Contributor

weronka commented Nov 4, 2016

@patrys
Sidebar already starts below the navbar. Attaching screenshot with closed sidebar:

close

Box shadow is added to the logo part on navbar for long pages, when side nav stay fixed and content is scrolling:

scroll

@artursmet artursmet force-pushed the add-optional-search branch 2 times, most recently from a104446 to cce3f69 Compare November 15, 2016 13:49
@artursmet
Copy link
Contributor Author

@patrys Could you review this branch?

@artursmet
Copy link
Contributor Author

Reopened on fresh branch in #661

@artursmet artursmet closed this Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants