Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Search For Empty Fields #107

Closed
Aleck-Sun opened this issue Apr 14, 2022 · 2 comments
Closed

How to Search For Empty Fields #107

Aleck-Sun opened this issue Apr 14, 2022 · 2 comments

Comments

@Aleck-Sun
Copy link

Hi, I've been trying to create a query that searches for documents that have an empty field. Currently, when creating the index I am just setting a documents' empty fields to a specific keyword like "EMPTYBLUGEFIELD" and creating a query for it. I was wondering if there was a more proper way to perform this search?

What I've been doing:
When creating index:

If field != "" {
	doc.AddField(bluge.NewKeywordField("Field", "FieldValue").StoreValue())
} else {
        doc.AddField(bluge.NewKeywordField("Field", "EMPTYBLUGEFIELD").StoreValue())
}

When searching:

query.AddShould(bluge.NewTermQuery("FieldValue").SetField("Field"))
query.AddShould(bluge.NewTermQuery("EMPTYBLUGEFIELD").SetField("Field"))
query.SetMinShould(1)
@mschoch
Copy link
Member

mschoch commented Apr 18, 2022

Hello,

So, there is nothing wrong with this approach, but it is worth pointing out that when using the keyword analyzer, the empty value is fine for indexing and searching as is. The keyword analyzer does not change the input at all, and the empty string is still a valid term (length 0).

I've added a test-case to illustrate this here: #110

This should perform the same, so if you already got it working there probably isn't a compelling reason to change, unless you just want to simplify things.

@Aleck-Sun
Copy link
Author

I see, thank you so much for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants