You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/08/30 10:04:30 UTC
svn commit: r264730 - in
/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene:
SharedFieldCache.java SharedFieldSortComparator.java
Author: mreutegg
Date: Tue Aug 30 01:04:25 2005
New Revision: 264730
URL: http://svn.apache.org/viewcvs?rev=264730&view=rev
Log:
Optimize queries with 'order by' clause
Modified:
incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java?rev=264730&r1=264729&r2=264730&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java Tue Aug 30 01:04:25 2005
@@ -57,7 +57,9 @@
* <code>prefix</code>. The term prefix acts as the property name for the
* shared <code>field</code>.
* <p/>
- * This method is an adapted version of: <code>org.apache.lucene.search.FieldCacheImpl.getStringIndex()</code>
+ * This method is an adapted version of: <code>FieldCacheImpl.getStringIndex()</code>
+ * The returned string index will <b>not</b> have a term lookup array!
+ * See {@link SharedFieldSortComparator} for more info.
*
* @param reader the <code>IndexReader</code>.
* @param field name of the shared field.
@@ -76,17 +78,13 @@
FieldCache.StringIndex ret = lookup(reader, field, prefix, comparator);
if (ret == null) {
final int[] retArray = new int[reader.maxDoc()];
- String[] mterms = new String[reader.maxDoc() + 1];
if (retArray.length > 0) {
TermDocs termDocs = reader.termDocs();
TermEnum termEnum = reader.terms(new Term(field, prefix));
- int t = 0; // current term number
-
- // an entry for documents that have no terms in this field
- // should a document with no terms be at top or bottom?
- // this puts them at the top - if it is changed, FieldDocSortedHitQueue
- // needs to change as well.
- mterms[t++] = null;
+ // documents without a term will have a term number = 0
+ // thus will be at the top, this needs to be in sync with
+ // the implementation of FieldDocSortedHitQueue
+ int t = 1; // current term number
try {
if (termEnum.term() == null) {
@@ -98,13 +96,6 @@
break;
}
- // store term text
- // we expect that there is at most one term per document
- if (t >= mterms.length) {
- throw new RuntimeException("there are more terms than documents in field \"" + field + "\"");
- }
- mterms[t] = term.text();
-
termDocs.seek(termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = t;
@@ -116,20 +107,8 @@
termDocs.close();
termEnum.close();
}
-
- if (t == 0) {
- // if there are no terms, make the term array
- // have a single null entry
- mterms = new String[1];
- } else if (t < mterms.length) {
- // if there are less terms than documents,
- // trim off the dead array space
- String[] terms = new String[t];
- System.arraycopy(mterms, 0, terms, 0, t);
- mterms = terms;
- }
}
- FieldCache.StringIndex value = new FieldCache.StringIndex(retArray, mterms);
+ FieldCache.StringIndex value = new FieldCache.StringIndex(retArray, null);
store(reader, field, prefix, comparator, value);
return value;
}
Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java?rev=264730&r1=264729&r2=264730&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java Tue Aug 30 01:04:25 2005
@@ -12,6 +12,13 @@
/**
* Implements a <code>SortComparator</code> which knows how to sort on a lucene
* field that contains values for multiple properties.
+ * <p/>
+ * <b>Important:</b> The ScoreDocComparator returned by {@link #newComparator}
+ * does not implement the contract for {@link ScoreDocComparator#sortValue(ScoreDoc)}
+ * properly. The method will always return an empty String to save memory consumption
+ * on large property ranges. Those values are only of relevance when queries
+ * are executed with a <code>MultiSearcher</code>, which is currently not the
+ * case in Jackrabbit.
*/
class SharedFieldSortComparator extends SortComparator {
@@ -43,7 +50,7 @@
* @return a <code>ScoreDocComparator</code> for the
* @throws IOException
*/
- public ScoreDocComparator newComparator(IndexReader reader, String propertyName)
+ public ScoreDocComparator newComparator(final IndexReader reader, String propertyName)
throws IOException {
// get the StringIndex for propertyName
final FieldCache.StringIndex index
@@ -51,20 +58,26 @@
propertyName, SharedFieldSortComparator.this);
return new ScoreDocComparator() {
- public final int compare (final ScoreDoc i, final ScoreDoc j) {
- final int fi = index.order[i.doc];
- final int fj = index.order[j.doc];
- if (fi < fj) {
- return -1;
- } else if (fi > fj) {
- return 1;
- } else {
- return 0;
- }
+ public final int compare(final ScoreDoc i, final ScoreDoc j) {
+ final int fi = index.order[i.doc];
+ final int fj = index.order[j.doc];
+ if (fi < fj) {
+ return -1;
+ } else if (fi > fj) {
+ return 1;
+ } else {
+ return 0;
+ }
}
- public Comparable sortValue (final ScoreDoc i) {
- return index.lookup[index.order[i.doc]];
+ /**
+ * Always returns an empty String.
+ * @param i the score doc.
+ * @return an empty String.
+ */
+ public Comparable sortValue(final ScoreDoc i) {
+ // return dummy value
+ return "";
}
public int sortType() {