Skip to content

Commit

Permalink
Minify JSON to improve search speed
Browse files Browse the repository at this point in the history
  • Loading branch information
talha131 committed Nov 10, 2013
1 parent c5788c8 commit baa90d8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tipue_search/tipue_search.py
Expand Up @@ -33,10 +33,12 @@ def create_json_node(self, page):
if getattr(page, 'status', 'published') != 'published':
return

page_title = page.title
soup_title = BeautifulSoup(page.title.replace(' ', ' '))
page_title = soup_title.get_text(' ', strip=True).replace('“', '"').replace('”', '"').replace('’', "'")

soup = BeautifulSoup(page.content, 'html.parser')
page_text = soup.get_text()
soup_text = BeautifulSoup(page.content)
page_text = soup_text.get_text(' ', strip=True).replace('“', '"').replace('”', '"').replace('’', "'").replace('¶', ' ')
page_text = ' '.join(page_text.split())

if getattr(page, 'category') == 'None':
page_category = ''
Expand Down Expand Up @@ -65,7 +67,7 @@ def generate_output(self, writer):
root_node = {'pages': self.json_nodes}

with open(path, 'w', encoding='utf-8') as fd:
json.dump(root_node, fd, indent=4)
json.dump(root_node, fd, separators=(',', ':'))


def get_generators(generators):
Expand Down

0 comments on commit baa90d8

Please sign in to comment.