JMA wrote on 06/17/2006 10:16 PM: > 1) Is there a way to find a document that has null fields? > For example, if I have two fields (FIRST_NAME, LAST_NAME) for World Cup > players: > > FIRST_NAME: Brian LAST_NAME: McBride > FIRST_NAME: Agustin LAST_NAME: Delgado > FIRST_NAME: Zinha LAST_NAME: (null or blank) > FIRST_NAME: Kaka LAST_NAME: (null or blank) > > ... and so on > > What's the way to find all players that use only their first name? >
By far the best way is to store a special token into null fields and then just match on this. One less-performant alternative if you have no control over the index is to enable prefix wildcard queries and then write a query like this: FIRST_NAME:* -LAST_NAME:* To enable prefix wildcard queries, you need to regenerate QueryParser.java from QueryParser.jj after replacing the wildcard production (search for OG, as Otis has nicely included the appropriate production as a comment). > 2) Is there a way to count field terms? For example, if instead we have one > field... > > NAME: Brian McBride > NAME: Agustin Delgado > NAME: Zinha > NAME: Kaka > > Can I answer the same question by finding all documents where the number of > terms > in the NAME field is 1 and only 1? Is there a way to do that? > You would need to write your own Query subclass, and I can't think of any way to achieve this that would not be very slow. Not recommended. Chuck --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]