You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Jerry Camel <rl...@msn.com> on 2009/12/16 05:35:05 UTC

Query For Unpopulated Fields

Is it possible to query for docs that do not have a specific field present?

Thanks.

J

Re: Query For Unpopulated Fields

Posted by Michael Garski <mg...@myspace-inc.com>.
Jerry,

You can't add a field to an existing document, but have to delete and  
reindex the item.

I'd suggest a copy of Lucene in Action to get started with those basics.

Michael

On Dec 16, 2009, at 1:43 PM, "Jerry Camel" <rl...@msn.com> wrote:

> I have since updated my code to do just that...  So to "fix" this, I  
> need to iterate through all the docs in the index and add in a false  
> value if the "hasattachments" field is not present.
>
> Is there a specific test for presence of a field, or do I just catch  
> an exception?
>
> Thanks.
>
> --------------------------------------------------
> From: "Michael Garski" <mg...@myspace-inc.com>
> Sent: Wednesday, December 16, 2009 4:38 PM
> To: <lu...@incubator.apache.org>
> Subject: Re: Query For Unpopulated Fields
>
>> Jerry,
>>
>> If you want to query for items without attachments you will want  
>> to  index them with the value of 'false' in that field.
>>
>> Michael
>>
>> On Dec 16, 2009, at 1:24 PM, "Jerry Camel" <rl...@msn.com> wrote:
>>
>>> Okay...  I stored a bunch of documents.  One of the fields is  
>>> called "hasattachments".  If the document has an attachment, I  
>>> stored the  value "true" in that field.  I didn't do the  
>>> converse...  I never  stored "false" if the document didn't have  
>>> attachments.  So it  appears that documents without attachments  
>>> don't have that field.   So I was trying to devise a way to query  
>>> for all documents that  don't have attachments.
>>>
>>> Does that clear it up?
>>>
>>> Thanks.
>>>
>>> Jerry
>>>
>>> --------------------------------------------------
>>> From: "Shashi Kant" <sk...@sloan.mit.edu>
>>> Sent: Wednesday, December 16, 2009 4:13 PM
>>> To: <lu...@incubator.apache.org>
>>> Subject: Re: Query For Unpopulated Fields
>>>
>>>> Jerry, there are several reasons other members might have stayed   
>>>> quiet. I
>>>> will give you mine. Your question did not make sense to me and  
>>>> it  would be
>>>> helpful if you could elaborate a bit without being too verbose.
>>>>
>>>> I am guessing you are looking for something like the EXCLUDE   
>>>> statement in
>>>> SQL. I am not aware of any Lucene method that would do it. But  
>>>> you could
>>>> approach it by storing the *fieldname* itself as a value in your   
>>>> index and
>>>> query.
>>>>
>>>> hth
>>>>
>>>> On Wed, Dec 16, 2009 at 1:17 PM, Jerry Camel <rl...@msn.com>  
>>>> wrote:
>>>>
>>>>> Anyone? ...  Does no response mean it's not possible or that  
>>>>> it's  such a
>>>>> newbie question that nobody will dignify it with a response?
>>>>>
>>>>> J
>>>>>
>>>>> --------------------------------------------------
>>>>> From: "Jerry Camel" <rl...@msn.com>
>>>>> Sent: Tuesday, December 15, 2009 11:35 PM
>>>>> To: <lu...@incubator.apache.org>
>>>>> Subject: Query For Unpopulated Fields
>>>>>
>>>>>
>>>>> Is it possible to query for docs that do not have a specific field
>>>>>> present?
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> J
>>>>>>
>>>>>
>>>>>
>>>
>>
>


Re: Query For Unpopulated Fields

Posted by Jerry Camel <rl...@msn.com>.
I have since updated my code to do just that...  So to "fix" this, I need to 
iterate through all the docs in the index and add in a false value if the 
"hasattachments" field is not present.

Is there a specific test for presence of a field, or do I just catch an 
exception?

Thanks.

--------------------------------------------------
From: "Michael Garski" <mg...@myspace-inc.com>
Sent: Wednesday, December 16, 2009 4:38 PM
To: <lu...@incubator.apache.org>
Subject: Re: Query For Unpopulated Fields

> Jerry,
>
> If you want to query for items without attachments you will want to  index 
> them with the value of 'false' in that field.
>
> Michael
>
> On Dec 16, 2009, at 1:24 PM, "Jerry Camel" <rl...@msn.com> wrote:
>
>> Okay...  I stored a bunch of documents.  One of the fields is called 
>> "hasattachments".  If the document has an attachment, I stored the  value 
>> "true" in that field.  I didn't do the converse...  I never  stored 
>> "false" if the document didn't have attachments.  So it  appears that 
>> documents without attachments don't have that field.   So I was trying to 
>> devise a way to query for all documents that  don't have attachments.
>>
>> Does that clear it up?
>>
>> Thanks.
>>
>> Jerry
>>
>> --------------------------------------------------
>> From: "Shashi Kant" <sk...@sloan.mit.edu>
>> Sent: Wednesday, December 16, 2009 4:13 PM
>> To: <lu...@incubator.apache.org>
>> Subject: Re: Query For Unpopulated Fields
>>
>>> Jerry, there are several reasons other members might have stayed  quiet. 
>>> I
>>> will give you mine. Your question did not make sense to me and it  would 
>>> be
>>> helpful if you could elaborate a bit without being too verbose.
>>>
>>> I am guessing you are looking for something like the EXCLUDE  statement 
>>> in
>>> SQL. I am not aware of any Lucene method that would do it. But you 
>>> could
>>> approach it by storing the *fieldname* itself as a value in your  index 
>>> and
>>> query.
>>>
>>> hth
>>>
>>> On Wed, Dec 16, 2009 at 1:17 PM, Jerry Camel <rl...@msn.com> wrote:
>>>
>>>> Anyone? ...  Does no response mean it's not possible or that it's  such 
>>>> a
>>>> newbie question that nobody will dignify it with a response?
>>>>
>>>> J
>>>>
>>>> --------------------------------------------------
>>>> From: "Jerry Camel" <rl...@msn.com>
>>>> Sent: Tuesday, December 15, 2009 11:35 PM
>>>> To: <lu...@incubator.apache.org>
>>>> Subject: Query For Unpopulated Fields
>>>>
>>>>
>>>> Is it possible to query for docs that do not have a specific field
>>>>> present?
>>>>>
>>>>> Thanks.
>>>>>
>>>>> J
>>>>>
>>>>
>>>>
>>
>
> 

Re: Query For Unpopulated Fields

Posted by Shashi Kant <sk...@sloan.mit.edu>.
try, a boolean query with a MUST_NOT clause. something like...

BooleanQuery bq = new BooleanQuery()
Query noattach = qp.Parse("hasAttachments",...)
bq.Add(noattach, BooleanClause.Occur.MUST_NOT)


On Dec 16, 2009, at 1:24 PM, "Jerry Camel" <rl...@msn.com> wrote:
>
>  Okay...  I stored a bunch of documents.  One of the fields is called
>> "hasattachments".  If the document has an attachment, I stored the value
>> "true" in that field.  I didn't do the converse...  I never stored "false"
>> if the document didn't have attachments.  So it appears that documents
>> without attachments don't have that field.  So I was trying to devise a way
>> to query for all documents that don't have attachments.
>>
>> Does that clear it up?
>>
>> Thanks.
>>
>> Jerry
>>
>> --------------------------------------------------
>> From: "Shashi Kant" <sk...@sloan.mit.edu>
>> Sent: Wednesday, December 16, 2009 4:13 PM
>> To: <lu...@incubator.apache.org>
>> Subject: Re: Query For Unpopulated Fields
>>
>>  Jerry, there are several reasons other members might have stayed quiet. I
>>> will give you mine. Your question did not make sense to me and it would
>>> be
>>> helpful if you could elaborate a bit without being too verbose.
>>>
>>> I am guessing you are looking for something like the EXCLUDE statement in
>>> SQL. I am not aware of any Lucene method that would do it. But you could
>>> approach it by storing the *fieldname* itself as a value in your index
>>> and
>>> query.
>>>
>>> hth
>>>
>>> On Wed, Dec 16, 2009 at 1:17 PM, Jerry Camel <rl...@msn.com> wrote:
>>>
>>>  Anyone? ...  Does no response mean it's not possible or that it's such a
>>>> newbie question that nobody will dignify it with a response?
>>>>
>>>> J
>>>>
>>>> --------------------------------------------------
>>>> From: "Jerry Camel" <rl...@msn.com>
>>>> Sent: Tuesday, December 15, 2009 11:35 PM
>>>> To: <lu...@incubator.apache.org>
>>>> Subject: Query For Unpopulated Fields
>>>>
>>>>
>>>> Is it possible to query for docs that do not have a specific field
>>>>
>>>>> present?
>>>>>
>>>>> Thanks.
>>>>>
>>>>> J
>>>>>
>>>>>
>>>>
>>>>
>>
>

Re: Query For Unpopulated Fields

Posted by Michael Garski <mg...@myspace-inc.com>.
Jerry,

If you want to query for items without attachments you will want to  
index them with the value of 'false' in that field.

Michael

On Dec 16, 2009, at 1:24 PM, "Jerry Camel" <rl...@msn.com> wrote:

> Okay...  I stored a bunch of documents.  One of the fields is called  
> "hasattachments".  If the document has an attachment, I stored the  
> value "true" in that field.  I didn't do the converse...  I never  
> stored "false" if the document didn't have attachments.  So it  
> appears that documents without attachments don't have that field.   
> So I was trying to devise a way to query for all documents that  
> don't have attachments.
>
> Does that clear it up?
>
> Thanks.
>
> Jerry
>
> --------------------------------------------------
> From: "Shashi Kant" <sk...@sloan.mit.edu>
> Sent: Wednesday, December 16, 2009 4:13 PM
> To: <lu...@incubator.apache.org>
> Subject: Re: Query For Unpopulated Fields
>
>> Jerry, there are several reasons other members might have stayed  
>> quiet. I
>> will give you mine. Your question did not make sense to me and it  
>> would be
>> helpful if you could elaborate a bit without being too verbose.
>>
>> I am guessing you are looking for something like the EXCLUDE  
>> statement in
>> SQL. I am not aware of any Lucene method that would do it. But you  
>> could
>> approach it by storing the *fieldname* itself as a value in your  
>> index and
>> query.
>>
>> hth
>>
>> On Wed, Dec 16, 2009 at 1:17 PM, Jerry Camel <rl...@msn.com> wrote:
>>
>>> Anyone? ...  Does no response mean it's not possible or that it's  
>>> such a
>>> newbie question that nobody will dignify it with a response?
>>>
>>> J
>>>
>>> --------------------------------------------------
>>> From: "Jerry Camel" <rl...@msn.com>
>>> Sent: Tuesday, December 15, 2009 11:35 PM
>>> To: <lu...@incubator.apache.org>
>>> Subject: Query For Unpopulated Fields
>>>
>>>
>>> Is it possible to query for docs that do not have a specific field
>>>> present?
>>>>
>>>> Thanks.
>>>>
>>>> J
>>>>
>>>
>>>
>


Re: Query For Unpopulated Fields

Posted by Jerry Camel <rl...@msn.com>.
Okay...  I stored a bunch of documents.  One of the fields is called 
"hasattachments".  If the document has an attachment, I stored the value 
"true" in that field.  I didn't do the converse...  I never stored "false" 
if the document didn't have attachments.  So it appears that documents 
without attachments don't have that field.  So I was trying to devise a way 
to query for all documents that don't have attachments.

Does that clear it up?

Thanks.

Jerry

--------------------------------------------------
From: "Shashi Kant" <sk...@sloan.mit.edu>
Sent: Wednesday, December 16, 2009 4:13 PM
To: <lu...@incubator.apache.org>
Subject: Re: Query For Unpopulated Fields

> Jerry, there are several reasons other members might have stayed quiet. I
> will give you mine. Your question did not make sense to me and it would be
> helpful if you could elaborate a bit without being too verbose.
>
> I am guessing you are looking for something like the EXCLUDE statement in
> SQL. I am not aware of any Lucene method that would do it. But you could
> approach it by storing the *fieldname* itself as a value in your index and
> query.
>
> hth
>
> On Wed, Dec 16, 2009 at 1:17 PM, Jerry Camel <rl...@msn.com> wrote:
>
>> Anyone? ...  Does no response mean it's not possible or that it's such a
>> newbie question that nobody will dignify it with a response?
>>
>> J
>>
>> --------------------------------------------------
>> From: "Jerry Camel" <rl...@msn.com>
>> Sent: Tuesday, December 15, 2009 11:35 PM
>> To: <lu...@incubator.apache.org>
>> Subject: Query For Unpopulated Fields
>>
>>
>>  Is it possible to query for docs that do not have a specific field
>>> present?
>>>
>>> Thanks.
>>>
>>> J
>>>
>>
>>
> 

Re: Query For Unpopulated Fields

Posted by Shashi Kant <sk...@sloan.mit.edu>.
Jerry, there are several reasons other members might have stayed quiet. I
will give you mine. Your question did not make sense to me and it would be
helpful if you could elaborate a bit without being too verbose.

I am guessing you are looking for something like the EXCLUDE statement in
SQL. I am not aware of any Lucene method that would do it. But you could
approach it by storing the *fieldname* itself as a value in your index and
query.

hth

On Wed, Dec 16, 2009 at 1:17 PM, Jerry Camel <rl...@msn.com> wrote:

> Anyone? ...  Does no response mean it's not possible or that it's such a
> newbie question that nobody will dignify it with a response?
>
> J
>
> --------------------------------------------------
> From: "Jerry Camel" <rl...@msn.com>
> Sent: Tuesday, December 15, 2009 11:35 PM
> To: <lu...@incubator.apache.org>
> Subject: Query For Unpopulated Fields
>
>
>  Is it possible to query for docs that do not have a specific field
>> present?
>>
>> Thanks.
>>
>> J
>>
>
>

Re: Query For Unpopulated Fields

Posted by Jerry Camel <rl...@msn.com>.
Anyone? ...  Does no response mean it's not possible or that it's such a 
newbie question that nobody will dignify it with a response?

J

--------------------------------------------------
From: "Jerry Camel" <rl...@msn.com>
Sent: Tuesday, December 15, 2009 11:35 PM
To: <lu...@incubator.apache.org>
Subject: Query For Unpopulated Fields

> Is it possible to query for docs that do not have a specific field 
> present?
>
> Thanks.
>
> J