matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
435 stars 68 forks source link

Easy search with minimongo engine only returns certain fields #421

Closed Xenophyte closed 7 years ago

Xenophyte commented 8 years ago

Hi,

I'm using minimongo as my easy search engine because I need to filter results first with a composite publish. The trick works and I only get the filtered data, however the returned data only contains two fields:

{_id: undefined, name: "concept", description: ""}

despite the fact that in the client console I can access quite a bit more

{ _id: "DRNk7LhKjpkwqhoXD" attempts: 0 content: Object created_on: 1452264617921 description: "" dislikes: 0 grants: Object likes: 0 name: "unit" needs: Object successes: 0 type: "content" proto: Object }

How do I access the rest of the fields? (most importantly the _id!)

Thanks!

matteodem commented 8 years ago

Can you please show me your EasySearch configuration together with what exactly your problem is?

Xenophyte commented 8 years ago

My configuration:

NodesSearchIndex = new EasySearch.Index({
    collection: Nodes,
    fields: ['name', 'description'],
    engine: new EasySearch.Minimongo({
        selector: function(searchObject, options, aggregation) {
            var selector = this.defaultConfiguration().selector(searchObject, options, aggregation);
            if (options.search.props.type) {
                selector.type = options.search.props.type;
            };
            return selector;
        }
    })
});

I've got two collections: Nodes and Personal. The objects in personal connect a user to a node:

{ _id: xxxxxx,
  nodeId: yyyyyy,
  userId: zzzzzz,
  state: 0.8 }

I want to search only items in Nodes that have a state greater than 0.8 for the current logged user. My solution was to filter Nodes with a composite publish and then search the published data in Nodes with easy search for name, etc. An example of a Node is:

{ _id: yyyyy,
  name: "this node",
  description: "just a node" }
Xenophyte commented 8 years ago

So, like I wrote above, if I type in the search box "concept", I'll get only the the Nodes that contain the word "concept" in either their name or description, but the array of returned objects will contain an empty _id and not contain at all other fields. For example, if I type in my browser's console Nodes.findOne({name: "concept"}) I get

{ _id: akjfhSHJKQ, name: "concept", description: "no description", views: 12, likes: 6 }

but easysearch only returns

{ _id: undefined, name: "concept", description: "no description" }

matteodem commented 8 years ago

Are those properties dynamically computed? As in, not part of the raw mongo doc that's stored in the backend?

matteodem commented 8 years ago

I wasn't able to reproduce it locally with the easy-search leaderboard example. Please give me a reproduction repository or steps to reproduce with an empty project.

matteodem commented 7 years ago

Be sure to publish all your fields and then it should work as expected