matteodem / meteor-easy-search

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

Using nested fields #484

Closed elsacha closed 8 years ago

elsacha commented 8 years ago

Hello, Thank you for this package. I have a question concerning displaying nested fields. I have an index by a nested field GlossariesIndex = new EasySearch.Index({ collection: Glossaries, fields: ['terms.source_term'], engine: new EasySearch.MongoDB() });

but when I display the results: `{{#EasySearch.Each index=glossariesIndex }}

  • Source: {{terms.source_term}}
  •     {{/EasySearch.Each}}`

    nothing is displayed. If I try to display other, not nested fields in the returned documents, they are displayed correctly. If I try to display 'terms' without nested fields, I get 'Source: [object Object],[object Object]'. But I cannot display the object fields.

    I would be grateful for any insight on this issue.

    matteodem commented 8 years ago

    To me terms sounds like an array, so you should loop through terms and check if that does what you want. If not, please show me an example document.

    elsacha commented 8 years ago

    Thank you very much for your reply. Yes, terms is an array and I try to search by one of its values. If I understand correctly, easy search returns the whole document with all the fields including the array. I just wanted to find a way to display only the matched array value (not other values in the array). You can see the schema here https://github.com/elsacha/meteor_glossaries/blob/master/lib/collections.js And I am trying to display it like this:

    {{#EasySearch.Each index=glossariesIndex }}
                  <li><a href="/view/{{this._id}}">{{title}} - {{terms.source_term}}</a></li>
              {{/EasySearch.Each}}

    I just need to display the term of the array which was matched (not other terms in this array).

    But I agree, this is not an issue with the package, it's just that I am trying to figure out how to achieve this.

    matteodem commented 8 years ago

    I'm sorry but I'm just to here to answer questions regarding the package, otherwise the scope of this project will be too big. Ask on the meteor forum or stack overflow if it's a general question, thanks