# Path: wikked/indexer/base.py
# class WikiIndex(object):
#     """ The search index for the wiki, allowing the user to run queries
#         to find pages.
#     """
#     def start(self, wiki):
#         """ Called when the wiki is started. """
#         pass
# 
#     def init(self, wiki):
#         """ Called when a new wiki is created. """
#         pass
# 
#     def postInit(self):
#         """ Called after a new wiki was created. """
#         pass
# 
#     def reset(self, pages):
#         """ Called when the index should be re-created from scratch
#             based on the given pages. """
#         pass
# 
#     def updatePage(self, page):
#         """ Called when the entry for the given page should be updated
#             with the latest information. """
#         pass
# 
#     def updateAll(self, pages):
#         """ Called when the entries for the given pages should be
#             updated with the latest information. """
#         pass
# 
#     def search(self, query):
#         raise NotImplementedError()
# 
# class HitResult(object):
#     def __init__(self, url, title, hl_text=None):
#         self.url = url
#         self.title = title
#         self.hl_text = hl_text


import os
import os.path
import logging
from .base import WikiIndex, HitResult
from whoosh.analysis import (
    StemmingAnalyzer, CharsetFilter, NgramWordAnalyzer)
from whoosh.fields import Schema, ID, TEXT, STORED
from whoosh.highlight import WholeFragmenter, UppercaseFormatter
from whoosh.index import create_in, open_dir
from whoosh.qparser import QueryParser
from whoosh.support.charset import accent_map

            writer.commit()
        logger.debug("...done updating index.")

    def previewSearch(self, query):
        with self.ix.searcher() as searcher:
            title_qp = QueryParser(
                "title_preview", self.ix.schema).parse(query)
            results = searcher.search(title_qp)
            results.fragmenter = WholeFragmenter()

            hits = []
            for result in results:
                hit = HitResult(
                    result['url'],
                    result.highlights('title_preview', text=result['title']))
                hits.append(hit)
            return hits

    def search(self, query, highlight=True):
        with self.ix.searcher() as searcher:
            title_qp = QueryParser("title", self.ix.schema).parse(query)
            text_qp = QueryParser("text", self.ix.schema).parse(query)
            comp_query = title_qp | text_qp
            results = searcher.search(comp_query)
            if not highlight:
                results.formatter = UppercaseFormatter()

            hits = []
            for result in results:

# Path: wikked/indexer/base.py
# class WikiIndex(object):
#     """ The search index for the wiki, allowing the user to run queries
#         to find pages.
#     """
#     def start(self, wiki):
#         """ Called when the wiki is started. """
#         pass
# 
#     def init(self, wiki):
#         """ Called when a new wiki is created. """
#         pass
# 
#     def postInit(self):
#         """ Called after a new wiki was created. """
#         pass
# 
#     def reset(self, pages):
#         """ Called when the index should be re-created from scratch
#             based on the given pages. """
#         pass
# 
#     def updatePage(self, page):
#         """ Called when the entry for the given page should be updated
#             with the latest information. """
#         pass
# 
#     def updateAll(self, pages):
#         """ Called when the entries for the given pages should be
#             updated with the latest information. """
#         pass
# 
#     def search(self, query):
#         raise NotImplementedError()
# 
# class HitResult(object):
#     def __init__(self, url, title, hl_text=None):
#         self.url = url
#         self.title = title
#         self.hl_text = hl_text


# Path: wikked/indexer/whooshidx.py
import os
import os.path
import logging
from .base import WikiIndex, HitResult
from whoosh.analysis import (
    StemmingAnalyzer, CharsetFilter, NgramWordAnalyzer)
from whoosh.fields import Schema, ID, TEXT, STORED
from whoosh.highlight import WholeFragmenter, UppercaseFormatter
from whoosh.index import create_in, open_dir
from whoosh.qparser import QueryParser
from whoosh.support.charset import accent_map


            writer.commit()
        logger.debug("...done updating index.")

    def previewSearch(self, query):
        with self.ix.searcher() as searcher:
            title_qp = QueryParser(
                "title_preview", self.ix.schema).parse(query)
            results = searcher.search(title_qp)
            results.fragmenter = WholeFragmenter()

            hits = []
            for result in results:
                hit = HitResult(
                    result['url'],
                    result.highlights('title_preview', text=result['title']))
                hits.append(hit)
            return hits

    def search(self, query, highlight=True):
        with self.ix.searcher() as searcher:
            title_qp = QueryParser("title", self.ix.schema).parse(query)
            text_qp = QueryParser("text", self.ix.schema).parse(query)
            comp_query = title_qp | text_qp
            results = searcher.search(comp_query)
            if not highlight:
                results.formatter = UppercaseFormatter()

            hits = []
            for result in results:

                hit = HitResult(