Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It would help to see how you are querying exactly, but you should take a look at <a href="http://ravendb.net/kb/11/querying-unlike-documents-using-a-multi-map-index" rel="nofollow">the example on querying unlike documents with a multimap index</a> on the RavenDB site.</p> <p>When I look at your index, it seems like you are trying to do way too much in terms of field storage and encapsulation of your results. It's sometimes difficult to grasp, but the mapping done in the index is not to define how the results are returned, but rather how the index is built. Unless you are doing a Reduce or TransformResults step, you are still returning the original document.</p> <p>So encapsulating the document as <code>Result = (object)item</code> is overkill. So is having a ResultType enum. If you need to know the type of document that matched, simply use <code>.GetType()</code> on the object and you will quickly see if it is a User or an Asset.</p> <p>Here is how I would define your search index. Note there's some differences because there were properties you showed in your index that aren't in the models you provided. (I'm assuming there is a separate entity on the backend than the models on the front end, but adjust as needed.)</p> <pre><code>public class SearchIndex : AbstractMultiMapIndexCreationTask&lt;SearchIndex.Result&gt; { public class Result { public object[] Content { get; set; } public string ResultType { get; set; } } public SearchIndex() { AddMap&lt;Asset&gt;(items =&gt; from item in items select new Result { Content = new object[] {item.Name, item.Description}, ResultType = MetadataFor(item)["Raven-Entity-Name"].ToString() }); AddMap&lt;User&gt;(items =&gt; from item in items select new Result { Content = new object[] { item.Username, item.FirstName, item.LastName, item.Email }, ResultType = MetadataFor(item)["Raven-Entity-Name"].ToString() }); Index(x =&gt; x.Content, FieldIndexing.Analyzed); } } </code></pre> <p>And then I would query it like so:</p> <pre><code>var results = session.Advanced .LuceneQuery&lt;object, SearchIndex&gt;() .Where("ResultType:" + resultTypeName) .AndAlso() .Search("Content", searchTerm); </code></pre> <p>You can then simply examine your results and find that while cast as <code>object</code>, you can indeed do <code>result.GetType()</code> and see how that object is constructed. If desired, you could also put a common interface on your entities to cast to instead of object, such as the <code>IAmSearchable</code> shown in the Raven example.</p> <p>When you finally pass your result back through MVC, it should be serialized properly, since it will be coming from the real object and not the raven DynamicJsonObject.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload