added count(fieldName, fieldValue) to helma.Search.Index prototype, returning the number of documents with a given field and value in the index
This commit is contained in:
parent
17e8ea6d82
commit
1893ab3494
3 changed files with 19 additions and 0 deletions
|
@ -395,6 +395,25 @@ helma.Search.Index.prototype.size = function() {
|
|||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the number of documents with the given field name and value.
|
||||
* @param {String} fieldName The name of the field
|
||||
* @param {String} fieldValue The value of the field
|
||||
* @returns The number of documents
|
||||
* @type Number
|
||||
*/
|
||||
helma.Search.Index.prototype.count = function(fieldName, fieldValue) {
|
||||
try {
|
||||
var reader = this.getReader();
|
||||
var term = new Packages.org.apache.lucene.index.Term(fieldName, fieldValue);
|
||||
return reader.docFreq(term);
|
||||
} finally {
|
||||
if (reader !== null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Optimizes the underlying index.
|
||||
*/
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue