0

I'm using Lucene for the first time I'm trying to make a search system with the following query...

  QueryParser qp1 = new QueryParser("title", new StandardAnalyzer()); 
  Q1 = qp1.parse(tr.toString()); // The same think for Q,Q2,Q3 


    BooleanQuery idQuery = new BooleanQuery.Builder()
                                .add(Q, BooleanClause.Occur.SHOULD)
                                .add(Q1, BooleanClause.Occur.SHOULD)
                                .add(Q2, BooleanClause.Occur.SHOULD)
                                .add(Q3, BooleanClause.Occur.SHOULD)
                                //.add(Q3, BooleanClause.Occur.SHOULD)
                                .build();

so I wanna add a query that can answer the query with boolean operation AND OR (a+b)(a-b)(a or b)... but I really don't know how to start so please help...

edit: for example, when I search for "search information" in the title I'm having all the documents that contain (search information)(information)(search) but I want the system to be able to answer the "search+ information" : show only the document that contains (search and information), "search - information" show only document contains (search) and without (information), "search | information" this what my system do I think

*pleas I really need help so plz any proposition *

asma bzd
  • 11
  • 3
  • I'm not sure what you are asking. Is your example not working the way you expect? If so, can you edit your question to show how it's not working - and why? Some example data would probably help. – andrewJames Jun 10 '20 at 01:32
  • no the code works but I wanna add a query that can answer the input withe boolean operation example my query work for "search information " but not in "search + information "or"search -information" – asma bzd Jun 10 '20 at 01:40
  • Please can you edit your question and add an example? – andrewJames Jun 10 '20 at 02:05
  • I added an example I wish that can help – asma bzd Jun 10 '20 at 15:51
  • I think I understand, but let me check: You want to find documents containing _both_ words `search` and `information` in the title. And you want to _exclude_ documents which may contain only one of these words, but not the other one. To do this, you need to use `BooleanClause.Occur.MUST` for both search terms. Does that help? – andrewJames Jun 10 '20 at 16:43

0 Answers0