FAQ
Hi friends,

I tried to implement the facet searching in a sample code and when I tried
it with various case and found no result in one case.I wanted to narrow by
one field "title" and gave the multiple word or say phrase.

So First, in this preparing the lucene query and converting it into
QueryFilter.
Adding IndexReader to this filter query and converting it into BitSet.
and We are preparing TermQuery on the basis of lucene field and given
value(Getting the field and value dynamically and value can be single word
or multiple word). Adding this term query to query filter and again
converting it to BitSet.
so this has two different bitset, one is based on free text lucene query and
another is on the basis of field by which I need to narrow by. and doing the
following operation:-
<code>
secondBitSet.and(FirstBitSet);
int count=secondBitSet.cardinality();
<code>
Now, The problem occured when I passed the multiple words in term query.
e.g.<code>
QueryFilter filter = new QueryFilter(new TermQuery(new Term(FieldName,
FieldValue)));
<code>
where field name and field value dynamically getting.
here we take the example value.
FieldName:- "Title"
FieldValue:- "Software Development" ot it may be "Software AND Development".
In this case i'm not getting the result. i.e . counts= 0.

Code is given below.
<code>
IndexReader reader = searcher.getIndexReader();
BitSet firstBitSet = firstQueryFilter.bits(reader);

QueryFilter filter = new QueryFilter(new TermQuery(new Term(FieldName,
FieldValue)));
BitSet secondBitSet = filter.bits(reader);

secondBitSet.and (FirstBitSet);
int count=secondBitSet.cardinality();

</code>
--
Regards

Sawan

Search Discussions

  • Steven Rowe at Jun 21, 2007 at 3:16 pm
    Hi Sawan,

    Sawan Sharma wrote:
    Now, The problem occured when I passed the multiple words in term query.
    e.g.<code>
    QueryFilter filter = new QueryFilter(new TermQuery(new Term(FieldName,
    FieldValue)));
    <code>
    where field name and field value dynamically getting.
    here we take the example value.
    FieldName:- "Title"
    FieldValue:- "Software Development" ot it may be "Software AND
    Development".
    In this case i'm not getting the result. i.e . counts= 0.
    It looks to me as though you expect the "Software AND Development" query
    to be parsed so that it matches a document containing both "Software"
    and "Development" terms, but TermQuery does not do query parsing - in
    the code above, you are telling Lucene to use "Software AND Development"
    as a literal string to be matched.

    Perhaps you should be using QueryParser[1] to parse user-supplied queries?

    At a minimum, you should make sure that the analyzer used to produce
    your index is compatible with the one you use with your queries. The
    simplest form of compatibility, of course, is to use the same analyzer
    in both places. (See the FAQ "Why is it important to use the same
    analyzer type during indexing and search?"[2])

    As always when questions about the contents of indexes come up, Luke[3]
    is indispensable.

    Steve

    [1]
    <http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/queryParser/QueryParser.html>
    [2]
    <http://wiki.apache.org/lucene-java/LuceneFAQ#head-0f374b0fe1483c90fe7d6f2c44472d10961ba63c>
    [3] <http://www.getopt.org/luke/>

    --
    Steve Rowe
    Center for Natural Language Processing
    http://www.cnlp.org/tech/lucene.asp

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJun 21, '07 at 4:31a
activeJun 21, '07 at 3:16p
posts2
users2
websitelucene.apache.org

2 users in discussion

Steven Rowe: 1 post Sawan Sharma: 1 post

People

Translate

site design / logo © 2022 Grokbase