lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lichtner, Guglielmo" <Guglielmo.Licht...@gs.com>
Subject RE: how to join 2 queries togther
Date Mon, 20 Jan 2003 21:52:25 GMT

>From this code I think I see a possible problem.

I think one way to fix it is to parse the word in readLine() and add a term
query for each:

BooleanQuery query = new BooleanQuery();
System.out.print("will all of the words ");
StringTokenizer tok1 = new StringTokenizer(in.readLine());
while (tok.hasMoreTokens()) {
    query.add(new TermQuery(new Term("content", tok1.nextToken()), true,
false);
}
System.out.print("without the words");
StringTokenizer tok2 = new StringTokenizer(in.readLine());
while (tok.hasMoreTokens()) {
    query.add(new TermQuery(new Term("content", tok2.nextToken()), false,
true);
}
System.out.println("Searching for: " + query);
Hits hits = searcher.search(query);
System.out.println(hits.length() + " total matching documents  ");


-----Original Message-----
From: alex [mailto:a@wong45.freeserve.co.uk]
Sent: Monday, January 20, 2003 2:57 PM
To: Lucene Users List
Subject: Re: how to join 2 queries togther


thxs for your suggestion this is what i have written but it does not work
any suggestion on how to get it to work ?

 System.out.print("will all of the words ");
        String q1 = in.readLine();
 System.out.print("without the words");
        String q2 = in.readLine();

        BooleanQuery query = new BooleanQuery();
              Query matchall = QueryParser.parse(q1, "content", analyzer);
        query.add(matchall, true, false);
              Query exclude = QueryParser.parse( q2, "content" , analyzer);
        query.add(exclude, false, true);

        System.out.println("Searching for: " + query.toString("content"));
        Hits hits = searcher.search(query);
        System.out.println(hits.length() + " total matching documents  ");


----- Original Message -----
From: "Lichtner, Guglielmo" <Guglielmo.Lichtner@gs.com>
To: "'Lucene Users List'" <lucene-user@jakarta.apache.org>
Sent: Monday, January 20, 2003 4:04 PM
Subject: RE: how to join 2 queries togther


>
> I'm a newbie, but I could suggest this:
>
> BooleanQuery bq = new BooleanQuery();
> bq.add(firstQuery, true, false);
> bq.add(secondQuery, false, true);
>
> That should make the first query required, and the second
> one prohibited, which is like saying "+firstQuery -secondQuery"
>
> I haven't tried this myself but I did try this for an either/or
combination,
> and it does work for me.
>
> -----Original Message-----
> From: alex [mailto:a@wong45.freeserve.co.uk]
> Sent: Monday, January 20, 2003 10:54 AM
> To: Lucene User
> Subject: how to join 2 queries togther
>
>
> hi all
>
> I have a method which takes in a normal query breaks into token and places
+
> in front it
> I have a second method which does the same instead puts a - sign front the
> token
>
> the reason i have done this is so that the user do not need to add + and -
> signs by themselfs and also I cound
>  not get the booleanQuery to work
>
> this makes it so that i have 2 queries
>
> 1) a file must contain all these words
> 2) a file must exclude this words
>
> my question is how do join these 2 queries togther so it filters out words
> that i want and do not want ?
>
> Alex
>
> --
> 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>

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


Mime
View raw message