You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Ricardo Borillo Domenech <Ri...@si.uji.es> on 2005/10/26 14:15:01 UTC

FilteredQuery usage

Hi all!!

I'm using PrefixQuery in my search application and I get TooManyClauses.
I have found many information about this problem and the solutions seems
to be the use of a FilteredQuery.

Now, I'm trying to write my Filter ...
Well, the problem is that when i try to write the "bits" function of my
filter, I need to query all the index checking if the value of field
name "path" is a prefix or not.

There's a way to do that query without having to retrieve all the
Document instances from the index?

public class PrefijoURLFilter extends Filter
{
    private String field;
    private String[] prefix;
    
    public PrefijoURLFilter(String field, String[] prefix)
    {
        this.field = field;
        this.prefix = prefix;
    }
    
    public BitSet bits(IndexReader reader) throws IOException
    {
        BitSet bits = new BitSet(reader.maxDoc());

	//FOR EACH PREFIX AND FOR EACH DOCUMENT IN INDEX CHECK IF 
	//STARTS WITH A VALID PREFIX AND SET IT IN THE BITSET
        
        return bits;
    }
}


A valid usage of this filter could be:

filter = new PrefijoURLFilter("path", new String[] {
	"http://xxx/CA/noticies/agenda/",
	"http://xxx/noticies/agenda/",
	"http://xxx/CA/content/agenda/",
    	"http://xxx/content/agenda/"
});

Thanks a lot!!!

-- 
Salut,
====================================
Ricardo Borillo Domenech
Analista/Programador - Servei d'Informàtica
Universitat Jaume I
http://xml-utils.com

Re: FilteredQuery usage

Posted by Chris Hostetter <ho...@fucit.org>.
: filter, I need to query all the index checking if the value of field
: name "path" is a prefix or not.
:
: There's a way to do that query without having to retrieve all the
: Document instances from the index?

Yep, you're definitely on the right track.  You don't need to retrieve any
documents at all, you just need to look at all of hte indexed terms in
your field, and find the ones that match your prefix.  I would start by
trying to write a Filter that only deals with one prefix (not an array of
prefixes) and when you get that working, then you can then combine several
of them using a ChainedFilter, or expand your filter to opperate on
an array/set of prefixes instead.

Start by taking a look at the way RangeFilter works for an example of how
to use a TermEnum and a TermDocs to collect the list of documentIds that
have values indexed between two terms.  The main difference between what
you want to do, and what is done in RangeFilter, is that instead of
looking for all terms between "a" and "b" you want to look for all terms
between "a" and the first subsequent term that does not have "a" as a
prefix.

http://svn.apache.org/viewcvs.cgi/lucene/java/trunk/src/java/org/apache/lucene/search/RangeFilter.java?rev=150665&view=markup




:
: public class PrefijoURLFilter extends Filter
: {
:     private String field;
:     private String[] prefix;
:
:     public PrefijoURLFilter(String field, String[] prefix)
:     {
:         this.field = field;
:         this.prefix = prefix;
:     }
:
:     public BitSet bits(IndexReader reader) throws IOException
:     {
:         BitSet bits = new BitSet(reader.maxDoc());
:
: 	//FOR EACH PREFIX AND FOR EACH DOCUMENT IN INDEX CHECK IF
: 	//STARTS WITH A VALID PREFIX AND SET IT IN THE BITSET
:
:         return bits;
:     }
: }
:
:
: A valid usage of this filter could be:
:
: filter = new PrefijoURLFilter("path", new String[] {
: 	"http://xxx/CA/noticies/agenda/",
: 	"http://xxx/noticies/agenda/",
: 	"http://xxx/CA/content/agenda/",
:     	"http://xxx/content/agenda/"
: });
:
: Thanks a lot!!!
:
: --
: Salut,
: ====================================
: Ricardo Borillo Domenech
: Analista/Programador - Servei d'Informàtica
: Universitat Jaume I
: http://xml-utils.com
:



-Hoss


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