lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Lalevée <nicolas.lale...@anyware-tech.com>
Subject Decorating a Query
Date Thu, 15 Feb 2007 09:21:06 GMT
Hi,

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 search.search(query), it works. But when I want to filter it :
query = new FilteredQuery(query, filter);
search.search(query);
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 ?

cheers,
Nicolas

-- 
Nicolas LALEVÉE
Solutions & Technologies
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message