Created
March 12, 2009 15:14
-
-
Save ArtemGr/78115 to your computer and use it in GitHub Desktop.
Lucene matching non-empty fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Skip attachments (images, documents, etc.) - all those files without "_id". | |
booleanQuery.add (new NotEmptyQuery (new Term ("alt__id")), BooleanClause.Occur.MUST) | |
// Skip removed objects (_removed = time of removal in milliseconds). | |
booleanQuery.add (new NotEmptyQuery (new Term ("alt__removed")), BooleanClause.Occur.MUST_NOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.lucene.search._, org.apache.lucene.document._, org.apache.lucene.index._ | |
class NotEmptyQuery (emptyTerm: Term) extends MultiTermQuery { | |
override def toString (field: String) = "NotEmptyQuery(" + (if ((field ne null) && field.length != 0) field else emptyTerm.field) + ")" | |
override def getEnum (reader: IndexReader) = new FilteredTermEnum { | |
setEnum (reader.terms (emptyTerm)) // Position at the start of the field terms. | |
var theEnd = false | |
override def termCompare (term: Term): Boolean = | |
if (term.field == emptyTerm.field && term.text != emptyTerm.text) true else {theEnd = true; false} | |
override def difference (): Float = 1 | |
override def endEnum (): Boolean = theEnd | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment