These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NHibernate.Search does not return any results
PostPosted: Wed Oct 29, 2008 11:01 am 
Newbie

Joined: Wed Oct 29, 2008 10:44 am
Posts: 1
Hello there,

I been struggling with NH.Search for almost two days. My problem is that the following code returns nothing although the table used contains many records. I'm running out of ideas here so any help would be much appreciated.

Main method:

Code:
public class Program
    {
        private static Configuration cfg;
        private static ISessionFactory sf;
        private static ISessionFactory sessionFactory;

        private static void Main()
        {
            #region Init
            cfg = new Configuration();
            cfg.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
            cfg.SetProperty("hibernate.search.default.directory_provider", "NHibernate.Search.Storage.FSDirectoryProvider, NHibernate.Search");
            cfg.SetProperty("hibernate.search.default.indexBase", @"~\Index");
            cfg.SetProperty("hibernate.search.analyzer", "Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net");
            cfg.SetProperty("cache.use_query_cache", "false");
            cfg.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
            cfg.SetProperty("dialect", "NHibernate.Dialect.MsSql2005Dialect");
            cfg.SetProperty("connection.connection_string", @"server=PC-VIL8-NEW\LOCALTEST;initial catalog=OrbitorHR;user id=sa;password=Zip8920n;Connection Timeout=40;");
            cfg.SetProperty("show_sql", "true");
            cfg.Configure();
            sessionFactory = cfg.BuildSessionFactory();
            SearchFactory.Initialize(cfg, sessionFactory);
            ISession session = sessionFactory.OpenSession(new SearchInterceptor());
            IFullTextSession fullTextSession = Search.CreateFullTextSession(session);
            #endregion

            string query = "admin";
            Analyzer analyzer = new SimpleAnalyzer();
            MultiFieldQueryParser parser = new MultiFieldQueryParser(
                                           new string[] { "UserName", "LoweredUserName" },
                                           analyzer);
            Query queryObj = null;
            try
            {
                queryObj = parser.Parse(query);
            }
            catch (ParseException) { }
            IFullTextSession session2 = fullTextSession;
            IQuery nhQuery = session2.CreateFullTextQuery(queryObj, new Type[] { typeof(User) });
            IList<User> users = nhQuery.List<User>();
            Console.ReadKey(true);
        }
}


User.cs

Code:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate.Search;
using NHibernate.Search.Attributes;
using NHibernate.Search.Bridge.Builtin;
using Lucene.Net.Analysis.Standard;

namespace NHibernateSearch_Demo.Model
{

    [Indexed(Index = "User")]
    public class User
    {
        public User()
        {
       
        }

        private Guid? userID;
       
        [DocumentId(Name = "UserID")]
        [FieldBridge(typeof(GuidBridge))]
        public virtual Guid? UserID
        {
            get { return userID; }
            set { userID = value; }
        }

        private Guid? applicationID;
        public virtual Guid? ApplicationID
        {
            get { return applicationID; }
            set { applicationID = value; }
        }

        private string userName;
        [Field(Index.Tokenized, Store = Store.No)]
        [Analyzer(typeof(StandardAnalyzer))]
        public virtual string UserName
        {
            get { return userName; }
            set { userName = value; }
        }

        private string loweredUserName;
        [Field(Index.Tokenized, Store = Store.No)]
        [Analyzer(typeof(StandardAnalyzer))]
        public virtual string LoweredUserName
        {
            get { return loweredUserName; }
            set { loweredUserName = value; }
        }

        private string mobileAlias;
        public virtual string MobileAlias
        {
            get { return mobileAlias; }
            set { mobileAlias = value; }
        }

        private bool isAnonymous;
        public virtual bool IsAnonymous
        {
            get { return isAnonymous; }
            set { isAnonymous = value; }
        }

        private DateTime? lastActivityDate;
        public virtual DateTime? LastActivityDate
        {
            get { return lastActivityDate; }
            set { lastActivityDate = value; }
        }
    }
}


mappings.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="NHibernateSearch-Demo"
                   namespace="NHibernateSearch_Demo.Model">

  <class name="User" table="aspnet_Users">
    <id name="UserID" type="guid">
      <generator class="guid"/>
    </id>
    <property name="ApplicationID"/>
    <property name="UserName" length="256" not-null="true"/>
    <property name="LoweredUserName" length="256" not-null="true"/>
    <property name="MobileAlias" length="256" not-null="true"/>
    <property name="IsAnonymous" not-null="true"/>
    <property name="LastActivityDate" not-null="true"/>
  </class>

</hibernate-mapping>


GuidBridge.cs
Code:
namespace NHibernate.Search.Bridge.Builtin
{
    public class GuidBridge : SimpleBridge
    {
        public override object StringToObject(string stringValue)
        {
            return new System.Guid(stringValue);
        }
    }
}


The code does not throw any exceptions. nhQuery.List<User>() returns empty list. Thanks in advance

Best Regards,

Dave


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.