Mailing List Archive

Few questions regarding the design of the Filter class
Hi, i have few questions regarding the Filter class.

Why this is not an interface ?
Why there is not method to get the field on which the filter is used to restrict the search ?

Thanks in advance
Best regards

Christian Meunier
RE: Few questions regarding the design of the Filter class [ In reply to ]
> From: Christian Meunier
>
> Hi, i have few questions regarding the Filter class.
>
> Why this is not an interface ?

No good reason. Since interfaces have some performance penalties with most
JVMs, when I first wrote Lucene I only used interfaces where multiple
inheritance was required. In retrospect, I probably should have also used
them in a few other places that are not performance critical.

Does the use of an abstract class instead of an interface keep you from
doing something that you need to do?

> Why there is not method to get the field on which the filter
> is used to restrict the search ?

A filter may not always restrict the search to a single field. One could
construct a filter with arbitrary criteria that may or may not correspond to
document fields.

Doug

--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
Re: Few questions regarding the design of the Filter class [ In reply to ]
----- Original Message -----
From: <cutting@lucene.com>
To: <lucene-user@jakarta.apache.org>
Sent: Thursday, May 23, 2002 10:04 PM
Subject: RE: Few questions regarding the design of the Filter class


> > From: Christian Meunier
> >
> > Hi, i have few questions regarding the Filter class.
> >
> > Why this is not an interface ?
>
> No good reason. Since interfaces have some performance penalties with
most
> JVMs, when I first wrote Lucene I only used interfaces where multiple
> inheritance was required. In retrospect, I probably should have also used
> them in a few other places that are not performance critical.
>
> Does the use of an abstract class instead of an interface keep you from
> doing something that you need to do?

No it's just a design question ;)
>
> > Why there is not method to get the field on which the filter
> > is used to restrict the search ?
>
> A filter may not always restrict the search to a single field. One could
> construct a filter with arbitrary criteria that may or may not correspond
to
> document fields.

Oky i ll try to think for a good workaround beside recompiling lucene
hacking the filter class.
Thanks for your answers Doug !

>
> Doug
>
> --
> To unsubscribe, e-mail:
<mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:lucene-user-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
RE: Few questions regarding the design of the Filter class [ In reply to ]
> From: Christian Meunier
>
> > > From: Christian Meunier
> > >
> > > Why there is not method to get the field on which the filter
> > > is used to restrict the search ?
> >
> > A filter may not always restrict the search to a single
> > field. One could
> > construct a filter with arbitrary criteria that may or may
> > not correspond to document fields.
>
> Oky i ll try to think for a good workaround beside recompiling lucene
> hacking the filter class.

A workaround for what? It's not clear what you're trying to do.

If you need something that's like a Filter, but that operates on a
particular field, then define a subclass of Filter that has a getFieldName()
method, and use that where you're using Filter.

Doug

--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
Re: Few questions regarding the design of the Filter class [ In reply to ]
>
> A workaround for what? It's not clear what you're trying to do.
>

Here is what i am trying to do:

A simple class to filter a field

FieldFilter.java
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------
import java.util.BitSet;
import java.io.IOException;

import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.IndexReader;

public class FieldFilter extends org.apache.lucene.search.Filter
{

private String field;
private String value;
private Term searchTerm;

public FieldFilter(String field, String value)
{
this.field = field;
this.value = value;
searchTerm = new Term(field, value);
}

public String getField()
{
return field;
}

public BitSet bits(IndexReader reader) throws IOException
{
BitSet bits = new BitSet(reader.maxDoc());
TermDocs matchingDocs = reader.termDocs(searchTerm);
try
{
while(matchingDocs.next())
{
bits.set(matchingDocs.doc());
}
}
catch (Exception e) { /* ignore */ }
finally
{
if (matchingDocs != null)
{
matchingDocs.close();
}
}
return bits;
}
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------

I then coded a class which handle multiple filters (FieldFilter,
DateFilter,....) at once


MultiFilter.java
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------
import java.util.Hashtable;
import java.util.BitSet;
import java.util.ArrayList;
import java.io.IOException;

import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Filter;

public class MultiFilter extends org.apache.lucene.search.Filter
{
private ArrayList filterList;

public MultiFilter()
{
filterList = new ArrayList();
}

public MultiFilter(int initialCapacity)
{
filterList = new ArrayList(initialCapacity);
}

public String getField()
{
return null;
}


public void add(Filter filter)
{
filterList.add(filter);
}

public BitSet bits(IndexReader reader) throws IOException
{
int filterListSize = filterList.size();

if (filterListSize > 0)
{
Hashtable filters = new Hashtable();
int pos=0;
for (int i=0; i<filterListSize; i++)
{
if(!filters.containsKey( ((Filter)filterList.get(i)).getField()))
{
filters.put(((Filter)filterList.get(i)).getField(),""+pos);
pos++;
}

}

BitSet [] tab_bits = new BitSet[filters.size()];
for (int i=0; i<filterListSize; i++)
{

if(tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i))
.getField()))]==null)

tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i)).ge
tField()))] = ((Filter)filterList.get(i)).bits(reader);
else

tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i)).ge
tField()))].or(((Filter)filterList.get(i)).bits(reader));
}

for(int i=1;i<tab_bits.length;i++)
tab_bits[0].and(tab_bits[i]);

return tab_bits[0];
}
else
{
return new BitSet(reader.maxDoc());
}
}
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------

As you can see, it's mandatory that the Filter class specify a getFilter
method so such MultiFilter can work.


> Doug
>
Best regards
Christian


--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
RE: Few questions regarding the design of the Filter class [ In reply to ]
Looks to me like your looking for Kelvin Tan's chainable filter

http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg01168.html

Dan



-----Original Message-----
From: Christian Meunier [mailto:vchris@club-internet.fr]
Sent: Friday, May 24, 2002 5:38 AM
To: Lucene Users List
Subject: Re: Few questions regarding the design of the Filter class


>
> A workaround for what? It's not clear what you're trying to do.
>

Here is what i am trying to do:

A simple class to filter a field

FieldFilter.java
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------
import java.util.BitSet;
import java.io.IOException;

import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.IndexReader;

public class FieldFilter extends org.apache.lucene.search.Filter
{

private String field;
private String value;
private Term searchTerm;

public FieldFilter(String field, String value)
{
this.field = field;
this.value = value;
searchTerm = new Term(field, value);
}

public String getField()
{
return field;
}

public BitSet bits(IndexReader reader) throws IOException
{
BitSet bits = new BitSet(reader.maxDoc());
TermDocs matchingDocs = reader.termDocs(searchTerm);
try
{
while(matchingDocs.next())
{
bits.set(matchingDocs.doc());
}
}
catch (Exception e) { /* ignore */ }
finally
{
if (matchingDocs != null)
{
matchingDocs.close();
}
}
return bits;
}
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------

I then coded a class which handle multiple filters (FieldFilter,
DateFilter,....) at once


MultiFilter.java
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------
import java.util.Hashtable;
import java.util.BitSet;
import java.util.ArrayList;
import java.io.IOException;

import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Filter;

public class MultiFilter extends org.apache.lucene.search.Filter
{
private ArrayList filterList;

public MultiFilter()
{
filterList = new ArrayList();
}

public MultiFilter(int initialCapacity)
{
filterList = new ArrayList(initialCapacity);
}

public String getField()
{
return null;
}


public void add(Filter filter)
{
filterList.add(filter);
}

public BitSet bits(IndexReader reader) throws IOException
{
int filterListSize = filterList.size();

if (filterListSize > 0)
{
Hashtable filters = new Hashtable();
int pos=0;
for (int i=0; i<filterListSize; i++)
{
if(!filters.containsKey( ((Filter)filterList.get(i)).getField()))
{
filters.put(((Filter)filterList.get(i)).getField(),""+pos);
pos++;
}

}

BitSet [] tab_bits = new BitSet[filters.size()];
for (int i=0; i<filterListSize; i++)
{

if(tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i))
.getField()))]==null)

tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i)).ge
tField()))] = ((Filter)filterList.get(i)).bits(reader);
else

tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i)).ge
tField()))].or(((Filter)filterList.get(i)).bits(reader));
}

for(int i=1;i<tab_bits.length;i++)
tab_bits[0].and(tab_bits[i]);

return tab_bits[0];
}
else
{
return new BitSet(reader.maxDoc());
}
}
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------

As you can see, it's mandatory that the Filter class specify a getFilter
method so such MultiFilter can work.


> Doug
>
Best regards
Christian


--
To unsubscribe, e-mail:
<mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:lucene-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
Re: Few questions regarding the design of the Filter class [ In reply to ]
More or less :

"A ChainableFilter allows multiple filters to be chained such that the result is the intersection of all the filters."

I do a OR operator on filters which are based on the same field (hence the issue, i need to know on which field the filter is based)

(All my filters are based on a field in my application)


----- Original Message -----
From: "Armbrust, Daniel C." <Armbrust.Daniel@mayo.edu>
To: "'Lucene Users List'" <lucene-user@jakarta.apache.org>
Sent: Friday, May 24, 2002 3:43 PM
Subject: RE: Few questions regarding the design of the Filter class


> Looks to me like your looking for Kelvin Tan's chainable filter
>
> http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg01168.html
>
> Dan
>
>
>
> -----Original Message-----
> From: Christian Meunier [mailto:vchris@club-internet.fr]
> Sent: Friday, May 24, 2002 5:38 AM
> To: Lucene Users List
> Subject: Re: Few questions regarding the design of the Filter class
>
>
> >
> > A workaround for what? It's not clear what you're trying to do.
> >
>
> Here is what i am trying to do:
>
> A simple class to filter a field
>
> FieldFilter.java
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------
> ----------
> import java.util.BitSet;
> import java.io.IOException;
>
> import org.apache.lucene.index.Term;
> import org.apache.lucene.index.TermDocs;
> import org.apache.lucene.index.IndexReader;
>
> public class FieldFilter extends org.apache.lucene.search.Filter
> {
>
> private String field;
> private String value;
> private Term searchTerm;
>
> public FieldFilter(String field, String value)
> {
> this.field = field;
> this.value = value;
> searchTerm = new Term(field, value);
> }
>
> public String getField()
> {
> return field;
> }
>
> public BitSet bits(IndexReader reader) throws IOException
> {
> BitSet bits = new BitSet(reader.maxDoc());
> TermDocs matchingDocs = reader.termDocs(searchTerm);
> try
> {
> while(matchingDocs.next())
> {
> bits.set(matchingDocs.doc());
> }
> }
> catch (Exception e) { /* ignore */ }
> finally
> {
> if (matchingDocs != null)
> {
> matchingDocs.close();
> }
> }
> return bits;
> }
> }
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------
> ----------
>
> I then coded a class which handle multiple filters (FieldFilter,
> DateFilter,....) at once
>
>
> MultiFilter.java
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------
> ----------
> import java.util.Hashtable;
> import java.util.BitSet;
> import java.util.ArrayList;
> import java.io.IOException;
>
> import org.apache.lucene.index.Term;
> import org.apache.lucene.index.TermDocs;
> import org.apache.lucene.index.IndexReader;
> import org.apache.lucene.search.Filter;
>
> public class MultiFilter extends org.apache.lucene.search.Filter
> {
> private ArrayList filterList;
>
> public MultiFilter()
> {
> filterList = new ArrayList();
> }
>
> public MultiFilter(int initialCapacity)
> {
> filterList = new ArrayList(initialCapacity);
> }
>
> public String getField()
> {
> return null;
> }
>
>
> public void add(Filter filter)
> {
> filterList.add(filter);
> }
>
> public BitSet bits(IndexReader reader) throws IOException
> {
> int filterListSize = filterList.size();
>
> if (filterListSize > 0)
> {
> Hashtable filters = new Hashtable();
> int pos=0;
> for (int i=0; i<filterListSize; i++)
> {
> if(!filters.containsKey( ((Filter)filterList.get(i)).getField()))
> {
> filters.put(((Filter)filterList.get(i)).getField(),""+pos);
> pos++;
> }
>
> }
>
> BitSet [] tab_bits = new BitSet[filters.size()];
> for (int i=0; i<filterListSize; i++)
> {
>
> if(tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i))
> .getField()))]==null)
>
> tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i)).ge
> tField()))] = ((Filter)filterList.get(i)).bits(reader);
> else
>
> tab_bits[Integer.parseInt((String)filters.get(((Filter)filterList.get(i)).ge
> tField()))].or(((Filter)filterList.get(i)).bits(reader));
> }
>
> for(int i=1;i<tab_bits.length;i++)
> tab_bits[0].and(tab_bits[i]);
>
> return tab_bits[0];
> }
> else
> {
> return new BitSet(reader.maxDoc());
> }
> }
> }
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------
> ----------
>
> As you can see, it's mandatory that the Filter class specify a getFilter
> method so such MultiFilter can work.
>
>
> > Doug
> >
> Best regards
> Christian
>
>
> --
> To unsubscribe, e-mail:
> <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:lucene-user-help@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
>