Skip to content

Commit

Permalink
PyLucene 7.7 and CherryPy 11 required.
Browse files Browse the repository at this point in the history
  • Loading branch information
coady committed Jun 16, 2019
1 parent 63b9f3c commit 6e877bd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ PyLucene is not `pip` installable.
* [Homebrew](https://brew.sh) formula: `$ brew install coady/tap/pylucene`

# Dependencies
* PyLucene >=7
* PyLucene >=7.7
* six

Optional server extras:
* Python >=3.5
* cherrypy >=10
* cherrypy >=11
* clients >=0.2

# Tests
Expand All @@ -68,6 +68,9 @@ Optional server extras:
$ pytest [--cov]

# Changes
dev
* PyLucene >=7.7 required

2.2
* PyLucene 7.6 supported

Expand Down
2 changes: 1 addition & 1 deletion lupyne/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
from .indexers import IndexSearcher, MultiSearcher, IndexWriter, Indexer # noqa

version = tuple(map(int, lucene.VERSION.split('.')))
assert version >= (7,), version
assert version >= (7, 7), version
7 changes: 5 additions & 2 deletions lupyne/engine/analyzers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
from java.io import StringReader
from java.lang import Float
from java.util import HashMap
Expand All @@ -8,6 +7,10 @@
from org.apache.pylucene.queryparser.classic import PythonQueryParser
from six import string_types
from .utils import method
try:
from typing import Mapping
except ImportError: # pragma: no cover
from collections import Mapping


class TokenStream(analysis.TokenStream):
Expand Down Expand Up @@ -140,7 +143,7 @@ def parse(self, query, field='', op='', parser=None, **attrs):
# parsers aren't thread-safe (nor slow), so create one each time
cls = queryparser.classic.QueryParser if isinstance(field, string_types) else queryparser.classic.MultiFieldQueryParser
args = field, self
if isinstance(field, collections.Mapping):
if isinstance(field, Mapping):
boosts = HashMap()
for key in field:
boosts.put(key, Float(field[key]))
Expand Down
4 changes: 3 additions & 1 deletion lupyne/engine/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ class IndexWriter(index.IndexWriter):
:param version: lucene Version argument passed to IndexWriterConfig, default is latest
:param attrs: additional attributes to set on IndexWriterConfig
"""
__len__ = index.IndexWriter.numDocs
parse = IndexSearcher.__dict__['parse']

def __init__(self, directory=None, mode='a', analyzer=None, version=None, **attrs):
Expand All @@ -505,6 +504,9 @@ def __del__(self):
with suppress(IOException):
self.close()

def __len__(self):
return self.docStats.numDocs

@classmethod
def check(cls, directory, fix=False):
"""Check and optionally fix unlocked index, returning lucene CheckIndex.Status."""
Expand Down
7 changes: 5 additions & 2 deletions lupyne/engine/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
import bisect
import collections
import contextlib
import heapq
import itertools
Expand All @@ -9,14 +8,18 @@
import six
from java.lang import Double, Float, Number, Object
from org.apache.lucene import analysis, util
try:
from typing import Iterable
except ImportError: # pragma: no cover
from collections import Iterable
long = int if six.PY3 else long # noqa


class Atomic(six.with_metaclass(abc.ABCMeta)):
"""Abstract base class to distinguish singleton values from other iterables."""
@classmethod
def __subclasshook__(cls, other):
return not issubclass(other, collections.Iterable) or NotImplemented
return not issubclass(other, Iterable) or NotImplemented


for cls in six.string_types + (analysis.TokenStream, lucene.JArray_byte):
Expand Down
2 changes: 1 addition & 1 deletion lupyne/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@


def HTTPError(exception, status=http.client.BAD_REQUEST):
return cherrypy.HTTPError.handle(exception, int(status))
return cherrypy.HTTPError.handle(exception, status)


@cherrypy.tools.register('before_request_body')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
license='Apache Software License',
packages=['lupyne', 'lupyne.engine'],
install_requires=['six'],
extras_require={'server': ['cherrypy>=10', 'clients>=0.2']},
extras_require={'server': ['cherrypy>=11', 'clients>=0.2']},
python_requires='>=2.7',
tests_require=['pytest-cov'],
classifiers=[
Expand Down
4 changes: 2 additions & 2 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def test_indexes(tempdir):
with engine.Indexer(tempdir) as temp:
temp.add()
with pytest.raises(KeyError), engine.Indexer(tempdir) as temp:
temp.add()
temp.add(missing='')
temp.add()
temp.add(missing='')
for other in (temp, temp.directory, tempdir):
indexer += other
assert len(indexer) == 3
Expand Down

0 comments on commit 6e877bd

Please sign in to comment.