Hi Trevor Well, you may negate it via qb.add(product_c_positive, Occur.MUST_NOT); it will work only if there is a sibling MUST/SHOULD clause. Regarding qb.add(BooleanQuery.Builder().add(product_c_positive, Occur.MUST_NOT).build(), Occur.FILTER); It may hardly work unless Lucene "adjusts pure negative query" somewhere that some search servers do or did under certain conditions.
On Wed, Nov 22, 2023 at 7:46 AM Trevor Nicholls <tre...@castingthevoid.com> wrote: > Hi > > > > I'm constructing a BooleanQuery with an optional filter query and a > mandatory content query, plus some optional boost queries. > > > > In effect, what I am doing is implementing this shorthand: > > > > BooleanQuery.Builder qb = new BooleanQuery.Builder(); > > if (filter) { > > qb.add(filterquery, Occur.FILTER); > > } > > qb.add(contentquery, Occur.MUST); > > if (boost) > > qb.add(boostquery, Occur.SHOULD); > > .. > > } > > Query fullquery = qb.build(); > > > > Typically the content query will be constructed from something like > "title:word OR text:word" and the filter query, if it exists, will be built > from something like "product:a". (The boost queries serve to push recent > content higher in the results, they don't really matter for this > question.) > > > > There will always be a content query. My question relates to the filter > query. I know that a query which has no 'positive' clauses will not return > any results. That although the two queries > > > > product:a or product:b or product:d > > > > and > > > > NOT product:c > > > > might be logically identical, the first will return results and the second > will not. > > > > However would a query like "NOT product:c" be OK as a filter query if it > was > combined with other queries as per the pseudocode above? > > > > I don't think it's significant but for what it's worth this application is > still using Lucene 8_6.3. > > > > cheers > > T > > > > -- Sincerely yours Mikhail Khludnev