[pylucene-dev] Prohibited field query

Georges Racinet gracinet at nuxeo.com
Mon Dec 11 05:20:22 PST 2006


Hi everyone !

First post to the list, I'd like to congratulate first PyLucene devs  
for the good piece of integration that PyLucene is.

I'm trying to fire a prohibited request on a field
I've tried many things, including going through QueryParser, nothing  
worked so far (I always get 0 matches, which is wrong).
This is on PyLucene 1.9.1 (upgrading isn't a option, sadly).

Say I want documents for which the value of the field 'status' is  
"hidden" *not* to match (the end use-case will actually need  
intersection with clauses on other fields ).

QueryParser attempts:
 >>> anal = PyLucene.KeyWordAnalyser()
 >>> query = PyLucene.QueryParser('status', anal).parseQuery(query_str)

wih query_str being:
	"-status:hidden"           (*** Fault: <Fault 8002: 'error'>)
	"status:-hidden"
	"status:(-hidden)"
	"-hidden" (after all, the field is already specified in the instance  
constructor)

My latest programatic attempt is:
 >>> anal = PyLucene.KeyWordAnalyzer()
 >>> b_query = PyLucene.TermQuery(PyLucene.Term("status", 'hidden'))
 >>> n_query = PyLucene.BooleanQuery()
 >>> n_query.add(PyLucene.BooleanClause(b_query, False, True))

Here's what toString says:
 >>> n_query.toString()
'-status:hidden'

which is also exactly what I got for the three latest values of  
query_str fed to QueryParser.

The search call itself is done as following: (the searcher object is  
a LuceneSearcher instance that
works as expected if I use it, e.g., on the simpler b_query instead  
of n_query).

 >>> query = n_query
 >>> hits = searcher.get().search(query, PyLucene.Sort.RELEVANCE)
 >>> hits.length()
0

I'm a bit worried that the QueryParser syntax documentation at
http://lucene.apache.org/java/docs/queryparsersyntax.html#NOT
does give examples of the '-' and 'NOT' syntaxes,  of which none is  
per-field...
So, I'm wondering.... is this actually supposed to work ?

Any help or hint would be greatly appreciated !

Many thanks,
---------
Georges Racinet,   Nuxeo SAS
Open Source Enterprise Content Management (ECM)
Web: http://www.nuxeo.com/ and http://www.nuxeo.org/ - Tel: +33 1 40  
33 79 87





More information about the pylucene-dev mailing list