# Path: sesql/config.py
# CONFIG_PATH_FALLBACK = 'sesql_config'
#     CONFIG_PATH = getattr(settings, 'SESQL_CONFIG_PATH', CONFIG_PATH_FALLBACK)
#     CONFIG_PATH = CONFIG_PATH_FALLBACK
# 
# Path: sesql/lemmatize.py
# def lemmatize(words, index = None):
#     """
#     Give a lemmatized version of those words
# 
#     Use the configuration for the given index, or the default one if
#     index is None
#     """
#     if index is None:
#         index = fieldmap.primary
# 
#     if index is None:
#         raise ValueError, "Not index given and no primary one"
# 
#     words = [ index.marshall(word) for word in words ]
# 
#     index = fieldmap.get_field(index)
#     return lemmatize_for(words, index.dictionnary)
# 
# Path: sesql/models.py
# class SearchHit(models.Model):
#     """Used to store queries made to the search engine"""
#     query = models.CharField(max_length=500)
#     nb_results = models.PositiveIntegerField()
#     date = models.DateField(auto_now=True)
# 
# Path: sesql/models.py
# class SearchQuery(models.Model):
#     """A table containing statistics and scores about search queries"""
#     query = models.CharField(max_length=500)
#     phonex = models.FloatField()
#     clean_query = models.CharField(max_length=500)
#     clean_phonex = models.FloatField()
#     
#     nb_results = models.PositiveIntegerField()
#     
#     nb_recent_search = models.PositiveIntegerField()
#     nb_total_search = models.PositiveIntegerField()
#     pondered_search_nb = models.FloatField()
#     
#     weight = models.FloatField()
# 
# Path: sesql/models.py
# class SearchHitHistoric(models.Model):
#     """Same as SearchHit used as an archive"""
#     query = models.CharField(max_length=500)
#     nb_results = models.PositiveIntegerField()
#     date = models.DateField(auto_now=True, db_index=True)
# 
# Path: sesql/suggest.py
# def levenshtein(a, b):


from optparse import make_option
from django.core.management.base import BaseCommand
from sesql import config
from sesql.lemmatize import lemmatize
from sesql.models import SearchHit
from sesql.models import SearchQuery
from sesql.models import SearchHitHistoric
from sesql.suggest import phonex

# Copyright (c) Pilot Systems and Libération, 2011

# This file is part of SeSQL.

# SeSQL is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# SeSQL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with SeSQL.  If not, see <http://www.gnu.org/licenses/>.
"""
This should be runned in a cron to process search histories and compute stats
"""




class Command(BaseCommand):
    help = """Build SearchQuery index"""

    option_list = BaseCommand.option_list + (
        make_option('-e','--erode',
                    action='store_true',

# Path: sesql/config.py
# CONFIG_PATH_FALLBACK = 'sesql_config'
#     CONFIG_PATH = getattr(settings, 'SESQL_CONFIG_PATH', CONFIG_PATH_FALLBACK)
#     CONFIG_PATH = CONFIG_PATH_FALLBACK
# 
# Path: sesql/lemmatize.py
# def lemmatize(words, index = None):
#     """
#     Give a lemmatized version of those words
# 
#     Use the configuration for the given index, or the default one if
#     index is None
#     """
#     if index is None:
#         index = fieldmap.primary
# 
#     if index is None:
#         raise ValueError, "Not index given and no primary one"
# 
#     words = [ index.marshall(word) for word in words ]
# 
#     index = fieldmap.get_field(index)
#     return lemmatize_for(words, index.dictionnary)
# 
# Path: sesql/models.py
# class SearchHit(models.Model):
#     """Used to store queries made to the search engine"""
#     query = models.CharField(max_length=500)
#     nb_results = models.PositiveIntegerField()
#     date = models.DateField(auto_now=True)
# 
# Path: sesql/models.py
# class SearchQuery(models.Model):
#     """A table containing statistics and scores about search queries"""
#     query = models.CharField(max_length=500)
#     phonex = models.FloatField()
#     clean_query = models.CharField(max_length=500)
#     clean_phonex = models.FloatField()
#     
#     nb_results = models.PositiveIntegerField()
#     
#     nb_recent_search = models.PositiveIntegerField()
#     nb_total_search = models.PositiveIntegerField()
#     pondered_search_nb = models.FloatField()
#     
#     weight = models.FloatField()
# 
# Path: sesql/models.py
# class SearchHitHistoric(models.Model):
#     """Same as SearchHit used as an archive"""
#     query = models.CharField(max_length=500)
#     nb_results = models.PositiveIntegerField()
#     date = models.DateField(auto_now=True, db_index=True)
# 
# Path: sesql/suggest.py
# def levenshtein(a, b):


# Path: sesql/management/commands/build_search_query_index.py
from optparse import make_option
from django.core.management.base import BaseCommand
from sesql import config
from sesql.lemmatize import lemmatize
from sesql.models import SearchHit
from sesql.models import SearchQuery
from sesql.models import SearchHitHistoric
from sesql.suggest import phonex


# Copyright (c) Pilot Systems and Libération, 2011

# This file is part of SeSQL.

# SeSQL is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# SeSQL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with SeSQL.  If not, see <http://www.gnu.org/licenses/>.
"""
This should be runned in a cron to process search histories and compute stats
"""




class Command(BaseCommand):
    help = """Build SearchQuery index"""

    option_list = BaseCommand.option_list + (
        make_option('-e','--erode',
                    action='store_true',

                    dest='erode',