lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Lalevée <>
Subject Decorating a Query
Date Thu, 15 Feb 2007 09:21:06 GMT

I wanted to implement my own query, query wich will be specific to my 
application. The query I want to implement is in fact just a combinaison of 
sevral already implemented queries. So acheive this, I do this kind of 
things :
public class MyQuery extends Query {
  private Query query;
  public MyQuery(String foo) {
    query = new TermQuery("myfield", foo);
  public Weight weight(Searcher searcher) throws IOException {
    return query.weight(searcher);
  public String toString(String field) {
    return foo;

But I have an issue with that kind of queries : I cannot implement 
createWeight() as I cannot access this function on the underlying query. So 
the Query's function is used with raise a UnsupportedOperationException. For 
basic, it works. But when I want to filter it :
query = new FilteredQuery(query, filter);;
This raise the UnsupportedOperationException.

I just see two options there.
* make my own interface which is a factory of query. But I lost the 
flexibility of extending Query. Even if I want to do a little term query, I 
will have to make a factory of this term query.
* patch Lucene to make createWeight() public

any other advise ?


Solutions & Technologies
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message