Commits

Matt Chaput committed 96fef81

Added logger objects to modules.

  • Participants
  • Parent commits ac6474d
  • Branches logging

Comments (0)

Files changed (41)

src/whoosh/analysis.py

 a filter first or a tokenizer after the first item).
 """
 
-import re
+import re, logging
 from collections import deque
 from itertools import chain
 
 from whoosh.util import lru_cache, unbound_cache, rcompile
 
 
+log = logging.getLogger(__name__)
+
+
 # Default list of stop words (words so common it's usually wasteful to index
 # them). This list is used by the StopFilter class, which allows you to supply
 # an optional list to override this one.

src/whoosh/codec/base.py

 # policies, either expressed or implied, of Matt Chaput.
 
 
-import random
+import logging, random
 from array import array
 from struct import Struct, pack
 from bisect import bisect_right
     can_compress = False
 
 
+log = logging.getLogger(__name__)
+
+
 # Base classes
 
 class Codec(object):

src/whoosh/codec/legacy.py

 # policies, either expressed or implied, of Matt Chaput.
 
 
+import logging
 from array import array
 from struct import Struct
 
     pass
 
 
+log = logging.getLogger(__name__)
+
+
 # Old field lengths format
 
 def load_old_lengths(obj, dbfile, doccount):

src/whoosh/codec/whoosh2.py

 # policies, either expressed or implied, of Matt Chaput.
 
 
+import logging
 from array import array
 from collections import defaultdict
 from struct import Struct
 from whoosh.util import byte_to_length, length_to_byte, utf8encode, utf8decode
 
 
+log = logging.getLogger(__name__)
+
+
 # Standard codec top-level object
 
 class W2Codec(base.Codec):

src/whoosh/fields.py

 """ Contains functions and classes related to fields.
 """
 
-import datetime, fnmatch, re, struct, sys
+import datetime, fnmatch, logging, re, struct, sys
 from decimal import Decimal
 
 from whoosh import formats
 from whoosh.support.times import datetime_to_long
 
 
+log = logging.getLogger(__name__)
+
+
 # "Default" values to indicate missing values when sorting and faceting numeric
 # fields. There's no "out-of-band" value possible (except for floats, where we
 # use NaN), so we try to be conspicuous at least by using the maximum possible
                                           "underscore")
         if " " in name:
             raise FieldConfigurationError("Field names cannot contain spaces")
-        if name in self._fields or (glob and name in self._dyn_fields):
+        if (name in self._fields) or (glob and name in self._dyn_fields):
             raise FieldConfigurationError("Schema already has a field %r"
                                           % name)
 

src/whoosh/filedb/compound.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import errno, mmap, sys
+import errno, logging, mmap, sys
 from threading import Lock
 from shutil import copyfileobj
 
 from whoosh.system import emptybytes
 
 
+log = logging.getLogger(__name__)
+
+
 class CompoundStorage(FileStorage):
     readonly = True
 

src/whoosh/filedb/fieldcache.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import with_statement
-import threading
-import weakref
+import logging, threading, weakref
 from array import array
 from collections import defaultdict
 from heapq import heappush, heapreplace
 from whoosh.util import utf8encode
 
 
+log = logging.getLogger(__name__)
+
+
 pack_int_le = Struct("<i").pack
 
 

src/whoosh/filedb/fileindex.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import re, sys
+import logging, re, sys
 from time import time, sleep
 
 from whoosh import __version__
 from whoosh.system import _INT_SIZE, _FLOAT_SIZE, _LONG_SIZE
 
 
+log = logging.getLogger(__name__)
+
+
 _INDEX_VERSION = -110
 
 

src/whoosh/filedb/filereading.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
+import logging
 from bisect import bisect_left
 
 from whoosh.compat import iteritems, xrange
 from whoosh.support import dawg
 
 
+log = logging.getLogger(__name__)
+
+
 SAVE_BY_DEFAULT = True
 
 

src/whoosh/filedb/filestore.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import os
+import logging, os
 from threading import Lock
 
 from whoosh.compat import BytesIO
 from whoosh.filedb.structfile import StructFile
 
 
+log = logging.getLogger(__name__)
+
+
 class ReadOnlyError(Exception):
     pass
 

src/whoosh/filedb/filetables.py

 D. J. Bernstein's CDB format (http://cr.yp.to/cdb.html).
 """
 
+import logging
 from binascii import crc32
 from collections import defaultdict
-from hashlib import md5  #@UnresolvedImport
+from hashlib import md5  # @UnresolvedImport
 from struct import Struct
 
 from whoosh.compat import long_type, xrange, b, bytes_type
 from whoosh.system import _INT_SIZE, _LONG_SIZE
 
 
+log = logging.getLogger(__name__)
+
+
 _4GB = 4 * 1024 * 1024 * 1024
 
 

src/whoosh/filedb/filewriting.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import with_statement
+import logging
 from bisect import bisect_right
 
 from whoosh.fields import UnknownFieldError
 from whoosh.writing import IndexWriter, IndexingError
 
 
+log = logging.getLogger(__name__)
+
+
 # Merge policies
 
 # A merge policy is a callable that takes the Index object, the SegmentWriter

src/whoosh/filedb/gae.py

     ix = DataStoreStorage().open_index()
 """
 
-from google.appengine.api import memcache  #@UnresolvedImport
-from google.appengine.ext import db  #@UnresolvedImport
+import logging
+from google.appengine.api import memcache  # @UnresolvedImport
+from google.appengine.ext import db  # @UnresolvedImport
 
 from whoosh.compat import BytesIO
 from whoosh.store import Storage
 from whoosh.filedb.structfile import StructFile
 
 
+log = logging.getLogger(__name__)
+
+
 class DatastoreFile(db.Model):
     """A file-like object that is backed by a BytesIO() object whose contents
     is loaded from a BlobProperty in the app engine datastore.

src/whoosh/filedb/multiproc.py

 # policies, either expressed or implied, of Matt Chaput.
 
 
-import os, tempfile
+import logging, os, tempfile
 from multiprocessing import Process, Queue, cpu_count
 
 from whoosh.compat import xrange, iteritems, pickle
 from whoosh.support.externalsort import imerge
 
 
+log = logging.getLogger(__name__)
+
+
 def finish_subsegment(writer, k=64):
     # Tell the pool to finish up the current file
     writer.pool.save()

src/whoosh/filedb/structfile.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import os
+import logging, os
 from array import array
 from copy import copy
 from struct import calcsize
                          decode_signed_varint, float_to_byte, byte_to_float)
 
 
+log = logging.getLogger(__name__)
+
+
 _SIZEMAP = dict((typecode, calcsize(typecode)) for typecode in "bBiIhHqQf")
 _ORDERMAP = {"little": "<", "big": ">"}
 

src/whoosh/formats.py

 occurance of a term.
 """
 
+import logging
 from collections import defaultdict
 
 from whoosh.analysis import unstopped, entoken
                            pack_float, unpack_float)
 
 
+log = logging.getLogger(__name__)
+
+
 # Format base class
 
 class Format(object):

src/whoosh/highlight.py

 """
 
 from __future__ import division
+import logging
 from collections import deque
 from heapq import nlargest
 from cgi import escape as htmlescape
 from whoosh.analysis import Token
 
 
+log = logging.getLogger(__name__)
+
+
 # The default value for the maximum chars to examine when fragmenting
 DEFAULT_CHARLIMIT = 2 ** 15
 
         self.qname = qname
         self.between = between
 
-        from genshi.core import START, END, TEXT  #@UnresolvedImport
-        from genshi.core import Attrs, Stream  #@UnresolvedImport
+        from genshi.core import START, END, TEXT  # @UnresolvedImport
+        from genshi.core import Attrs, Stream  # @UnresolvedImport
         self.START, self.END, self.TEXT = START, END, TEXT
         self.Attrs, self.Stream = Attrs, Stream
 

src/whoosh/index.py

 """
 
 from __future__ import division
-import os.path
-import sys
+import logging, os.path, sys
+
+
+log = logging.getLogger(__name__)
 
 
 _DEF_INDEX_NAME = "MAIN"
 
     if indexname is None:
         indexname = _DEF_INDEX_NAME
+    log.debug("Opening index %s in %s", indexname, dirname)
 
     from whoosh.filedb.filestore import FileStorage
     storage = FileStorage(dirname, readonly=readonly)

src/whoosh/matching/binary.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
+import logging
+
 from whoosh.matching import mcore
 
 
+log = logging.getLogger(__name__)
+
+
 class BiMatcher(mcore.Matcher):
     """Base class for matchers that combine the results of two sub-matchers in
     some way.

src/whoosh/matching/mcore.py

 method will return ``True``.
 """
 
-import sys
+import logging, sys
 from itertools import repeat
 
 from whoosh.compat import izip, xrange
 from whoosh.compat import abstractmethod
 
 
+log = logging.getLogger(__name__)
+
+
 # Exceptions
 
 class ReadTooFar(Exception):

src/whoosh/matching/wrappers.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import sys
+import logging, sys
 from whoosh.compat import xrange
 from whoosh.matching import mcore
 
 
+log = logging.getLogger(__name__)
+
+
 class WrappingMatcher(mcore.Matcher):
     """Base class for matchers that wrap sub-matchers.
     """

src/whoosh/qparser/dateparse.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import re
-import sys
+import logging, re, sys
 from datetime import datetime, timedelta
 
 from whoosh.compat import string_type, iteritems
 from whoosh.util import rcompile
 
 
+log = logging.getLogger(__name__)
+
+
 class DateParseError(Exception):
     "Represents an error in parsing date text."
 

src/whoosh/qparser/default.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import sys
+import logging, sys
 
 from whoosh import query
 from whoosh.qparser import syntax
 from whoosh.qparser.common import print_debug, QueryParserError
 
 
+log = logging.getLogger(__name__)
+
+
 # Query parser object
 
 class QueryParser(object):

src/whoosh/qparser/plugins.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import copy
+import copy, logging
 
 from whoosh import query
 from whoosh.compat import iteritems, u, PY3
 from whoosh.util import rcompile
 
 
+log = logging.getLogger(__name__)
+
+
 class Plugin(object):
     """Base class for parser plugins.
     """

src/whoosh/qparser/syntax.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import sys, weakref
+import logging, sys, weakref
 
 from whoosh import query
 from whoosh.qparser.common import get_single_text, QueryParserError, attach
 
 
+log = logging.getLogger(__name__)
+
+
 class SyntaxNode(object):
     """Base class for nodes that make up the abstract syntax tree (AST) of a
     parsed user query string. The AST is an intermediate step, generated

src/whoosh/qparser/taggers.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
+import logging
+
 from whoosh.util import rcompile
 
 
+log = logging.getLogger(__name__)
+
+
 # Tagger objects
 
 class Tagger(object):
 
     def match(self, parser, text, pos):
         """This method should see if this tagger matches the query string at
-        the given position. If it matches, it should return 
+        the given position.
         
         :param parser: the :class:`whoosh.qparser.default.QueryParser` object.
         :param text: the text being parsed.

src/whoosh/query/nary.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import division
+import logging
 
 from whoosh import matching
 from whoosh.compat import text_type, u
 from whoosh.util import make_binary_tree, make_weighted_tree
 
 
+log = logging.getLogger(__name__)
+
+
 class CompoundQuery(qcore.Query):
     """Abstract base class for queries that combine or manipulate the results
     of multiple sub-queries .

src/whoosh/query/nested.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
+import logging
+
 from whoosh import matching
 from whoosh.compat import text_type, u, xrange
 from whoosh.query import qcore
 from whoosh.query.wrappers import WrappingQuery
 
 
+log = logging.getLogger(__name__)
+
+
 class NestedParent(WrappingQuery):
     """A query that allows you to search for "nested" documents, where you can
     index (possibly multiple levels of) "parent" and "child" documents using

src/whoosh/query/positional.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import division
-import copy
+import copy, logging
 
 from whoosh import matching
 from whoosh.analysis import Token
 from whoosh.query import qcore, terms, nary
 
 
+log = logging.getLogger(__name__)
+
+
 class Phrase(qcore.Query):
     """Matches documents containing a given phrase."""
 

src/whoosh/query/qcore.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import division
-import copy
+import copy, logging
 from array import array
 
 from whoosh import matching
 from whoosh.compat import methodcaller
 
 
+log = logging.getLogger(__name__)
+
+
 # Exceptions
 
 class QueryError(Exception):

src/whoosh/query/ranges.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import division
+import logging
 
 from whoosh.compat import u
 from whoosh.query import qcore, terms, nary, wrappers
 from whoosh.support.times import datetime_to_long
 
 
+log = logging.getLogger(__name__)
+
+
 class RangeMixin(object):
     # Contains methods shared by TermRange and NumericRange
 

src/whoosh/query/terms.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import division
-import copy, fnmatch, re
+import copy, fnmatch, logging, re
 from collections import defaultdict
 
 from whoosh import matching
 from whoosh.query import qcore
 
 
+log = logging.getLogger(__name__)
+
+
 class Term(qcore.Query):
     """Matches documents containing the given term (fieldname+text pair).
 

src/whoosh/query/wrappers.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import division
+import logging
 from array import array
 
 from whoosh import matching
 from whoosh.query import qcore
 
 
+log = logging.getLogger(__name__)
+
+
 class WrappingQuery(qcore.Query):
     def __init__(self, child):
         self.child = child

src/whoosh/reading.py

 """This module contains classes that allow reading from an index.
 """
 
-from math import log
+import logging, math
 from bisect import bisect_right
 from heapq import heapify, heapreplace, heappop, nlargest
 
 from whoosh.compat import abstractmethod
 
 
+log = logging.getLogger(__name__)
+
+
 # Exceptions
 
 class TermNotFound(Exception):
         """
 
         N = float(self.doc_count())
-        gen = ((terminfo.weight() * log(N / terminfo.doc_frequency()), text)
-               for text, terminfo in self.iter_prefix(fieldname, prefix))
+        gen = ((ti.weight() * math.log(N / ti.doc_frequency()), text)
+               for text, ti in self.iter_prefix(fieldname, prefix))
         return nlargest(number, gen)
 
     def leaf_readers(self):
     def terms_within(self, fieldname, text, maxdist, prefix=0):
         tset = set()
         for r in self.readers:
-            tset.update(r.terms_within(fieldname, text, maxdist, prefix=prefix))
+            tset.update(r.terms_within(fieldname, text, maxdist,
+                                       prefix=prefix))
         return tset
 
     def format(self, fieldname):

src/whoosh/scoring.py

 """
 
 from __future__ import division
-from math import log, pi
+import logging, math
+from whoosh.compat import iteritems
 
-from whoosh.compat import iteritems
+
+log = logging.getLogger(__name__)
 
 
 # Base classes
         parent = searcher.get_parent()
         n = parent.doc_frequency(fieldname, text)
         dc = parent.doc_count_all()
-        return log(dc / (n + 1)) + 1
+        return math.log(dc / (n + 1)) + 1
 
     def scorer(self, searcher, fieldname, text, qf=1):
         """Returns an instance of :class:`whoosh.scoring.Scorer` configured
 
 class WeightScorer(BaseScorer):
     """A scorer that simply returns the weight as the score. This is useful
-    for more complex weighting models to return when they are asked for a 
+    for more complex weighting models to return when they are asked for a
     scorer for fields that aren't scorable (don't store field lengths).
     """
 
     prior = tf / dl
     post = (tf + 1.0) / (dl + 1.0)
     invpriorcol = fl / cf
-    norm = tf * log(post / prior)
+    norm = tf * math.log(post / prior)
 
-    return qf * norm * (tf * (log(prior * invpriorcol))
-                        + (tf + 1.0) * (log(post * invpriorcol))
-                        + 0.5 * log(post / prior))
+    return qf * norm * (tf * (math.log(prior * invpriorcol))
+                        + (tf + 1.0) * (math.log(post * invpriorcol))
+                        + 0.5 * math.log(post / prior))
 
 
 class DFree(WeightingModel):
 
 # PL2 model
 
-rec_log2_of_e = 1.0 / log(2)
+rec_log2_of_e = 1.0 / math.log(2)
 
 
 def pl2(tf, cf, qf, dc, fl, avgfl, c):
     # avgfl - average field length across all documents
     # c -free parameter
 
-    TF = tf * log(1.0 + (c * avgfl) / fl)
+    TF = tf * math.log(1.0 + (c * avgfl) / fl)
     norm = 1.0 / (TF + 1.0)
     f = cf / dc
-    return norm * qf * (TF * log(1.0 / f)
+    return norm * qf * (TF * math.log(1.0 / f)
                         + f * rec_log2_of_e
-                        + 0.5 * log(2 * pi * TF)
-                        + TF * (log(TF) - rec_log2_of_e))
+                        + 0.5 * math.log(2 * math.pi * TF)
+                        + TF * (math.log(TF) - rec_log2_of_e))
 
 
 class PL2(WeightingModel):
 #class PositionWeighting(WeightingModel):
 #    def __init__(self, reversed=False):
 #        self.reversed = reversed
-#        
+#
 #    def scorer(self, searcher, fieldname, text, qf=1):
 #        return PositionWeighting.PositionScorer()
-#    
+#
 #    class PositionScorer(BaseScorer):
 #        def score(self, matcher):
 #            p = min(span.pos for span in matcher.spans())

src/whoosh/searching.py

 
 
 from __future__ import division
-import copy
-import threading
-import weakref
+import copy, logging, threading, weakref
 from collections import defaultdict
 from heapq import heappush, heapreplace, nlargest, nsmallest
 from math import ceil
 from whoosh.util import now, lru_cache
 
 
+log = logging.getLogger(__name__)
+
+
 class TimeLimit(Exception):
     pass
 

src/whoosh/sorting.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
+import logging
 from array import array
 from collections import defaultdict
 
                                   timedelta_to_usecs)
 
 
+log = logging.getLogger(__name__)
+
+
 # Faceting objects
 
 class FacetType(object):

src/whoosh/spans.py

 
 """
 
+import logging
+
 from whoosh.matching import mcore, wrappers, binary
 from whoosh.query import Query, And, AndMaybe, Or, Term
 from whoosh.util import make_binary_tree
 
 
+log = logging.getLogger(__name__)
+
+
 # Span class
 
 class Span(object):

src/whoosh/spelling.py

 """This module contains helper functions for correcting typos in user queries.
 """
 
+import logging
 from collections import defaultdict
 from heapq import heappush, heapreplace
 
 from whoosh.util import utf8encode
 
 
+log = logging.getLogger(__name__)
+
+
 # Corrector objects
 
 class Corrector(object):

src/whoosh/store.py

 # those of the authors and should not be interpreted as representing official
 # policies, either expressed or implied, of Matt Chaput.
 
-import random
+import logging, random
+
+
+log = logging.getLogger(__name__)
 
 
 class LockError(Exception):

src/whoosh/writing.py

 # policies, either expressed or implied, of Matt Chaput.
 
 from __future__ import with_statement
-import threading
-import time
+import logging, threading, time
 from contextlib import contextmanager
 
 from whoosh.compat import abstractmethod
 from whoosh.util import synchronized
 
 
+log = logging.getLogger(__name__)
+
+
 # Exceptions
 
 class IndexingError(Exception):