You need to subtract the matching documents from everything else in the negative part, effectively:
*:* AND NOT (zips-within area) D. On Wed, May 8, 2024 at 8:27 PM Siraj Haider <siraj.hai...@jobdiva.com.invalid> wrote: > Hello there, > We are using Lucene v6.4.1 and are looking to implement geopoint searching > within or outside certain zipcode. The within part works well, but the > outside part does not, can somebody please check the code below and give > some suggestions? > > Thanks in advance! > > > query //this has some other criteria and we are adding zipcode radius > related criteria to it here... > > BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); > queryBuilder.add(query, BooleanClause.Occur.MUST); > > Query zipQuery1 = new GeoPointDistanceQuery("ZIPLOC", latitude, longitude, > radius_in_meters); > BooleanQuery.Builder zipQueryBuilder = new BooleanQuery.Builder(); > > if(!searchType.equals("outside"))){ > // searching WITHIN radius > zipQueryBuilder.add(zipQuery1, BooleanClause.Occur.SHOULD); > }else{ > // searching outside the radius > zipQueryBuilder.add(zipQuery1, BooleanClause.Occur.MUST_NOT); > } > > BooleanQuery zipQuery = zipQueryBuilder.build(); > queryBuilder.add(zipQuery, BooleanClause.Occur.MUST); > BooleanQuery booleanQuery = queryBuilder.build(); > query=booleanQuery; > > [https://signaturehound.com/api/v1/file/56citokvb3uvw4]< > https://jobdiva.com/> > Siraj Haider > JobDiva Technology > [https://signaturehound.com/api/v1/png/email/default/c52e28.png] > siraj.hai...@jobdiva.com<mailto:siraj.hai...@jobdiva.com> > [https://signaturehound.com/api/v1/png/phone/default/c52e28.png] > 212.306.0154 > [https://signaturehound.com/api/v1/png/map/default/c52e28.png] > 44 Wall Street, New York, NY 10005 > [https://signaturehound.com/api/v1/png/website/default/c52e28.png] > jobdiva.com<https://jobdiva.com/> > > > > > > > > > > > > The content of this email is confidential and intended for the recipient > specified in message only. It is strictly forbidden to share any part of > this message with any third party, without a written consent of the sender. > If you received this message by mistake, please reply to this message and > follow with its deletion, so that we can ensure such a mistake does not > occur in the future. > > > ________________________________ > > This electronic mail message and any attachments may contain information > which is privileged, sensitive and/or otherwise exempt from disclosure > under applicable law. The information is intended only for the use of the > individual or entity named as the addressee above. If you are not the > intended recipient, you are hereby notified that any disclosure, copying, > distribution (electronic or otherwise) or forwarding of, or the taking of > any action in reliance on, the contents of this transmission is strictly > prohibited. If you have received this electronic transmission in error, > please notify us by telephone, facsimile, or e-mail as noted above to > arrange for the return of any electronic mail or attachments. Thank You. >