Re: how to join 2 queries togther
It should all be pretty clear from the API javadocs. Take a look at BooleanQuery, which is that single query that you can add other queries. Good luck. Otis --- Charles [EMAIL PROTECTED] wrote: Hi everyone, First of all I'd like to thank you guys for developing a great search engine framework. I've tested it out and it works flawlessly (and really fast too). Right now I plan to create a more advance search capability. I understand how to construct the Query object using the QueryParser, but I would like to know how I can add in different types of queries (like range, terms, boolean) all into one. I'm not sure if I can do this with the QueryParser and am looking for information on how to manually construct a Query object so i can combine all these requirements. Here's what I want to do: I would like to have the user select values from a combo box (e.g. Price range, Area, Country, Number of rooms, land area, is Freehold or Leasehold etc). From what I gather this involves several type of queries including RangeQuery (for the price range), a TermQuery, BooleanQuery etc. So the question is how do i combine all these types of queries into one so I can obtain a single Hits result that matches all these requirements? Any advice or urls is very much appreciated. Charles - Original Message - From: alex [EMAIL PROTECTED] To: Lucene Users List [EMAIL PROTECTED] Sent: Tuesday, January 21, 2003 3:23 PM Subject: Re: how to join 2 queries togther Thank you everyone for your help - Original Message - From: Lichtner, Guglielmo [EMAIL PROTECTED] To: 'Lucene Users List' [EMAIL PROTECTED] Sent: Monday, January 20, 2003 9:52 PM Subject: RE: how to join 2 queries togther 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:[EMAIL PROTECTED]] 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 [EMAIL PROTECTED] To: 'Lucene Users List' [EMAIL PROTECTED] 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:[EMAIL PROTECTED]] 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
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 [EMAIL PROTECTED] To: 'Lucene Users List' [EMAIL PROTECTED] 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:[EMAIL PROTECTED]] 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:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: how to join 2 queries togther
Do you want hits to contain the word words or not? You've got it in both clauses... Also, +(a b c) requires that any of a b or c be in a document, but not necessarily all of them. If you want it to contain all of them then each term must be required, e.g., +a +b +c. In the latest sources this can be achieved through the query parser with: queryParser.setOperator(DEFAULT_OPERATOR_AND); I'm not quite sure precisely what you're trying to do, so it's hard to tell you how to do it. Doug alex wrote: 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 [EMAIL PROTECTED] To: 'Lucene Users List' [EMAIL PROTECTED] 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:[EMAIL PROTECTED]] 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:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: how to join 2 queries togther
Alex, If you are using an older version of Lucene, and at the line input (going into q1 and q2) your user is entering terms without a plus or minus, I think what your code is actually doing is creating the following query: +( a b c) -(d e f) (which is +(a OR b OR c) OR -(d OR e OR f)) What I think you want to create is: +(a AND b AND c) AND NOT (d AND e AND f), or +a +b +c -d -e -f You can check it quickly by, for the line input going into q1, enter on the line: +a +b +c, and for the line input going into q2 enter on the line: -d -e -f. That should give you what you're looking for. Alternatively, if you follow Doug's comment about using one of the later Lucene versions and changing the default operator, your code should work the way you want when terms are entered without pluses or minuses. HTH, Terry - Original Message - From: alex [EMAIL PROTECTED] To: Lucene Users List [EMAIL PROTECTED] Sent: Monday, January 20, 2003 3:52 PM Subject: Re: how to join 2 queries togther I m trying to achieve something like the advanced search for google where the user has these option of allowing will all of the words = without the words = http://www.google.com/advanced_search?hl=en - Original Message - From: Doug Cutting [EMAIL PROTECTED] To: Lucene Users List [EMAIL PROTECTED] Sent: Monday, January 20, 2003 8:08 PM Subject: Re: how to join 2 queries togther Do you want hits to contain the word words or not? You've got it in both clauses... Also, +(a b c) requires that any of a b or c be in a document, but not necessarily all of them. If you want it to contain all of them then each term must be required, e.g., +a +b +c. In the latest sources this can be achieved through the query parser with: queryParser.setOperator(DEFAULT_OPERATOR_AND); I'm not quite sure precisely what you're trying to do, so it's hard to tell you how to do it. Doug alex wrote: 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 [EMAIL PROTECTED] To: 'Lucene Users List' [EMAIL PROTECTED] 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:[EMAIL PROTECTED]] 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:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]