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 Samuru Jackson <sa...@googlemail.com> on 2006/02/26 11:38:24 UTC

Filter Field.Keyword possible?

Hi to all!

I added some documents to my index repository this way:

Document document = new Document();
document.add(Field.Keyword("id", id));
document.add(Field.Keyword("type", type));
document.add(Field.Text("content", content));


Is it possible to search only within a specific Field.Keyword? For example I
want to search only the contents that have got a Keyword *type*="webpages".

Is there a way to create such a filter?

Samuru

Re: Filter Field.Keyword possible?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Feb 28, 2006, at 8:11 AM, Samuru Jackson wrote:

>> Also heed the other recommendations in LIA and don't necessarily use
>> Filters when BooleanQuery clauses will suffice.  There is overhead
>> involved in the Filter mechanism in terms of executing multiple
>> queries to build all the filters you're proposing.
>
> I'm aware of the fact that using multiple filters will result in
> performance problems. One point is that QueryFilters can be reused to
> benefit from its caching.
>
> BooleanQueries seem to do no caching except when using
> CachingWrappingFilter.

That last statement is not correct.  BooleanQuery and  
CachingWrapperFilter are separate beasts.  BooleanQuery does no  
caching... but then again you might not need it.  Experimentation is  
the best judge of what is needed.

>
> Regarding ChainedFilter ... I can't find any API on the web!

It's all open source :)

Our Subversion repository starts here: http://svn.apache.org/repos/ 
asf/lucene/java/trunk

And ChainedFilter is here:

	<http://svn.apache.org/repos/asf/lucene/java/trunk/contrib/ 
miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java>



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


Re: Filter Field.Keyword possible?

Posted by Samuru Jackson <sa...@googlemail.com>.
> Also heed the other recommendations in LIA and don't necessarily use
> Filters when BooleanQuery clauses will suffice.  There is overhead
> involved in the Filter mechanism in terms of executing multiple
> queries to build all the filters you're proposing.

I'm aware of the fact that using multiple filters will result in
performance problems. One point is that QueryFilters can be reused to
benefit from its caching.

BooleanQueries seem to do no caching except when using
CachingWrappingFilter. But I don't think that will help me in my
project as I won't create similar Filters that often. I will see how
it performs with 3gb indexed docs ;-)

> There is a ChainedFilter available in the contrib/miscellaneous area
> (previously called the "sandbox", as in LIA) that can be used to
> combine multiple Filters in sophisticated ways.  Maybe this is what
> you're after?  It is covered in LIA.

ChainedFilter is interesting, but I noticed that I can *add* more than
one Term to BooleanQueries and combine them with BooleanClause.Occur.
That would be sufficient for the moment...



Regarding ChainedFilter ... I can't find any API on the web!


Thanks a lot!

Samuru

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


Re: Filter Field.Keyword possible?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Feb 28, 2006, at 6:10 AM, Samuru Jackson wrote:
> Hi again!
>
>>         2) Use a QueryFilter with that same TermQuery, and apply  
>> that Filter
>> to your search method.
>
> Thanks for the hint - I just bought "Lucene in Action" and now I'm
> more into it :-)
>
> But at this point I'm facing some Filter problems again.
>
> As proposed in LiA the easiest way would be to use the QueryFilter for
> my problem. I just create a Term for "type" in my last example and
> thats all.

Also heed the other recommendations in LIA and don't necessarily use  
Filters when BooleanQuery clauses will suffice.  There is overhead  
involved in the Filter mechanism in terms of executing multiple  
queries to build all the filters you're proposing.

> **But** what if I want to create a whole set of filters?

There is a ChainedFilter available in the contrib/miscellaneous area  
(previously called the "sandbox", as in LIA) that can be used to  
combine multiple Filters in sophisticated ways.  Maybe this is what  
you're after?  It is covered in LIA.

	Erik


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


Re: Filter Field.Keyword possible?

Posted by Samuru Jackson <sa...@googlemail.com>.
Hi again!

>         2) Use a QueryFilter with that same TermQuery, and apply that Filter
> to your search method.

Thanks for the hint - I just bought "Lucene in Action" and now I'm
more into it :-)

But at this point I'm facing some Filter problems again.

As proposed in LiA the easiest way would be to use the QueryFilter for
my problem. I just create a Term for "type" in my last example and
thats all.

**But** what if I want to create a whole set of filters?

For example I add documents to my index like the way above:

Document document = new Document();
document.add(Field.Keyword("id", id));
document.add(Field.Keyword("type", type));
document.add(Field.Text("content", content));

Now I want to search through only the documents with the ids 1, 12,
33, 44, 55, 87 and 123 plus "type" must be filtered to something too
to make it much more complicated.

Can anyone give me a hint again ;-)

Thanks!

Samuru

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


Re: Filter Field.Keyword possible?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Feb 26, 2006, at 5:38 AM, Samuru Jackson wrote:

> Hi to all!
>
> I added some documents to my index repository this way:
>
> Document document = new Document();
> document.add(Field.Keyword("id", id));
> document.add(Field.Keyword("type", type));
> document.add(Field.Text("content", content));
>
>
> Is it possible to search only within a specific Field.Keyword? For  
> example I
> want to search only the contents that have got a Keyword  
> *type*="webpages".
>
> Is there a way to create such a filter?

Two ways....

	1) Simply create a BooleanQuery with one clause a TermQuery for  
"type" and the constraint

	2) Use a QueryFilter with that same TermQuery, and apply that Filter  
to your search method.

#1 is the simplest and most recommended to begin with unless you have  
other reasons to go to #2.

	Erik


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