Skip to content

Commit

Permalink
PyLucene 7 required.
Browse files Browse the repository at this point in the history
  • Loading branch information
coady committed Sep 5, 2018
1 parent 2255f7c commit 01d7c59
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 48 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ Read the [documentation](http://lupyne.surge.sh).
$ pip install lupyne

# Dependencies
* PyLucene >=6.5 (installed separately)
* PyLucene >=7 (installed separately)
* six

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

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

# Changes
dev
* PyLucene >=7 required

2.0
* PyLucene >=6 required
* Python 3 support
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

version = tuple(map(int, lucene.VERSION.split('.')))
assert version >= (6,), version
assert version >= (7,), version
5 changes: 2 additions & 3 deletions lupyne/engine/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .analyzers import Analyzer
from .queries import Query, DocValues, SpellParser
from .documents import Field, Document, Hits, GroupingSearch
from .utils import long, lucene6, suppress, Atomic, SpellChecker
from .utils import long, suppress, Atomic, SpellChecker


class closing(set):
Expand Down Expand Up @@ -210,7 +210,6 @@ def terms(self, name, value='', stop='', counts=False, distance=0, prefix=0):
return iter([])
term, termsenum = index.Term(name, value), terms.iterator()
if distance:
distance = (float if lucene6 else int)(distance)
terms = termsenum = search.FuzzyTermsEnum(terms, util.AttributeSource(), term, distance, prefix, False)
else:
termsenum.seekCeil(util.BytesRef(value))
Expand Down Expand Up @@ -333,7 +332,7 @@ def spans(self, query, positions=False):
:param positions: optionally include slice positions instead of counts
"""
offset = 0
weight = query.createWeight(self, False, *([1.0] * (not lucene6)))
weight = query.createWeight(self, False, 1.0)
postings = search.spans.SpanWeight.Postings.POSITIONS
for reader in self.readers:
try:
Expand Down
59 changes: 18 additions & 41 deletions lupyne/engine/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from org.apache.pylucene.queryparser.classic import PythonQueryParser
from six import string_types
from six.moves import map, range
from .utils import long, lucene6, method
from .utils import long, method


class Query(object):
Expand Down Expand Up @@ -244,65 +244,42 @@ def within(self, other):
return SpanQuery(spans.SpanWithinQuery, self, other)


class Base(object):
def __init__(self, docvalues, size, type):
self.docvalues, self.size, self.type = docvalues, size, type

def __iter__(self):
return map(self.__getitem__, range(self.size))
class DocValues:
"""DocValues with type conversion."""
class Sorted(object):
def __init__(self, docvalues, size, type):
self.docvalues, self.size, self.type = docvalues, size, type

def select(self, ids):
"""Return mapping of doc ids to values."""
return {id: self[id] for id in sorted(ids)}
def __iter__(self):
return map(self.__getitem__, range(self.size))

def select(self, ids):
"""Return mapping of doc ids to values."""
return {id: self[id] for id in sorted(ids)}

class DocValues: # pragma: no cover
"""DocValues with type conversion."""
class Numeric(Base):
def __getitem__(self, id):
if self.docvalues.advanceExact(id):
return self.type(self.docvalues.longValue())
return self.type(self.docvalues.binaryValue())

Binary = Sorted

class Binary(Numeric):
class Numeric(Sorted):
def __getitem__(self, id):
if self.docvalues.advanceExact(id):
return self.type(self.docvalues.binaryValue())

Sorted = Binary
return self.type(self.docvalues.longValue())

class SortedNumeric(Base):
class SortedNumeric(Sorted):
def __getitem__(self, id):
if self.docvalues.advanceExact(id):
return tuple(self.type(self.docvalues.nextValue()) for _ in range(self.docvalues.docValueCount()))

class SortedSet(Base):
class SortedSet(Sorted):
def __getitem__(self, id):
ords = iter(self.docvalues.nextOrd, self.docvalues.NO_MORE_ORDS)
if self.docvalues.advanceExact(id):
return tuple(self.type(self.docvalues.lookupOrd(ord)) for ord in ords)


if lucene6: # pragma: no cover
class DocValues: # noqa
"""DocValues with type conversion."""
class Numeric(Base):
def __getitem__(self, id):
return self.type(self.docvalues.get(id))

Binary = Sorted = Numeric

class SortedNumeric(Base):
def __getitem__(self, id):
self.docvalues.document = id
return tuple(self.type(self.docvalues.valueAt(index)) for index in range(self.docvalues.count()))

class SortedSet(Base):
def __getitem__(self, id):
self.docvalues.document = id
ords = iter(self.docvalues.nextOrd, self.docvalues.NO_MORE_ORDS)
return tuple(self.type(self.docvalues.lookupOrd(ord)) for ord in ords)


class SpellParser(PythonQueryParser):
"""Inherited lucene QueryParser which corrects spelling.
Expand Down
1 change: 0 additions & 1 deletion lupyne/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from java.lang import Double, Float, Number, Object
from org.apache.lucene import analysis, util
long = int if six.PY3 else long # noqa
lucene6 = lucene.VERSION.startswith('6.')


class Atomic(six.with_metaclass(abc.ABCMeta)):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,10 @@ def test_docvalues():
with pytest.raises(AttributeError):
indexer.docvalues('id')
assert indexer.search().docvalues('title') == {0: 'two'}

indexer.add()
indexer.commit()
assert None in indexer.docvalues('title')
assert None in indexer.docvalues('size', type=int)
assert None in indexer.docvalues('tags')
assert None in indexer.docvalues('sizes', type=int)

0 comments on commit 01d7c59

Please sign in to comment.