I would like to find my index in two fields called "a" and "b". I have been given queries such as Freud -- theories of psychology, and I would like to execute the following query:
(a="Freud" AND b="theories of psychology") OR (b="Freud" AND a="theories of psychology")
How should I do it? As long as I have Lucene creating two halves ( firstHalfand secondHalf) with help MultiFieldQueryParser, then I combined them with
BooleanQuery combined = new BooleanQuery();
combined.add(firstHalf, BooleanClause.Occur.SHOULD);
combined.add(secondHalf, BooleanClause.Occur.SHOULD);
But combinedit allows you to return results where only "theories" are found, not "psychology", where I definitely want both terms. It seems that Lutsen breaks down "theories of psychology" into three words and combines them individually with OR. How to prevent this?
firstHalf as follows:
Query firstHalf = MultiFieldQueryParser.parse(Version.LUCENE_33,
new String[]{"Freud", "theories of psychology"},
new String[]{"a", "b"},
new BooleanClause.Occur[]{BooleanClause.Occur.MUST, BooleanClause.Occur.MUST},
analyzer);
where analyzeris just an object StandardAnalyzer.