You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by na...@apache.org on 2007/07/25 04:24:27 UTC
svn commit: r559286 -
/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java
Author: natalia
Date: Tue Jul 24 19:24:26 2007
New Revision: 559286
URL: http://svn.apache.org/viewvc?view=rev&rev=559286
Log:
Fix for search over wildcard index
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java?view=diff&rev=559286&r1=559285&r2=559286
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java Tue Jul 24 19:24:26 2007
@@ -109,7 +109,7 @@
public void remove(String value, Key key, int pos, int len, short elemID, short attrID) throws DBException {
try {
- removeValue(key);
+ removeValue(getCombinedValue(key, pos, len, elemID, attrID));
} catch (IOException e) {
throw new BTreeCorruptException("Corruption detected on remove", e);
}
@@ -117,12 +117,62 @@
public void add(String value, Key key, int pos, int len, short elemID, short attrID) throws DBException {
try {
- addValue(key, 0);
+ addValue(getCombinedValue(key, pos, len, elemID, attrID), 0);
} catch (IOException e) {
throw new BTreeCorruptException("Corruption detected on add", e);
}
}
+ private Value getCombinedValue(Key key, int pos, int len, short elemID, short attrID) {
+ Value result;
+ try {
+ int l = key.getLength();
+ byte[] b = new byte[l + 13];
+
+ // Write the key
+ key.copyTo(b, 0, l);
+ b[l] = 0;
+
+ // Write the pos
+ b[l + 1] = (byte) ((pos >>> 24) & 0xFF);
+ b[l + 2] = (byte) ((pos >>> 16) & 0xFF);
+ b[l + 3] = (byte) ((pos >>> 8) & 0xFF);
+ b[l + 4] = (byte) ( pos & 0xFF);
+
+ // Write the len
+ b[l + 5] = (byte) ((len >>> 24) & 0xFF);
+ b[l + 6] = (byte) ((len >>> 16) & 0xFF);
+ b[l + 7] = (byte) ((len >>> 8) & 0xFF);
+ b[l + 8] = (byte) ( len & 0xFF);
+
+ // Write the elemID
+ b[l + 9] = (byte) ((elemID >>> 8) & 0xFF);
+ b[l + 10] = (byte) ( elemID & 0xFF);
+
+ // Write the attrID
+ b[l + 11] = (byte) ((attrID >>> 8) & 0xFF);
+ b[l + 12] = (byte) ( attrID & 0xFF);
+
+ result = new Value(b);
+ } catch (Exception e) {
+ result = null; // This will never happen
+ }
+ return result;
+ }
+
+ private IndexMatch getIndexMatch(Value v) {
+ byte[] b = v.getData();
+ int l = b.length - 13;
+ Key key = new Key(b, 0, b.length - 13);
+
+ int pos = ((b[l + 1] << 24) | (b[l + 2] << 16) | (b[l + 3] << 8) | b[l + 4]);
+ int len = ((b[l + 5] << 24) | (b[l + 6] << 16) | (b[l + 7] << 8) | b[l + 8]);
+ short elemID = (short) ((b[l + 9] << 8) | b[l + 10]);
+ short attrID = (short) ((b[l + 11] << 8) | b[l + 12]);
+
+ return new IndexMatch(key, pos, len, elemID, attrID);
+ }
+
public IndexMatch[] queryMatches(final IndexQuery query) throws DBException {
final List results = new ArrayList();
final IndexPattern pattern = query.getPattern();
@@ -130,7 +180,15 @@
try {
query(query, new BTreeCallback() {
public boolean indexInfo(Value value, long pos) {
- results.add(new IndexMatch(new Key(value), pattern));
+ IndexMatch match = getIndexMatch(value);
+ if (wildcard) {
+ IndexPattern pt = new IndexPattern(symbols, match.getElement(), match.getAttribute());
+ if (pt.getMatchLevel(pattern) > 0) {
+ results.add(match);
+ }
+ } else {
+ results.add(match);
+ }
return true;
}
});