coady avatar coady committed 786d6be

PyLucene 3.6 supported.

Comments (0)

Files changed (5)

 Lupyne should run anywhere PyLucene does, though its primary testing is on the popular unix variants.
 
  * Python 2.6.6+, 2.7
- * PyLucene 3.2, 3.3, 3.4, 3.5
+ * PyLucene 3.2, 3.3, 3.4, 3.5, 3.6
  * CherryPy 3.1.2+, 3.2 (only required for server)
 
 Usage

lupyne/engine/indexers.py

     def count(self, name, value):
         "Return number of documents with given term."
         return self.docFreq(lucene.Term(name, value))
-    def names(self, option='all'):
-        "Return field names, given option description."
-        option = getattr(self.FieldOption, option.upper())
-        return list(self.getFieldNames(option))
+    def names(self, option='all', **attrs):
+        "Return field names, given option description or as of lucene 3.6 FieldInfo attributes to filter."
+        if hasattr(lucene.IndexReader, 'getFieldNames'):
+            return list(self.getFieldNames(getattr(self.FieldOption, option.upper())))
+        fieldinfos = lucene.ReaderUtil.getMergedFieldInfos(self.indexReader).iterator()
+        return [fieldinfo.name for fieldinfo in fieldinfos if all(getattr(fieldinfo, name) == attrs[name] for name in attrs)]
     def terms(self, name, value='', stop=None, counts=False, **fuzzy):
         """Generate a slice of term values, optionally with frequency counts.
         Supports a range of terms, wildcard terms, or fuzzy terms.
     def highlighter(self, query, field, **kwargs):
         "Return `Highlighter`_ or if applicable `FastVectorHighlighter`_ specific to searcher and query."
         query = self.parse(query, field=field)
-        vector = field in self.names('termvector_with_position_offset')
+        vector = field in self.names('termvector_with_position_offset', storeTermVector=True)
         return (FastVectorHighlighter if vector else Highlighter)(self, query, field, **kwargs)
     def count(self, *query, **options):
         """Return number of hits for given query or term.
 ==================
  * Engine:
    
+   - PyLucene 3.6 supported
    - PyLucene 3.1 deprecated
    - Support for all IndexWriterConfig options
 
         assert not list(indexer.termvector(0, 'tag'))
         assert indexer.count('text', 'hello') == indexer.count('text:hello') == 1
         assert sorted(indexer.names()) == ['name', 'tag', 'text']
-        assert sorted(indexer.names('indexed')) == ['tag', 'text']
-        assert indexer.names('unindexed') == ['name']
+        assert sorted(indexer.names('indexed', isIndexed=True)) == ['tag', 'text']
+        assert indexer.names('unindexed', isIndexed=False) == ['name']
         assert list(indexer.terms('text')) == ['hello', 'world']
         assert list(indexer.terms('text', 'h', 'v')) == ['hello']
         assert dict(indexer.terms('text', 'w', counts=True)) == {'world': 1}
         assert indexer.search('text:hello hi') and not indexer.search('text:hello hi', op='and')
         assert indexer.search('text:*hello', allowLeadingWildcard=True)
         query = engine.Query.multiphrase('text', ('hello', 'hi'), None, 'world')
-        assert str(query) == 'text:"(hello hi) world"' and list(query.positions) == [0, 2]
+        assert str(query).startswith('text:"(hello hi) ') and list(query.positions) == [0, 2]
         query = engine.Query.wildcard('text', '*')
         assert str(query) == 'text:*' and isinstance(query, lucene.WildcardQuery)
         assert str(lucene.MatchAllDocsQuery() | query) == '*:* text:*'
                 location = '.'.join(doc[name] for name in ['state', 'county', 'city'])
                 indexer.add(doc, latitude=lat, longitude=lng, location=location)
         indexer.commit()
-        assert set(['state', 'zipcode']) < set(indexer.names('indexed'))
-        assert set(['latitude', 'longitude', 'county', 'city']) == set(indexer.names('unindexed'))
+        assert set(['state', 'zipcode']) < set(indexer.names('indexed', isIndexed=True))
+        assert set(['latitude', 'longitude', 'county', 'city']) == set(indexer.names('unindexed', isIndexed=False))
         states = list(indexer.terms('state'))
         assert states[0] == 'AK' and states[-1] == 'WY'
         counties = [term.split('.')[-1] for term in indexer.terms('state.county', 'CA', 'CA~')]
         assert resource.get('/docs/0', fields='missing') == {'missing': None}
         assert resource.get('/docs/0', fields='', **{'fields.multi': 'missing'}) == {'missing': []}
         assert resource.get('/terms') == ['name', 'text']
-        assert resource.get('/terms', option='unindexed') == []
+        assert resource.get('/terms', option='unindexed', isIndexed=False) == []
         assert resource.get('/terms/text') == ['hello', 'world']
         assert resource.get('/terms/text/world') == 1
         with assertRaises(httplib.HTTPException, httplib.BAD_REQUEST):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.