Hi Mathieu,
For a simple case like that, your class bridge should work like that (from
memory):
[Indexed]
[ClassBridge(typeof(ClassBridge))]
public class Entity
{
public string Foo{get;set;}
public string Bar{get;set;}
}
public class ClassBridge:IFieldBridge
{
public void Set(string name, object value, Document document,
Field.Store store, Field.Index index, float? boost)
{
var entity = (Entity) value;
Field f = new Field("fieldName",entity.Foo + " " + entity.Bar,
Store.No, Index.Tokenized);
document.AddField(f);
}
}
The bridge basically allows you to fall back to Lucene when you need it.
Simon
On Fri, Oct 16, 2009 at 6:39 PM, mathieu <[email protected]> wrote:
>
> Hi Simon,
>
> Thank you for the source code, but it doesn't work in my case : I need
> all fields from the current object, and put them in another field of
> this same object.
> So i get a stackoverflow on Builder.GetDocument(). This solution was
> so nice to be true :)
>
> Still searching how to do it cleanly.
>
> On 16 oct, 22:50, Simon Laroche <[email protected]> wrote:
> > Hi Mathieu,
> >
> > There you go,
> >
> > This bridge ads fields from another object into the current object. It
> could
> > be as simple as creating a field, adding values from the object and
> adding
> > the field to the document.
> >
> > Some of the names are in French but my guess is that you can understand
> ;)
> >
> > [Indexed]
> > [ClassBridge(typeof(StatutDAjustementQualitatifClassBridge))]
> > public class StatutDAjustementQualitatif
> > {
> > ...
> > }
> >
> > public class StatutDAjustementQualitatifClassBridge:IFieldBridge
> > {
> > public void Set(string name, object value, Document document,
> > Field.Store store, Field.Index index, float? boost)
> > {
> > if(!(value is StatutDAjustementQualitatif))
> > {
> > throw new ArgumentException("Value should be of type
> > StatutDAjustementQualitatif for this bridge to work properly", "value");
> > }
> >
> > var statutDAjustementQualitatif =
> (StatutDAjustementQualitatif)
> > value;
> > var intervenant = statutDAjustementQualitatif.Intervenant;
> >
> > Debug.Assert(intervenant != null, "Intervenant should never
> be
> > null");
> >
> > Configuration cfg =
> > ActiveRecordMediator.GetSessionFactoryHolder().GetConfiguration(typeof
> > (ActiveRecordBase));
> > NHibernate.Search.Impl.SearchFactoryImpl factoryImpl =
> > NHibernate.Search.Impl.SearchFactoryImpl.GetSearchFactory(cfg);
> >
> > DocumentBuilder builder =
> > factoryImpl.GetDocumentBuilder(intervenant.GetType());
> >
> > if(builder == null)
> > {
> > throw new InvalidOperationException(
> > string.Format("No document builder could be found for
> > {0} type. Make sure the type {0} is marked with the Indexed attribute.",
> > intervenant.GetType()));
> > }
> >
> > Document intervenantDoc = builder.GetDocument(intervenant,
> 0);
> >
> > //Use only fields no declared in SAQ
> > foreach (Field field in intervenantDoc.Fields())
> > {
> > if(document.GetField(field.Name()) == null)
> > {document.Add(field);}
> > }
> > }
> > }
> >
> > On Fri, Oct 16, 2009 at 7:40 AM, mathieu <[email protected]>
> wrote:
> >
> > > Hi Simon,
> >
> > > Is it possible for you to share the code ? I tried this approach but I
> > > couldn't find an easy way to get all indexed fields of my entity...
> >
> > > Thanks,
> > > Mathieu
> >
> > > On Oct 16, 1:15 pm, Simon Laroche <[email protected]> wrote:
> > > > Hi Mathieu,
> >
> > > > Then way I do this is by creating a class bridge. That way you can
> create
> > > > and manipulate any field in the document ans you have access to your
> > > object.
> >
> > > > Simon
> >
> > > > On Fri, Oct 16, 2009 at 5:34 AM, mathieu <[email protected]>
> > > wrote:
> >
> > > > > Hello everyone,
> >
> > > > > How could I index "all" fields of my classes to make searching them
> > > > > easier ?
> > > > > For example, I have the following class :
> >
> > > > > [Indexed(Index="Index")]
> > > > > public class MyEntity
> > > > > {
> > > > > [DocumentId]
> > > > > public virtual long Id { get; set; }
> >
> > > > > Field(Index.Tokenized, Store = Store.Yes)]
> > > > > public virtual string Title { get; set; }
> >
> > > > > [Field(Index.Tokenized, Store = Store.Yes)]
> > > > > public virtual string Description { get; set; }
> > > > > }
> >
> > > > > I would like to index both Title and Description in an "AllFields"
> > > > > Field, so when I want to search in any fields, I just query
> > > > > "AllFields:something". It's easy to do directly in Lucene.Net, but
> I
> > > > > can't find a way to do the same in NHibernate.Search.
> >
> > > > > I've tried :
> > > > > 1 - Putting an attribute [Field(Index.Tokenized, Store = Store.Yes,
> > > > > Name="All")] on all fields that I want indexed that way, but
> > > > > ScopedAnalyzer throws an exceptionon line 26 : scopedAnalyzers.Add
> > > > > (scope, analyzer);
> > > > > So i've added "if( !scopedAnalyzers.ContainsKey( scope ) )" just
> > > > > before. But I don't like it very much...
> > > > > 2 - Modifying DocumentBuilder.cs, line 392, by adding :
> > > > > propertiesMetadata.fieldBridges[i].Set(
> > > > > "AllFields",
> > > > > value,
> > > > > doc,
> > > > > propertiesMetadata.fieldStore[i],
> > > > > propertiesMetadata.fieldIndex[i],
> > > > > GetBoost(member));
> > > > > But I don't like it very much neither...
> >
> > > > > Anyone got an idea ? I "need" this "AllFields" Field so I can
> search
> > > > > all my index, and return "all" Documents that match my query,
> > > > > regardless of their fields or type.
> >
> > > > > Thanks in advance,
> > > > > Mathieu
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---