Hi, As Mike says, it is not wanted to call getTermsEnum directly (not on the level of query). The workaround by subclassing does not work because NumericRangeQuery has no constructor, only static factories for the data types.
One correct way to handle all this is (and works with all MultiTermQueries around, so also TermRangeQuery, FuzzyQuery, WildcardQuery,...): Implement your own MultiTermQuery.RewriteMethod. >From this class you implement the way how to rewrite the query to a query with all expanded terms. The trick here is to return to some fake query that contains all the terms. This is done quite often in some special query types that do fancy rewrites: e.g., one that may construct a phrase query containing wildcards. The code is not yet released open source, but works exactly that way - I will open an issue soon, here some code parts: /** A fake query that is just used to collect all term instances for the {@link ScoringRewrite} API. */ final class TermHolderQuery extends Query { private final ArrayList<Term> terms = new ArrayList<Term>(); @Override public String toString(String defaultField) { return getClass().getSimpleName() + terms; } void add(Term term) { terms.add(term); } Term[] getTerms() { return terms.toArray(new Term[terms.size()]); } } final class MultiPhraseMTQRewrite extends ScoringRewrite<TermHolderQuery> { @Override protected void addClause(TermHolderQuery topLevel, Term term, float boost) { topLevel.add(term); } @Override protected TermHolderQuery getTopLevelQuery() { return new TermHolderQuery(); } } But I still think you have an XY problem: Please explain what you want to do originally, so we can help you to implement this in "the Lucene way", without crazy workaround. The above code is used for rewriting a query, so it is not misusing Lucene, but your use case seems strange to me. Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: u...@thetaphi.de > -----Original Message----- > From: Michael McCandless [mailto:luc...@mikemccandless.com] > Sent: Monday, September 30, 2013 10:36 PM > To: chetvora > Cc: Lucene/Solr dev > Subject: Re: NumericRangeTermsEnum > > Well, it was protected just because we didn't think apps needed to call it > directly. > > You could workaround it ... subclass it and add your own public method that > delegates to .getTermsEnum. Or access it via reflection. > > Alternatively, just call Query.rewrite() and the returned Query will reflect > the > terms that the original query had expanded to (though, it may rewrite to > MultiTermQueryWrapperFilter, which won't get you the terms ...). > > But, can you describe more how you plan to create performant filters from > this method? > > Mike McCandless > > http://blog.mikemccandless.com > > > On Mon, Sep 30, 2013 at 1:18 PM, Chet Vora <chetv...@gmail.com> wrote: > > Mike > > > > We want to use the lower level Terms API to create some custom high > > performant filters ... is there any reason why the method > > NumericRangeQuery.getTermsEnum() was made protected in the API as > > opposed to public? > > > > CV > > > > > > On Fri, Sep 27, 2013 at 4:15 PM, Michael McCandless > > <luc...@mikemccandless.com> wrote: > >> > >> Normally you'd create a NumericRangeFilter/Query and just use that? > >> > >> Under the hood, Lucene uses that protected API to visit all matching > >> terms... > >> > >> Mike McCandless > >> > >> http://blog.mikemccandless.com > >> > >> > >> On Thu, Sep 26, 2013 at 9:59 AM, Chet Vora <chetv...@gmail.com> > wrote: > >> > Hi all > >> > > >> > I was trying to use the above enum to do some range search on dates... > >> > this > >> > enum is returned by NumericRangeQuery.getTermsEnum() but I > realized > >> > that this is a protected method of the class and since this is a > >> > final class, I can't see how I can use it. Maybe I'm missing > >> > something ? > >> > > >> > Would appreciate any pointers. > >> > > >> > Thanks > >> > > >> > CV > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional > commands, e-mail: dev-h...@lucene.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org