Adding ability to add navigation data to the index, so that the effect of this feature on index size can be measured
1.1 --- a/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java Fri Jun 22 23:22:14 2012 +0200
1.2 +++ b/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java Tue Jun 26 05:19:38 2012 +0200
1.3 @@ -76,6 +76,7 @@
1.4 import javax.lang.model.util.ElementFilter;
1.5 import javax.lang.model.util.Elements;
1.6 import javax.lang.model.util.Types;
1.7 +import org.apache.lucene.document.CompressionTools;
1.8 import org.apache.lucene.document.Document;
1.9 import org.apache.lucene.document.Field;
1.10 import org.apache.lucene.document.Field.Index;
1.11 @@ -102,6 +103,7 @@
1.12 */
1.13 public class IndexerImpl implements JavaIndexerPlugin {
1.14
1.15 + private static final boolean NAVIGABLE = Boolean.getBoolean("jackpot.navigable.index");
1.16 private static final String KEY_SIGNATURES = "signatures";
1.17 private static final String KEY_MARKER = "usagesIndexMarker";
1.18
1.19 @@ -126,6 +128,9 @@
1.20 usages.add(new Field("file", file, Store.YES, Index.NOT_ANALYZED));
1.21 usages.add(new Field(KEY_MARKER, "true", Store.NO, Index.NOT_ANALYZED));
1.22
1.23 + final StringBuilder attributedSignatures = new StringBuilder();
1.24 + final StringBuilder attributedSubSignatures = new StringBuilder();
1.25 +
1.26 new TreePathScanner<Void, Void>() {
1.27 private final Set<String> SEEN_SIGNATURES = new HashSet<String>();
1.28 @Override public Void visitIdentifier(IdentifierTree node, Void p) {
1.29 @@ -150,6 +155,19 @@
1.30 usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
1.31 }
1.32
1.33 + long pos = trees.getSourcePositions().getStartPosition(getCurrentPath().getCompilationUnit(), getCurrentPath().getLeaf());
1.34 +
1.35 + if (NAVIGABLE) {
1.36 + attributedSignatures.append(Long.toString(pos));
1.37 + attributedSignatures.append(":");
1.38 + attributedSignatures.append(serialized);
1.39 + attributedSignatures.append(",");
1.40 + attributedSubSignatures.append(Long.toString(pos));
1.41 + attributedSubSignatures.append(":");
1.42 + attributedSubSignatures.append(serialized);
1.43 + attributedSubSignatures.append(",");
1.44 + }
1.45 +
1.46 if (el.getKind() == ElementKind.METHOD) {
1.47 for (ExecutableElement e : overrides(types, elements, (ExecutableElement) el)) {
1.48 serialized = Common.serialize(ElementHandle.create(e));
1.49 @@ -157,6 +175,13 @@
1.50 if (SEEN_SIGNATURES.add(serialized)) {
1.51 usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
1.52 }
1.53 +
1.54 + if (NAVIGABLE) {
1.55 + attributedSubSignatures.append(Long.toString(pos));
1.56 + attributedSubSignatures.append(":");
1.57 + attributedSubSignatures.append(serialized);
1.58 + attributedSubSignatures.append(",");
1.59 + }
1.60 }
1.61 }
1.62 }
1.63 @@ -263,6 +288,11 @@
1.64 }
1.65 }.scan(toProcess, null);
1.66
1.67 + if (NAVIGABLE) {
1.68 + usages.add(new Field("attributedSignatures", CompressionTools.compressString(attributedSignatures.toString())));
1.69 + usages.add(new Field("attributedSubSignatures", CompressionTools.compressString(attributedSubSignatures.toString())));
1.70 + }
1.71 +
1.72 IndexAccessor.getCurrent().getIndexWriter().addDocument(usages);
1.73 } catch (IOException ex) {
1.74 Exceptions.printStackTrace(ex);