mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Added subtree search. Search view now only searches for pages in current site
This commit is contained in:
parent
334744abd9
commit
b33248519c
@ -184,6 +184,10 @@ class Page(MP_Node, ClusterableModel, Indexed):
|
||||
'type': 'boolean',
|
||||
'index': 'not_analyzed',
|
||||
},
|
||||
'path': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed',
|
||||
},
|
||||
}
|
||||
|
||||
search_name = None
|
||||
@ -373,12 +377,16 @@ class Page(MP_Node, ClusterableModel, Indexed):
|
||||
return ('' if current_site.id == id else root_url) + self.url_path[len(root_path) - 1:]
|
||||
|
||||
@classmethod
|
||||
def search(cls, query_string, show_unpublished=False, search_title_only=False, extra_filters={}, prefetch_related=[]):
|
||||
def search(cls, query_string, show_unpublished=False, search_title_only=False, extra_filters={}, prefetch_related=[], path=None):
|
||||
# Filters
|
||||
filters = extra_filters.copy()
|
||||
if not show_unpublished:
|
||||
filters['live'] = True
|
||||
|
||||
# Path
|
||||
if path:
|
||||
filters['path__startswith'] = path
|
||||
|
||||
# Fields
|
||||
fields = None
|
||||
if search_title_only:
|
||||
|
@ -15,7 +15,7 @@ def search(request):
|
||||
|
||||
# Search
|
||||
if query_string != "":
|
||||
search_results = models.Page.search(query_string)
|
||||
search_results = models.Page.search(query_string, path=request.site.root_page.path)
|
||||
|
||||
# Get query object
|
||||
query = Query.get(query_string)
|
||||
@ -50,7 +50,7 @@ def suggest(request):
|
||||
|
||||
# Search
|
||||
if query_string != "":
|
||||
search_results = models.Page.search(query_string, search_title_only=True)[:5]
|
||||
search_results = models.Page.search(query_string, search_title_only=True, path=request.site.root_page.path)[:5]
|
||||
|
||||
# Get list of suggestions
|
||||
suggestions = []
|
||||
|
Loading…
Reference in New Issue
Block a user