(N) Hibernate.Search: index different properties in one field

When I used Lucene to index my objects, I was in the habit of putting all my indexed properties in a field called "all" to search on "all" types of objects.

Now, using NHibernate.Search, I cannot find how to do this. I tried this:

[Indexed(Index = "MyIndex")]
public class Post
{
    [DocumentId]
    public virtual int Id { get; set; }
    [IndexedEmbedded]
    public virtual Author Author { get; set; }
    [IndexedEmbedded]
    public virtual IEnumerable<Category> Categories { get; set; }
    [Field(Index.Tokenized, Store = Store.Yes)]
    [Field(Name = "All", Index = Index.Tokenized, Store = Store.Yes)]
    public virtual string Name { get; set; }
    [Field(Name = "All", Index = Index.Tokenized, Store = Store.Yes)]
    [Field(Index.Tokenized, Store = Store.Yes)]
    public virtual string Body { get; set; }
}

But I have an exception: "key is already present in the dictionary", in ScopedAnalyzer.cs line 26:

scopedAnalyzers.Add(scope, analyzer);

Where "scope" is the name of the index field (here "Everything"). If I put a check, for example

if( !scopedAnalyzers.ContainsKey( scope ) )

It will work very well: I will have 2 fields for each Mail document, one with a body, one with a name. However, I cannot easily modify the source code of NHibernate.Search.

- , ?

+3
1

Field, , , , .

ClassBridgeAttribute , IFieldBridge. , Lucene.

http://docs.jboss.org/hibernate/stable/search/reference/en/html/search-mapping-bridge.html 4.2.2.3. ClassBridge

+2

Source: https://habr.com/ru/post/1719793/


All Articles