import { TagRels } from './collection.js';
import { ensureIndex } from '../../collectionUtils';

TagRels.addDefaultView(terms => {
  return {
    selector: {
      deleted: false,
    },
  };
});

TagRels.addView('postsWithTag', terms => {
  return {
    selector: {
      tagId: terms.tagId,
      baseScore: {$gt: 0},
    },
    sort: {baseScore: -1},
  }
});

TagRels.addView('tagsOnPost', terms => {
  return {
    selector: {
      postId: terms.postId,
      baseScore: {$gt: 0},
    },
    sort: {baseScore: -1},
  }
});

ensureIndex(TagRels, {postId:1});
ensureIndex(TagRels, {tagId:1});

@@ -184,13 +184,64 @@
  %7D,%0A
+    options: %7B%0A      sort: %7BbaseScore: -1%7D,%0A    %7D,%0A
   %7D;%0A
-
 %7D);%0A
@@ -375,35 +375,8 @@
  %7D,%0A
-    sort: %7BbaseScore: -1%7D,%0A
   %7D%0A
@@ -507,42 +507,15 @@
 0%7D,%0A
+
     %7D,%0A
-    sort: %7BbaseScore: -1%7D,%0A
   %7D%0A

Fix relevance-sorting on tag page