Browse files

Backported NHibernate 1.2, changed other files only where necessary t…

…o ensure compile/working tests

SVN: branches/1.2.x@3119
  • Loading branch information...
1 parent 1442af8 commit edfcfca4c58bcba15eeedf056d2484f4fa116758 @phatcher phatcher committed Nov 19, 2007
Showing with 12,889 additions and 5 deletions.
  1. +3 −0 default.build
  2. BIN lib/net/2.0/Lucene.Net.dll
  3. +6,740 −0 lib/net/2.0/Lucene.Net.xml
  4. +32 −0 src/NHibernate.Everything-2.0.sln
  5. +100 −0 src/NHibernate.Search.Tests/App.config
  6. +144 −0 src/NHibernate.Search.Tests/Bridge/BridgeTestCase.cs
  7. +202 −0 src/NHibernate.Search.Tests/Bridge/Cloud.cs
  8. +31 −0 src/NHibernate.Search.Tests/Bridge/Cloud.hbm.xml
  9. +14 −0 src/NHibernate.Search.Tests/Bridge/CloudType.cs
  10. +48 −0 src/NHibernate.Search.Tests/Bridge/TruncateFieldBridge.cs
  11. +135 −0 src/NHibernate.Search.Tests/DirectoryProvider/FSSlaveAndMasterDPTest.cs
  12. +77 −0 src/NHibernate.Search.Tests/DirectoryProvider/MultiplySessionFactoriesTestCase.cs
  13. +38 −0 src/NHibernate.Search.Tests/DirectoryProvider/SnowStorm.cs
  14. +12 −0 src/NHibernate.Search.Tests/DirectoryProvider/SnowStorm.hbm.xml
  15. +61 −0 src/NHibernate.Search.Tests/FieldAccess/Document.cs
  16. +13 −0 src/NHibernate.Search.Tests/FieldAccess/Document.hbm.xml
  17. +66 −0 src/NHibernate.Search.Tests/FieldAccess/FieldAccessTest.cs
  18. +80 −0 src/NHibernate.Search.Tests/FileHleperTestCase.cs
  19. +28 −0 src/NHibernate.Search.Tests/Inheritance/Animal.cs
  20. +11 −0 src/NHibernate.Search.Tests/Inheritance/Animal.hbm.xml
  21. +72 −0 src/NHibernate.Search.Tests/Inheritance/InheritanceTest.cs
  22. +16 −0 src/NHibernate.Search.Tests/Inheritance/Mammal.cs
  23. +12 −0 src/NHibernate.Search.Tests/Inheritance/Mammal.hbm.xml
  24. +37 −0 src/NHibernate.Search.Tests/NHibernate.Search.Tests.build
  25. +129 −0 src/NHibernate.Search.Tests/NHibernate.Search.Tests.csproj
  26. +37 −0 src/NHibernate.Search.Tests/Queries/AlternateBook.cs
  27. +11 −0 src/NHibernate.Search.Tests/Queries/AlternateBook.hbm.xml
  28. +49 −0 src/NHibernate.Search.Tests/Queries/Book.cs
  29. +12 −0 src/NHibernate.Search.Tests/Queries/Book.hbm.xml
  30. +35 −0 src/NHibernate.Search.Tests/Queries/Clock.cs
  31. +11 −0 src/NHibernate.Search.Tests/Queries/Clock.hbm.xml
  32. +240 −0 src/NHibernate.Search.Tests/Queries/LuceneQueryTest.cs
  33. +43 −0 src/NHibernate.Search.Tests/SearchTestCase.cs
  34. +56 −0 src/NHibernate.Search.Tests/Sessions/Email.cs
  35. +13 −0 src/NHibernate.Search.Tests/Sessions/Email.hbm.xml
  36. +96 −0 src/NHibernate.Search.Tests/Sessions/MassIndexTest.cs
  37. +27 −0 src/NHibernate.Search.Tests/Workers/Employee.cs
  38. +11 −0 src/NHibernate.Search.Tests/Workers/Employee.hbm.xml
  39. +24 −0 src/NHibernate.Search.Tests/Workers/Employer.cs
  40. +11 −0 src/NHibernate.Search.Tests/Workers/Employer.hbm.xml
  41. +166 −0 src/NHibernate.Search.Tests/Workers/WorkerTestCase.cs
  42. +73 −0 src/NHibernate.Search/AttributeUtil.cs
  43. +21 −0 src/NHibernate.Search/Attributes/BoostAttribute.cs
  44. +21 −0 src/NHibernate.Search/Attributes/DateBridgeAttribute.cs
  45. +17 −0 src/NHibernate.Search/Attributes/DocumentIdAttribute.cs
  46. +35 −0 src/NHibernate.Search/Attributes/FieldAttribute.cs
  47. +27 −0 src/NHibernate.Search/Attributes/FieldBridgeAttribute.cs
  48. +18 −0 src/NHibernate.Search/Attributes/Indexed.cs
  49. +13 −0 src/NHibernate.Search/Attributes/Resolution.cs
  50. +118 −0 src/NHibernate.Search/DirectoryProviderHelper.cs
  51. +14 −0 src/NHibernate.Search/IFieldBridge.cs
  52. +20 −0 src/NHibernate.Search/IFullTextSession.cs
  53. +16 −0 src/NHibernate.Search/IStringBridge.cs
  54. +10 −0 src/NHibernate.Search/ITwoWayFieldBridge.cs
  55. +12 −0 src/NHibernate.Search/ITwoWayStringBridge.cs
  56. +20 −0 src/NHibernate.Search/Impl/AddLuceneWork.cs
  57. +68 −0 src/NHibernate.Search/Impl/BatchedQueueingProcessor.cs
  58. +150 −0 src/NHibernate.Search/Impl/BridgeFactory.cs
  59. +89 −0 src/NHibernate.Search/Impl/DateBridge.cs
  60. +12 −0 src/NHibernate.Search/Impl/DeleteLuceneWork.cs
  61. +391 −0 src/NHibernate.Search/Impl/DocumentBuilder.cs
  62. +19 −0 src/NHibernate.Search/Impl/EnumBridge.cs
  63. +19 −0 src/NHibernate.Search/Impl/Environment.cs
  64. +232 −0 src/NHibernate.Search/Impl/FullTextQueryImpl.cs
  65. +101 −0 src/NHibernate.Search/Impl/FullTextSearchHelper.cs
  66. +403 −0 src/NHibernate.Search/Impl/FullTextSessionImpl.cs
  67. +23 −0 src/NHibernate.Search/Impl/IBackendQueueProcessorFactory.cs
  68. +9 −0 src/NHibernate.Search/Impl/IParameterizedBridge.cs
  69. +25 −0 src/NHibernate.Search/Impl/IQueueingProcessor.cs
  70. +10 −0 src/NHibernate.Search/Impl/Index.cs
  71. +72 −0 src/NHibernate.Search/Impl/LuceneBackendQueueProcessor.cs
  72. +19 −0 src/NHibernate.Search/Impl/LuceneBackendQueueProcessorFactory.cs
  73. +28 −0 src/NHibernate.Search/Impl/LuceneWork.cs
  74. +107 −0 src/NHibernate.Search/Impl/LuceneWorker.cs
  75. +166 −0 src/NHibernate.Search/Impl/LuceneWorkspace.cs
  76. +20 −0 src/NHibernate.Search/Impl/SearchException.cs
  77. +191 −0 src/NHibernate.Search/Impl/SearchFactory.cs
  78. +110 −0 src/NHibernate.Search/Impl/SearchInterceptor.cs
  79. +20 −0 src/NHibernate.Search/Impl/SimpleBridge.cs
  80. +9 −0 src/NHibernate.Search/Impl/Store.cs
  81. +14 −0 src/NHibernate.Search/Impl/StringBridge.cs
  82. +29 −0 src/NHibernate.Search/Impl/TwoWayString2FieldBridgeAdaptor.cs
  83. +21 −0 src/NHibernate.Search/Impl/ValueTypeBridge.cs
  84. +52 −0 src/NHibernate.Search/Impl/Work.cs
  85. +9 −0 src/NHibernate.Search/Impl/WorkType.cs
  86. +58 −0 src/NHibernate.Search/LuceneQueryExpression.cs
  87. +30 −0 src/NHibernate.Search/NHibernate.Search.build
  88. +120 −0 src/NHibernate.Search/NHibernate.Search.csproj
  89. +38 −0 src/NHibernate.Search/NHibernate.Search.sln
  90. +39 −0 src/NHibernate.Search/Search.cs
  91. +121 −0 src/NHibernate.Search/Storage/DirectoryProviderFactory.cs
  92. +64 −0 src/NHibernate.Search/Storage/FSDirectoryProvider.cs
  93. +182 −0 src/NHibernate.Search/Storage/FSMasterDirectoryProvider.cs
  94. +260 −0 src/NHibernate.Search/Storage/FSSlaveDirectoryProvider.cs
  95. +53 −0 src/NHibernate.Search/Storage/FileHelper.cs
  96. +13 −0 src/NHibernate.Search/Storage/IDirectoryProvider.cs
  97. +61 −0 src/NHibernate.Search/Storage/RAMDirectoryProvider.cs
  98. +29 −0 src/NHibernate.Search/String2FieldBridgeAdaptor.cs
  99. +2 −2 src/NHibernate.Test/TestCase.cs
  100. +7 −1 src/NHibernate/Expression/InExpression.cs
  101. +10 −2 src/NHibernate/ISessionFactory.cs
  102. +6 −0 src/NHibernate/Impl/SessionFactoryImpl.cs
View
3 default.build
@@ -37,6 +37,8 @@
<include name="NHibernate.Mapping.Attributes/NHibernate.Mapping.Attributes.build" />
<include name="NHibernate.Mapping.Attributes.Test/NHibernate.Mapping.Attributes.Test.build" />
<include name="NHibernate.Tasks/NHibernate.Tasks.build" />
+ <include name="NHibernate.Search/NHibernate.Search.build" />
+ <include name="NHibernate.Search.Tests/NHibernate.Search.Tests.build" />
<include name="NHibernate.Tool.hbm2net/NHibernate.Tool.hbm2net.build" />
<include name="NHibernate.Tool.hbm2net.Console/NHibernate.Tool.hbm2net.Console.build" />
<include name="NHibernate.Tool.hbm2net.Tests/NHibernate.Tool.hbm2net.Tests.build" />
@@ -56,6 +58,7 @@
<include name="NHibernate.Caches.SysCache.Tests/NHibernate.Caches.SysCache.Tests.build" />
<include name="NHibernate.Caches.Prevalence.Tests/NHibernate.Caches.Prevalence.Tests.build" />
<include name="NHibernate.Mapping.Attributes.Test/NHibernate.Mapping.Attributes.Test.build" />
+ <include name="NHibernate.Search.Tests/NHibernate.Search.Tests.build" />
<include name="NHibernate.Tool.hbm2net.Tests/NHibernate.Tool.hbm2net.Tests.build" />
<include name="NHibernate.UserTypes.Tests/NHibernate.UserTypes.Tests.build" />
<include name="Nullables.Tests/Nullables.Tests.build" />
View
BIN lib/net/2.0/Lucene.Net.dll
Binary file not shown.
View
6,740 lib/net/2.0/Lucene.Net.xml
6,740 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
32 src/NHibernate.Everything-2.0.sln
@@ -195,6 +195,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.Caches.SysCache2
Release.AspNetCompiler.Debug = "False"
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.Search", "NHibernate.Search\NHibernate.Search.csproj", "{CC25D767-990D-4CE0-9F64-3426E244403B}"
+ ProjectSection(WebsiteProperties) = preProject
+ Debug.AspNetCompiler.Debug = "True"
+ Release.AspNetCompiler.Debug = "False"
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.Search.Tests", "NHibernate.Search.Tests\NHibernate.Search.Tests.csproj", "{71560152-A693-4F66-99CF-570685A33169}"
+ ProjectSection(WebsiteProperties) = preProject
+ Debug.AspNetCompiler.Debug = "True"
+ Release.AspNetCompiler.Debug = "False"
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|.NET = Debug|.NET
@@ -486,6 +498,26 @@ Global
{2AE716DC-D909-4100-8ED5-09B701EF2E14}.Release|Any CPU.Build.0 = Release|Any CPU
{2AE716DC-D909-4100-8ED5-09B701EF2E14}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2AE716DC-D909-4100-8ED5-09B701EF2E14}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Debug|.NET.ActiveCfg = Debug|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Release|.NET.ActiveCfg = Release|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {CC25D767-990D-4CE0-9F64-3426E244403B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Debug|.NET.ActiveCfg = Debug|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Release|.NET.ActiveCfg = Release|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Release|Any CPU.Build.0 = Release|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {71560152-A693-4F66-99CF-570685A33169}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
100 src/NHibernate.Search.Tests/App.config
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
+ <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
+ </configSections>
+
+ <connectionStrings>
+ <add name="TestConnectionString" connectionString="TestConnectionString-TestConnectionString" />
+ </connectionStrings>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
+ applies-to="v1.1.4322">
+ <qualifyAssembly partialName="System.Web"
+ fullName="System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ </assemblyBinding>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
+ applies-to="v2.0.50727">
+ <qualifyAssembly partialName="System.Web"
+ fullName="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ </assemblyBinding>
+ </runtime>
+
+ <nhibernate>
+ <add key="hibernate.connection.provider" value="NHibernate.Test.DebugConnectionProvider, NHibernate.Test" />
+ <add key="hibernate.connection.isolation" value="ReadCommitted" />
+ <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
+ <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
+ <add key="hibernate.connection.connection_string" value="Server=(local);initial catalog=nhibernate;Integrated Security=SSPI" />
+ <add key="hibernate.query.substitutions" value="true 1, false 0, yes 'Y', no 'N'" />
+ <add key="hibernate.adonet.batch_size" value="10" />
+ <add key="hibernate.prepare_sql" value="false" />
+ <add key="hibernate.cache.provider_class" value="NHibernate.Cache.HashtableCacheProvider, NHibernate" />
+ <add key="hibernate.cache.use_query_cache" value="true" />
+ </nhibernate>
+
+ <!-- This section contains the log4net configuration settings -->
+ <log4net debug="false">
+
+ <!-- Define some output appenders -->
+ <appender name="trace"
+ type="log4net.Appender.TraceAppender, log4net">
+ <layout type="log4net.Layout.PatternLayout,log4net">
+ <param name="ConversionPattern"
+ value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
+ </layout>
+ </appender>
+
+ <appender name="console"
+ type="log4net.Appender.ConsoleAppender, log4net">
+ <layout type="log4net.Layout.PatternLayout,log4net">
+ <param name="ConversionPattern"
+ value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
+ </layout>
+ </appender>
+
+ <appender name="rollingFile"
+ type="log4net.Appender.RollingFileAppender,log4net" >
+
+ <param name="File"
+ value="log.txt" />
+ <param name="AppendToFile"
+ value="false" />
+ <param name="RollingStyle"
+ value="Date" />
+ <param name="DatePattern"
+ value="yyyy.MM.dd" />
+ <param name="StaticLogFileName"
+ value="true" />
+
+ <layout type="log4net.Layout.PatternLayout,log4net">
+ <param name="ConversionPattern"
+ value="%d [%t] %-5p %c - %m%n" />
+ </layout>
+ </appender>
+
+ <!-- Setup the root category, add the appenders and set the default priority -->
+
+ <root>
+ <priority value="WARN" />
+ <appender-ref ref="console" />
+ </root>
+
+ <logger name="NHibernate.Bytecode.CodeDom">
+ <priority value="OFF" />
+ </logger>
+
+ <logger name="NHibernate.SQL">
+ <level value="OFF" />
+ </logger>
+
+ <logger name="NHibernate.Tool.hbm2ddl.SchemaExport">
+ <level value="WARN" />
+ </logger>
+ </log4net>
+
+
+</configuration>
+
+
View
144 src/NHibernate.Search.Tests/Bridge/BridgeTestCase.cs
@@ -0,0 +1,144 @@
+using System;
+using System.Collections;
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Search;
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests.Bridge
+{
+ [TestFixture]
+ public class BridgeTest : SearchTestCase
+ {
+ [Test]
+ public void DefaultAndNullBridges()
+ {
+ Cloud cloud = new Cloud();
+ cloud.DateTime = null;
+ cloud.Double1 = (null);
+ cloud.Double2 = (2.1d);
+ cloud.Int1 = (null);
+ cloud.Int2 = (2);
+ cloud.Float1 = (null);
+ cloud.Float2 = (2.1f);
+ cloud.Long1 = (null);
+ cloud.Long2 = (2L);
+ cloud.String1 = (null);
+ cloud.Type = (CloudType.Dog);
+ cloud.Storm = (false);
+ ISession s = OpenSession();
+ ITransaction tx = s.BeginTransaction();
+ s.Save(cloud);
+ s.Flush();
+ tx.Commit();
+
+ tx = s.BeginTransaction();
+ IFullTextSession session = Search.CreateFullTextSession(s);
+ QueryParser parser = new QueryParser("id", new StandardAnalyzer());
+ Query query;
+ IList result;
+
+ query = parser.Parse("Double2:[2 TO 2.1] AND Float2:[2 TO 2.1] " +
+ "AND Int2:[2 TO 2.1] AND Long2:[2 TO 2.1] AND Type:\"Dog\" AND Storm:false");
+
+ result = session.CreateFullTextQuery(query).List();
+ Assert.AreEqual(1, result.Count, "find primitives and do not fail on null");
+
+ query = parser.Parse("Double1:[2 TO 2.1] OR Float1:[2 TO 2.1] OR Int1:[2 TO 2.1] OR Long1:[2 TO 2.1]");
+ result = session.CreateFullTextQuery(query).List();
+ Assert.AreEqual(0, result.Count, "null elements should not be stored"); //the query is dumb because restrictive
+
+ s.Delete(s.Get(typeof(Cloud), cloud.Id));
+ tx.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void CustomBridges()
+ {
+ Cloud cloud = new Cloud();
+ cloud.CustomFieldBridge = ("This is divided by 2");
+ cloud.CustomStringBridge = ("This is div by 4");
+ ISession s = OpenSession();
+ ITransaction tx = s.BeginTransaction();
+ s.Save(cloud);
+ s.Flush();
+ tx.Commit();
+
+ tx = s.BeginTransaction();
+ IFullTextSession session = Search.CreateFullTextSession(s);
+ QueryParser parser = new QueryParser("id", new SimpleAnalyzer());
+ Query query;
+ IList result;
+
+ query = parser.Parse("CustomFieldBridge:This AND CustomStringBridge:This");
+ result = session.CreateFullTextQuery(query).List();
+ Assert.AreEqual(1, result.Count, "Properties not mapped");
+
+ query = parser.Parse("CustomFieldBridge:by AND CustomStringBridge:is");
+ result = session.CreateFullTextQuery(query).List();
+ Assert.AreEqual(0, result.Count, "Custom types not taken into account");
+
+ s.Delete(s.Get(typeof(Cloud), cloud.Id));
+ tx.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void DateTimeBridge()
+ {
+ Cloud cloud = new Cloud();
+
+
+ DateTime date = new DateTime(2000, 12, 15, 3, 43, 2);
+ cloud.DateTime = (date); //5 millisecond
+ cloud.DateTimeDay = (date);
+ cloud.DateTimeHour = (date);
+ cloud.DateTimeMillisecond = (date);
+ cloud.DateTimeMinute = (date);
+ cloud.DateTimeMonth = (date);
+ cloud.DateTimeSecond = (date);
+ cloud.DateTimeYear = (date);
+ ISession s = OpenSession();
+ ITransaction tx = s.BeginTransaction();
+ s.Save(cloud);
+ s.Flush();
+ tx.Commit();
+
+ tx = s.BeginTransaction();
+ IFullTextSession session = Search.CreateFullTextSession(s);
+ QueryParser parser = new QueryParser("id", new StandardAnalyzer());
+ Query query;
+ IList result;
+
+ query = parser.Parse("DateTime:[19900101 TO 20060101]"
+ + " AND DateTimeDay:[20001214 TO 2000121501]"
+ + " AND DateTimeMonth:[200012 TO 20001201]"
+ + " AND DateTimeYear:[2000 TO 200001]"
+ + " AND DateTimeHour:[20001214 TO 2000121503]"
+ + " AND DateTimeMinute:[20001214 TO 200012150343]"
+ + " AND DateTimeSecond:[20001214 TO 20001215034302]"
+ + " AND DateTimeMillisecond:[20001214 TO 20001215034302005]"
+ );
+ result = session.CreateFullTextQuery(query).List();
+ Assert.AreEqual(1, result.Count, "DateTime not found or not property truncated");
+
+ s.Delete(s.Get(typeof(Cloud), cloud.Id));
+ tx.Commit();
+ s.Close();
+ }
+
+ protected override void Configure(Configuration configuration)
+ {
+ base.Configure(configuration);
+ configuration.SetProperty(Environment.AnalyzerClass, typeof(SimpleAnalyzer).AssemblyQualifiedName);
+ }
+
+ protected override IList Mappings
+ {
+ get { return new string[] { "Bridge.Cloud.hbm.xml" }; }
+ }
+ }
+}
View
202 src/NHibernate.Search.Tests/Bridge/Cloud.cs
@@ -0,0 +1,202 @@
+using System;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Bridge
+{
+ [Indexed]
+ public class Cloud
+ {
+ private int id;
+ private long? long1;
+ private long long2;
+ private int? int1;
+ private int int2;
+ private double? double1;
+ private double double2;
+ private float? float1;
+ private float float2;
+ private string string1;
+ private DateTime? dateTime;
+ private DateTime? dateTimeYear;
+ private DateTime? dateTimeMonth;
+ private DateTime? dateTimeDay;
+ private DateTime? dateTimeHour;
+ private DateTime? dateTimeMinute;
+ private DateTime? dateTimeSecond;
+ private DateTime? dateTimeMillisecond;
+ private String customFieldBridge;
+ private String customStringBridge;
+ private CloudType type;
+ private bool storm;
+
+ [Field(Index.Tokenized, Store = Store.Yes)]
+ [FieldBridge(typeof (TruncateFieldBridge))]
+ public virtual string CustomFieldBridge
+ {
+ get { return customFieldBridge; }
+ set { this.customFieldBridge = value; }
+ }
+
+ [Field(Index.Tokenized, Store = Store.Yes)]
+ [FieldBridge(typeof (TruncateStringBridge), 4)]
+ public virtual string CustomStringBridge
+ {
+ get { return customStringBridge; }
+ set { this.customStringBridge = value; }
+ }
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { this.id = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual long? Long1
+ {
+ get { return long1; }
+ set { this.long1 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual long Long2
+ {
+ get { return long2; }
+ set { this.long2 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual int? Int1
+ {
+ get { return int1; }
+ set { this.int1 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual int Int2
+ {
+ get { return int2; }
+ set { this.int2 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual double? Double1
+ {
+ get { return double1; }
+ set { this.double1 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual double Double2
+ {
+ get { return double2; }
+ set { this.double2 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual float? Float1
+ {
+ get { return float1; }
+ set { this.float1 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual float Float2
+ {
+ get { return float2; }
+ set { this.float2 = value; }
+ }
+
+ [Field(Index.Tokenized, Store = Store.Yes)]
+ public virtual string String1
+ {
+ get { return string1; }
+ set { this.string1 = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual DateTime? DateTime
+ {
+ get { return dateTime; }
+ set { this.dateTime = value; }
+ }
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Year)]
+ public virtual DateTime? DateTimeYear
+ {
+ get { return dateTimeYear; }
+ set { this.dateTimeYear = value; }
+ }
+
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Month)]
+ public virtual DateTime? DateTimeMonth
+ {
+ get { return dateTimeMonth; }
+ set { this.dateTimeMonth = value; }
+ }
+
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Day)]
+ public virtual DateTime? DateTimeDay
+ {
+ get { return dateTimeDay; }
+ set { this.dateTimeDay = value; }
+ }
+
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Hour)]
+ public virtual DateTime? DateTimeHour
+ {
+ get { return dateTimeHour; }
+ set { this.dateTimeHour = value; }
+ }
+
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Minute)]
+ public virtual DateTime? DateTimeMinute
+ {
+ get { return dateTimeMinute; }
+ set { this.dateTimeMinute = value; }
+ }
+
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Second)]
+ public virtual DateTime? DateTimeSecond
+ {
+ get { return dateTimeSecond; }
+ set { this.dateTimeSecond = value; }
+ }
+
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ [DateBridge(Resolution.Millisecond)]
+ public virtual DateTime? DateTimeMillisecond
+ {
+ get { return dateTimeMillisecond; }
+ set { this.dateTimeMillisecond = value; }
+ }
+
+ [Field(Index.Tokenized)]
+ public virtual CloudType Type
+ {
+ get { return type; }
+ set { this.type = value; }
+ }
+
+
+ [Field(Index.Tokenized)]
+ public virtual bool Storm
+ {
+ get { return storm; }
+ set { this.storm = value; }
+ }
+ }
+}
View
31 src/NHibernate.Search.Tests/Bridge/Cloud.hbm.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Bridge"
+ assembly="NHibernate.Search.Tests">
+ <class name="Cloud">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Long1"/>
+ <property name="Long2"/>
+ <property name="Int1"/>
+ <property name="Int2"/>
+ <property name="Double1"/>
+ <property name="Double2"/>
+ <property name="Float1"/>
+ <property name="Float2"/>
+ <property name="String1"/>
+ <property name="DateTime"/>
+ <property name="DateTimeYear"/>
+ <property name="DateTimeMonth"/>
+ <property name="DateTimeDay"/>
+ <property name="DateTimeHour"/>
+ <property name="DateTimeMinute"/>
+ <property name="DateTimeSecond"/>
+ <property name="DateTimeMillisecond"/>
+ <property name="CustomFieldBridge"/>
+ <property name="CustomStringBridge"/>
+ <property name="Type"/>
+ <property name="Storm"/>
+ </class>
+</hibernate-mapping>
View
14 src/NHibernate.Search.Tests/Bridge/CloudType.cs
@@ -0,0 +1,14 @@
+using System;
+using Lucene.Net.Documents;
+using NHibernate.Util;
+
+namespace NHibernate.Search.Tests.Bridge
+{
+ public enum CloudType
+ {
+ Dragon,
+ House,
+ Dog,
+ Europe
+ }
+}
View
48 src/NHibernate.Search.Tests/Bridge/TruncateFieldBridge.cs
@@ -0,0 +1,48 @@
+using System;
+using Lucene.Net.Documents;
+using NHibernate.Util;
+
+namespace NHibernate.Search.Tests.Bridge
+{
+ public class TruncateFieldBridge : IFieldBridge
+ {
+ public Object Get(String name, Document document)
+ {
+ Field field = document.GetField(name);
+ return field.StringValue();
+ }
+
+ public void Set(String name, Object value, Document document, Field.Store store, Field.Index index, float? boost)
+ {
+ String indexedString = (String) value;
+ //Do not add fields on empty strings, seems a sensible default in most situations
+ if (StringHelper.IsNotEmpty(indexedString))
+ {
+ Field field = new Field(name, indexedString.Substring(0, indexedString.Length/2), store, index);
+ if (boost != null) field.SetBoost(boost.Value);
+ document.Add(field);
+ }
+ }
+ }
+
+ public class TruncateStringBridge : StringBridge, IParameterizedBridge
+ {
+ private int div;
+
+ public Object StringToObject(String stringValue)
+ {
+ return stringValue;
+ }
+
+ public String ObjectToString(Object obj)
+ {
+ String str = (String) obj;
+ return obj != null ? str.Substring(0, str.Length/div) : null;
+ }
+
+ public void SetParameterValues(object[] parameters)
+ {
+ div = (int)parameters[0];
+ }
+ }
+}
View
135 src/NHibernate.Search.Tests/DirectoryProvider/FSSlaveAndMasterDPTest.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Threading;
+using Lucene.Net.Analysis;
+using Lucene.Net.QueryParsers;
+using NHibernate.Cfg;
+using NHibernate.Search.Impl;
+using NHibernate.Search.Storage;
+using NUnit.Framework;
+using TestCase=NHibernate.Test.TestCase;
+
+namespace NHibernate.Search.Tests.DirectoryProvider
+{
+ [TestFixture]
+ public class FSSlaveAndMasterDPTest : MultiplySessionFactoriesTestCase
+ {
+ public override void TestInitialize()
+ {
+ if(Directory.Exists("./lucenedirs/"))
+ Directory.Delete("./lucenedirs/",true);
+ Directory.CreateDirectory("./lucenedirs/master/copy");
+ Directory.CreateDirectory("./lucenedirs/master/main");
+ Directory.CreateDirectory("./lucenedirs/slave");
+ base.TestInitialize();
+ }
+
+ [Test]
+ public void ProperCopy()
+ {
+ ISession s1 = CreateSession(0);
+ SnowStorm sn = new SnowStorm();
+ sn.DateTime = DateTime.Now;
+ sn.Location = ("Dallas, TX, USA");
+
+ IFullTextSession fts2 = Search.CreateFullTextSession(CreateSession(1));
+ QueryParser parser = new QueryParser("id", new StopAnalyzer());
+ IList result = fts2.CreateFullTextQuery(parser.Parse("Location:texas")).List();
+ Assert.AreEqual(0, result.Count, "No copy yet, fresh index expected");
+
+ s1.Save(sn);
+ s1.Flush(); //we don' commit so we need to flush manually
+
+ fts2.Close();
+ s1.Close();
+
+ int waitPeroid = 2*1*1000 + 10; //wait a bit more than 2 refresh (one master / one slave)
+ Thread.Sleep(waitPeroid);
+
+ //temp test original
+ fts2 = Search.CreateFullTextSession(CreateSession(0));
+ result = fts2.CreateFullTextQuery(parser.Parse("Location:dallas")).List();
+ Assert.AreEqual(1, result.Count, "Original should get one");
+
+ fts2 = Search.CreateFullTextSession(CreateSession(1));
+ result = fts2.CreateFullTextQuery(parser.Parse("Location:dallas")).List();
+ Assert.AreEqual(1, result.Count, "First copy did not work out");
+
+ s1 = CreateSession(0);
+ sn = new SnowStorm();
+ sn.DateTime = DateTime.Now;
+ sn.Location = ("Chennai, India");
+
+ s1.Save(sn);
+ s1.Flush(); //we don' commit so we need to flush manually
+
+ fts2.Close();
+ s1.Close();
+
+ Thread.Sleep(waitPeroid); //wait a bit more than 2 refresh (one master / one slave)
+
+ fts2 = Search.CreateFullTextSession(CreateSession(1));
+ result = fts2.CreateFullTextQuery(parser.Parse("Location:chennai")).List();
+ Assert.AreEqual(1, result.Count, "Second copy did not work out");
+
+ s1 = CreateSession(0);
+ sn = new SnowStorm();
+ sn.DateTime = DateTime.Now;
+ sn.Location = ("Melbourne, Australia");
+
+ s1.Save(sn);
+ s1.Flush(); //we don' commit so we need to flush manually
+
+ fts2.Close();
+ s1.Close();
+
+ Thread.Sleep(waitPeroid); //wait a bit more than 2 refresh (one master / one slave)
+
+ fts2 = Search.CreateFullTextSession(CreateSession(1));
+ result = fts2.CreateFullTextQuery(parser.Parse("Location:melbourne")).List();
+ Assert.AreEqual(1, result.Count, "Third copy did not work out");
+
+ fts2.Close();
+ }
+
+ private ISession CreateSession(int sessionFactoryNumber)
+ {
+ return SessionFactories[sessionFactoryNumber].OpenSession(new SearchInterceptor());
+ }
+
+ [TearDown]
+ protected void TearDown()
+ {
+ Directory.Delete("./lucenedirs/",true);
+ }
+
+ protected override void Configure(IList<Configuration> cfg)
+ {
+ //master
+ cfg[0].SetProperty("hibernate.search.default.sourceBase", "./lucenedirs/master/copy");
+ cfg[0].SetProperty("hibernate.search.default.indexBase", "./lucenedirs/master/main");
+ cfg[0].SetProperty("hibernate.search.default.refresh", "1"); //every minute
+ cfg[0].SetProperty("hibernate.search.default.directory_provider", typeof(FSMasterDirectoryProvider).AssemblyQualifiedName);
+
+ //slave(s)
+ cfg[1].SetProperty("hibernate.search.default.sourceBase", "./lucenedirs/master/copy");
+ cfg[1].SetProperty("hibernate.search.default.indexBase", "./lucenedirs/slave");
+ cfg[1].SetProperty("hibernate.search.default.refresh", "1"); //every minute
+ cfg[1].SetProperty("hibernate.search.default.directory_provider", typeof(FSSlaveDirectoryProvider).AssemblyQualifiedName);
+ }
+
+
+ protected override IList Mappings
+ {
+ get { return new string[] {"DirectoryProvider.SnowStorm.hbm.xml"}; }
+ }
+
+ protected override int NumberOfSessionFactories
+ {
+ get { return 2; }
+ }
+ }
+}
View
77 src/NHibernate.Search.Tests/DirectoryProvider/MultiplySessionFactoriesTestCase.cs
@@ -0,0 +1,77 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Cfg;
+using NHibernate.Tool.hbm2ddl;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests.DirectoryProvider
+{
+ public abstract class MultiplySessionFactoriesTestCase
+ {
+ private List<ISessionFactory> sessionFactories = new List<ISessionFactory>();
+ private List<Configuration> configurations;
+
+ protected abstract int NumberOfSessionFactories { get; }
+
+ protected IList<ISessionFactory> SessionFactories
+ {
+ get { return sessionFactories; }
+ }
+
+ [TestFixtureSetUp]
+ public virtual void TestInitialize()
+ {
+ Configure();
+ CreateSchema();
+ BuildSessionFactories();
+ }
+
+ private void CreateSchema()
+ {
+ foreach (Configuration configuration in configurations)
+ {
+ new SchemaExport(configuration).Create(false, true);
+ }
+ }
+
+ public void BuildSessionFactories()
+ {
+ foreach (Configuration configuration in configurations)
+ {
+ ISessionFactory sessionFactory = configuration.BuildSessionFactory();
+ SearchFactory.Initialize(configuration,sessionFactory);
+ sessionFactories.Add(sessionFactory);
+ }
+ }
+
+ private void Configure()
+ {
+ configurations = new List<Configuration>();
+ for (int i = 0; i < NumberOfSessionFactories; i++)
+ {
+ configurations.Add(CreateConfiguration());
+ }
+ Configure(configurations);
+ }
+
+ private Configuration CreateConfiguration()
+ {
+ Configuration cfg = new Configuration();
+ Assembly assembly = Assembly.GetExecutingAssembly();
+
+ foreach (string file in Mappings)
+ {
+ cfg.AddResource(assembly.GetName().Name + "." + file, assembly);
+ }
+ return cfg;
+ }
+
+ protected abstract void Configure(IList<Configuration> cfg);
+
+ protected abstract IList Mappings
+ {
+ get;
+ }
+ }
+}
View
38 src/NHibernate.Search.Tests/DirectoryProvider/SnowStorm.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Search.Attributes;
+using NHibernate.Test;
+
+namespace NHibernate.Search.Tests.DirectoryProvider
+{
+ [Indexed]
+ public class SnowStorm
+ {
+ private long id;
+ private DateTime dateTime;
+ private string location;
+
+ [DocumentId]
+ public virtual long Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.UnTokenized)]
+ [DateBridge(Resolution.Day)]
+ public virtual DateTime DateTime
+ {
+ get { return dateTime; }
+ set { dateTime = value; }
+ }
+
+ [Field(Index.Tokenized)]
+ public virtual string Location
+ {
+ get { return location; }
+ set { location = value; }
+ }
+ }
+}
View
12 src/NHibernate.Search.Tests/DirectoryProvider/SnowStorm.hbm.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.DirectoryProvider"
+ assembly="NHibernate.Search.Tests">
+ <class name="SnowStorm">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Location"/>
+ <property name="DateTime"/>
+ </class>
+</hibernate-mapping>
View
61 src/NHibernate.Search.Tests/FieldAccess/Document.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.FieldAccess
+{
+ [Indexed(Index = "DocumentField")]
+ public class Document
+ {
+ [DocumentId]
+ private int id;
+
+ [Field(Index.Tokenized, Store = Store.Yes)]
+ [Boost(2)]
+ private string title;
+
+ [Field(Index.Tokenized, Name = "Abstract", Store = Store.No)]
+ private string summary;
+
+ [Field(Index.Tokenized, Store = Store.No)]
+ private string text;
+
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public virtual string Title
+ {
+ get { return title; }
+ set { title = value; }
+ }
+
+ public virtual string Summary
+ {
+ get { return summary; }
+ set { summary = value; }
+ }
+
+
+ public virtual string Text
+ {
+ get { return text; }
+ set { text = value; }
+ }
+
+ public Document()
+ {
+ }
+
+
+ public Document(string title, string summary, string text)
+ {
+ this.title = title;
+ this.summary = summary;
+ this.text = text;
+ }
+ }
+}
View
13 src/NHibernate.Search.Tests/FieldAccess/Document.hbm.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.FieldAccess"
+ assembly="NHibernate.Search.Tests">
+ <class name="Document">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Text"/>
+ <property name="Summary"/>
+ <property name="Title"/>
+ </class>
+</hibernate-mapping>
View
66 src/NHibernate.Search.Tests/FieldAccess/FieldAccessTest.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.QueryParsers;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests.FieldAccess
+{
+ [TestFixture]
+ public class FieldAccessTest : SearchTestCase
+ {
+ [Test]
+ public void Fields()
+ {
+ Document doc = new Document("Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah");
+ ISession s = OpenSession();
+ ITransaction tx = s.BeginTransaction();
+ s.Save(doc);
+ tx.Commit();
+
+ s.Clear();
+
+ IFullTextSession session = Search.CreateFullTextSession(s);
+ tx = session.BeginTransaction();
+ QueryParser p = new QueryParser("id", new StandardAnalyzer());
+ IList result = session.CreateFullTextQuery(p.Parse("Abstract:Hibernate")).List();
+ Assert.AreEqual(1, result.Count, "Query by field");
+ s.Delete(result[0]);
+ tx.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void FieldBoost()
+ {
+ ISession s = OpenSession();
+ ITransaction tx = s.BeginTransaction();
+ s.Save(
+ new Document("Hibernate in Action", "Object and Relational", "blah blah blah")
+ );
+ s.Save(
+ new Document("Object and Relational", "Hibernate in Action", "blah blah blah")
+ );
+ tx.Commit();
+
+ s.Clear();
+
+ IFullTextSession session = Search.CreateFullTextSession(s);
+ tx = session.BeginTransaction();
+ QueryParser p = new QueryParser("id", new StandardAnalyzer());
+ IList result = session.CreateFullTextQuery(p.Parse("title:Action OR Abstract:Action")).List();
+ Assert.AreEqual(2, result.Count, "Query by field");
+ Assert.AreEqual("Hibernate in Action", ((Document)result[0]).Title, "@Boost fails");
+ s.Delete(result[0]);
+ s.Delete(result[1]);
+ tx.Commit();
+ s.Close();
+
+ }
+
+ protected override IList Mappings
+ {
+ get { return new string[] { "FieldAccess.Document.hbm.xml" }; }
+ }
+ }
+}
View
80 src/NHibernate.Search.Tests/FileHleperTestCase.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Threading;
+using NHibernate.Search.Storage;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests
+{
+ [TestFixture]
+ public class FileHleperTestCase
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ DirectoryInfo dir = new DirectoryInfo("./filehelpersrc");
+ dir.Create();
+ WriteFile(dir, "a");
+ WriteFile(dir, "b");
+ dir = new DirectoryInfo(Path.Combine(dir.FullName, "subdir"));
+ dir.Create();
+ WriteFile(dir, "c");
+ }
+
+ private void WriteFile(DirectoryInfo dir, String name)
+ {
+ FileInfo a = new FileInfo(Path.Combine(dir.FullName, name));
+ StreamWriter os = a.CreateText();
+ os.WriteLine(1);
+ os.WriteLine(2);
+ os.WriteLine(3);
+ os.Flush();
+ os.Close();
+ }
+
+ [TearDown]
+ protected void TearDown()
+ {
+ DirectoryInfo dir = new DirectoryInfo("./filehelpersrc");
+ dir.Delete(true);
+ dir = new DirectoryInfo("./filehelperdest");
+ dir.Delete(true);
+ }
+
+ [Test]
+ public void Synchronize()
+ {
+ DirectoryInfo src = new DirectoryInfo("./filehelpersrc");
+ DirectoryInfo dest = new DirectoryInfo("./filehelperdest");
+ FileHelper.Synchronize(src, dest, true);
+ Assert.IsTrue(File.Exists(Path.Combine(dest.FullName, "b")));
+
+ string path = Path.Combine(dest.FullName, Path.Combine("subdir", "c"));
+ Assert.IsTrue(File.Exists(path));
+
+ //change
+ Thread.Sleep(2*2000);
+ StreamWriter os = File.CreateText(Path.Combine(src.FullName, "c"));
+ os.WriteLine(1);
+ os.WriteLine(2);
+ os.WriteLine(3);
+ os.Flush();
+ os.Close();
+ FileInfo test = new FileInfo(Path.Combine(src.FullName, "c"));
+ FileInfo destTest = new FileInfo(Path.Combine(dest.FullName, "c"));
+ Assert.AreNotSame(test.LastWriteTime, destTest.LastWriteTime);
+ FileHelper.Synchronize(src, dest, true);
+ destTest.Refresh();
+ Assert.AreEqual(test.LastWriteTime, destTest.LastWriteTime);
+ Assert.AreEqual(test.Length, destTest.Length);
+
+ //delete file
+ test.Delete();
+ FileHelper.Synchronize(src, dest, true);
+ destTest.Refresh();
+ Assert.IsTrue(! destTest.Exists);
+ }
+ }
+}
View
28 src/NHibernate.Search.Tests/Inheritance/Animal.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Inheritance
+{
+ [Indexed]
+ public class Animal
+ {
+ private int id;
+ private string name;
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized, Store = Store.No)]
+ public virtual string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+ }
+}
View
11 src/NHibernate.Search.Tests/Inheritance/Animal.hbm.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Inheritance"
+ assembly="NHibernate.Search.Tests">
+ <class name="Animal">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
View
72 src/NHibernate.Search.Tests/Inheritance/InheritanceTest.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using Lucene.Net.Analysis;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Search;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests.Inheritance
+{
+ [TestFixture]
+ public class InheritanceTest : SearchTestCase
+ {
+ [Test]
+ public void Inheritance()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ Animal a = new Animal();
+ a.Name = ("Shark Jr");
+ s.Save(a);
+ Mammal m = new Mammal();
+ m.NumberOfLegs = (4);
+ m.Name = ("Elephant Jr");
+ s.Save(m);
+ tx.Commit(); //post commit events for lucene
+ s.Clear();
+ tx = s.BeginTransaction();
+ QueryParser parser = new QueryParser("Name", new StopAnalyzer());
+
+ Query query;
+ IQuery hibQuery;
+
+ query = parser.Parse("Elephant");
+ hibQuery = s.CreateFullTextQuery(query, typeof (Mammal));
+ IList result = hibQuery.List();
+ Assert.IsNotEmpty(result);
+ Assert.AreEqual(1, result.Count, "Query subclass by superclass attribute");
+
+ query = parser.Parse("NumberOfLegs:[4 TO 4]");
+ hibQuery = s.CreateFullTextQuery(query, typeof (Animal), typeof (Mammal));
+ result = hibQuery.List();
+ Assert.IsNotEmpty(result);
+ Assert.AreEqual(1, result.Count, "Query subclass by subclass attribute");
+
+ query = parser.Parse("Jr");
+ hibQuery = s.CreateFullTextQuery(query, typeof (Animal));
+ result = hibQuery.List();
+ Assert.IsNotEmpty(result);
+ Assert.AreEqual(2, result.Count, "Query filtering on superclass return mapped subclasses");
+ foreach (Object managedEntity in result)
+ {
+ s.Delete(managedEntity);
+ }
+ tx.Commit();
+ s.Close();
+ }
+
+ protected override IList Mappings
+ {
+ get
+ {
+ return new string[]
+ {
+ "Inheritance.Animal.hbm.xml",
+ "Inheritance.Mammal.hbm.xml",
+ };
+ }
+ }
+ }
+}
View
16 src/NHibernate.Search.Tests/Inheritance/Mammal.cs
@@ -0,0 +1,16 @@
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Inheritance
+{
+ public class Mammal : Animal
+ {
+ private int numberOfLegs;
+
+ [Field(Index.UnTokenized, Store = Store.Yes)]
+ public virtual int NumberOfLegs
+ {
+ get { return numberOfLegs; }
+ set { numberOfLegs = value; }
+ }
+ }
+}
View
12 src/NHibernate.Search.Tests/Inheritance/Mammal.hbm.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Inheritance"
+ assembly="NHibernate.Search.Tests">
+ <class name="Mammal">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Name"/>
+ <property name="NumberOfLegs"/>
+ </class>
+</hibernate-mapping>
View
37 src/NHibernate.Search.Tests/NHibernate.Search.Tests.build
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<project
+ name="NHibernate.Search.Tests"
+ default="build"
+ description="Unit tests for NHibernate Search - Lucene.Net integration"
+ xmlns="http://nant.sf.net/release/0.85-rc3/nant.xsd">
+
+ <property name="root.dir" value="..\.." />
+ <include buildfile="${root.dir}/build-common/common-project.xml" />
+
+ <target name="init" depends="common.init">
+ <property name="clover.instrument" value="false" />
+ <assemblyfileset id="project.references" basedir="${bin.dir}">
+ <include name="System.dll" />
+ <include name="System.Data.dll" />
+ <include name="System.XML.dll" />
+ <include name="System.web.dll" />
+ <include name="NHibernate.Search.dll" />
+ <include name="NHibernate.Test.dll" />
+ <include name="Lucene.Net.dll" />
+ <include name="NHibernate.dll" />
+ <include name="nunit.framework.dll" />
+ <include name="log4net.dll" />
+ </assemblyfileset>
+
+ <resourcefileset id="project.resources" prefix="NHibernate.Search.Tests" dynamicprefix="true">
+ <include name="**/*.xml" />
+ <exclude name="bin/**/*.xml" />
+ </resourcefileset>
+ </target>
+
+ <target name="build" depends="init common.compile-tests" />
+ <target name="test" depends="init build common.run-tests" />
+
+ <!-- Intentionally empty -->
+ <target name="generate-assemblyinfo" />
+</project>
View
129 src/NHibernate.Search.Tests/NHibernate.Search.Tests.csproj
@@ -0,0 +1,129 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{71560152-A693-4F66-99CF-570685A33169}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NHibernate.Search.Tests</RootNamespace>
+ <AssemblyName>NHibernate.Search.Tests</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Lucene.Net, Version=2.0.0.4, Culture=neutral, PublicKeyToken=255f08c3cb6b422d, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\2.0\Lucene.Net.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\2.0\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Bridge\BridgeTestCase.cs" />
+ <Compile Include="Bridge\Cloud.cs" />
+ <Compile Include="Bridge\CloudType.cs" />
+ <Compile Include="Bridge\TruncateFieldBridge.cs" />
+ <Compile Include="DirectoryProvider\FSSlaveAndMasterDPTest.cs" />
+ <Compile Include="DirectoryProvider\MultiplySessionFactoriesTestCase.cs" />
+ <Compile Include="DirectoryProvider\SnowStorm.cs" />
+ <Compile Include="FieldAccess\Document.cs" />
+ <Compile Include="FieldAccess\FieldAccessTest.cs" />
+ <Compile Include="FileHleperTestCase.cs" />
+ <Compile Include="Inheritance\Animal.cs" />
+ <Compile Include="Inheritance\InheritanceTest.cs" />
+ <Compile Include="Inheritance\Mammal.cs" />
+ <Compile Include="Queries\AlternateBook.cs" />
+ <Compile Include="Queries\Book.cs" />
+ <Compile Include="Queries\Clock.cs" />
+ <Compile Include="Queries\LuceneQueryTest.cs" />
+ <Compile Include="SearchTestCase.cs" />
+ <Compile Include="Sessions\Email.cs" />
+ <Compile Include="Sessions\MassIndexTest.cs" />
+ <Compile Include="Workers\Employee.cs" />
+ <Compile Include="Workers\Employer.cs" />
+ <Compile Include="Workers\WorkerTestCase.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\NHibernate.Test\NHibernate.Test-2.0.csproj">
+ <Project>{7AEE5B37-C552-4E59-9B6F-88755BCB5070}</Project>
+ <Name>NHibernate.Test-2.0</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\NHibernate\NHibernate-2.0.csproj">
+ <Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project>
+ <Name>NHibernate-2.0</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\NHibernate.Search\NHibernate.Search.csproj">
+ <Project>{CC25D767-990D-4CE0-9F64-3426E244403B}</Project>
+ <Name>NHibernate.Search</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Bridge\Cloud.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="DirectoryProvider\SnowStorm.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="FieldAccess\Document.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Inheritance\Animal.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Inheritance\Mammal.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Queries\AlternateBook.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Queries\Book.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Queries\Clock.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Sessions\Email.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Workers\Employee.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Workers\Employer.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Properties\" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
37 src/NHibernate.Search.Tests/Queries/AlternateBook.cs
@@ -0,0 +1,37 @@
+using System;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Queries
+{
+ [Indexed(Index = "Book")]
+ public class AlternateBook
+ {
+ private int id;
+ private String summary;
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized, Store=Store.Yes)]
+ public virtual string Summary
+ {
+ get { return summary; }
+ set { summary = value; }
+ }
+
+ public AlternateBook()
+ {
+
+ }
+
+ public AlternateBook(int id, string summary)
+ {
+ this.id = id;
+ this.summary = summary;
+ }
+ }
+}
View
11 src/NHibernate.Search.Tests/Queries/AlternateBook.hbm.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Queries"
+ assembly="NHibernate.Search.Tests">
+ <class name="AlternateBook">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="Summary"/>
+ </class>
+</hibernate-mapping>
View
49 src/NHibernate.Search.Tests/Queries/Book.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Queries
+{
+ [Indexed(Index = "Book")]
+ public class Book
+ {
+ private int id;
+ private String body;
+ private String summary;
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized,Store=Store.No)]
+ public virtual string Body
+ {
+ get { return body; }
+ set { body = value; }
+ }
+
+ [Field(Index.Tokenized, Store=Store.Yes)]
+ public virtual string Summary
+ {
+ get { return summary; }
+ set { summary = value; }
+ }
+
+
+ public Book(int id, string body, string summary)
+ {
+ this.id = id;
+ this.body = body;
+ this.summary = summary;
+ }
+
+ public Book()
+ {
+
+ }
+ }
+}
View
12 src/NHibernate.Search.Tests/Queries/Book.hbm.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Queries"
+ assembly="NHibernate.Search.Tests">
+ <class name="Book">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="Summary"/>
+ <property name="Body"/>
+ </class>
+</hibernate-mapping>
View
35 src/NHibernate.Search.Tests/Queries/Clock.cs
@@ -0,0 +1,35 @@
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Queries
+{
+ [Indexed]
+ public class Clock
+ {
+ private int id;
+ private string brand;
+ public Clock()
+ {
+
+ }
+
+ public Clock(int id, string brand)
+ {
+ this.id = id;
+ this.brand = brand;
+ }
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized, Store=Store.Yes)]
+ public virtual string Brand
+ {
+ get { return brand; }
+ set { brand = value; }
+ }
+ }
+}
View
11 src/NHibernate.Search.Tests/Queries/Clock.hbm.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Queries"
+ assembly="NHibernate.Search.Tests">
+ <class name="Clock">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="Brand"/>
+ </class>
+</hibernate-mapping>
View
240 src/NHibernate.Search.Tests/Queries/LuceneQueryTest.cs
@@ -0,0 +1,240 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using Lucene.Net.Analysis;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Search;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests.Queries
+{
+ [TestFixture]
+ public class LuceneQueryTest : SearchTestCase
+ {
+ [Test]
+ public void UsingCriteriaApi()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ Clock clock = new Clock(1, "Seiko");
+ s.Save(clock);
+ tx.Commit();
+
+ IList list = s.CreateCriteria(typeof(Clock))
+ .Add(Search.Query("Brand:seiko"))
+ .List();
+ Assert.AreEqual(1, list.Count, "should get result back from query");
+
+ s.Delete(clock);
+ s.Flush();
+ s.Close();
+ }
+
+ [Test]
+ public void List()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ Clock clock = new Clock(1, "Seiko");
+ s.Save(clock);
+ clock = new Clock(2, "Festina");
+ s.Save(clock);
+ Book book = new Book(1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah");
+ s.Save(book);
+ book = new Book(2, "La gloire de mon père", "Les deboires de mon père en vélo");
+ s.Save(book);
+ tx.Commit();
+ s.Clear();
+ tx = s.BeginTransaction();
+ QueryParser parser = new QueryParser("title", new StopAnalyzer());
+
+ Query query = parser.Parse("Summary:noword");
+ IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ IList result = hibQuery.List();
+ Assert.AreEqual(0, result.Count);
+
+ query = parser.Parse("Summary:Festina Or Brand:Seiko");
+ hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ result = hibQuery.List();
+ Assert.AreEqual(2, result.Count, "Query with explicit class filter");
+
+
+ query = parser.Parse("Summary:Festina Or Brand:Seiko");
+ hibQuery = s.CreateFullTextQuery(query);
+ result = hibQuery.List();
+ Assert.AreEqual(2, result.Count, "Query with no class filter");
+ foreach (Object element in result)
+ {
+ Assert.IsTrue(NHibernateUtil.IsInitialized(element));
+ s.Delete(element);
+ }
+ s.Flush();
+ tx.Commit();
+
+ tx = s.BeginTransaction();
+ query = parser.Parse("Summary:Festina Or Brand:Seiko");
+ hibQuery = s.CreateFullTextQuery(query);
+ result = hibQuery.List();
+ Assert.AreEqual(0, result.Count, "Query with delete objects");
+
+ s.Delete("from System.Object");
+ tx.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void FirstMax()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ Clock clock = new Clock(1, "Seiko");
+ s.Save(clock);
+ clock = new Clock(2, "Festina");
+ s.Save(clock);
+ Book book = new Book(1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah");
+ s.Save(book);
+ book = new Book(2, "La gloire de mon père", "Les deboires de mon père en vélo");
+ s.Save(book);
+ tx.Commit();
+ s.Clear();
+ tx = s.BeginTransaction();
+ QueryParser parser = new QueryParser("title", new StopAnalyzer());
+
+ Query query = parser.Parse("Summary:Festina Or Brand:Seiko");
+ IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ hibQuery.SetFirstResult(1);
+ IList result = hibQuery.List();
+ Assert.AreEqual(1, result.Count, "first result no max result");
+
+ hibQuery.SetFirstResult(0);
+ hibQuery.SetMaxResults(1);
+ result = hibQuery.List();
+ Assert.AreEqual(1, result.Count, "max result set");
+
+ hibQuery.SetFirstResult(0);
+ hibQuery.SetMaxResults(3);
+ result = hibQuery.List();
+ Assert.AreEqual(2, result.Count, "max result out of limit");
+
+ hibQuery.SetFirstResult(2);
+ hibQuery.SetMaxResults(3);
+ result = hibQuery.List();
+ Assert.AreEqual(0, result.Count, "first result out of limit");
+
+ s.Delete("from System.Object");
+ tx.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void Iterator()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ Clock clock = new Clock(1, "Seiko");
+ s.Save(clock);
+ clock = new Clock(2, "Festina");
+ s.Save(clock);
+ Book book = new Book(1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah");
+ s.Save(book);
+ book = new Book(2, "La gloire de mon père", "Les deboires de mon père en vélo");
+ s.Save(book);
+ tx.Commit(); //post Commit events for lucene
+ s.Clear();
+ tx = s.BeginTransaction();
+ QueryParser parser = new QueryParser("title", new StopAnalyzer());
+
+ Query query = parser.Parse("Summary:noword");
+ IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ IEnumerator result = hibQuery.Enumerable().GetEnumerator();
+ Assert.IsFalse(result.MoveNext());
+
+ query = parser.Parse("Summary:Festina Or Brand:Seiko");
+ hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ result = hibQuery.Enumerable().GetEnumerator();
+ int index = 0;
+ while (result.MoveNext())
+ {
+ index++;
+ s.Delete(result.Current);
+ }
+ Assert.AreEqual(2, index);
+
+ tx.Commit();
+
+ tx = s.BeginTransaction();
+ query = parser.Parse("Summary:Festina Or Brand:Seiko");
+ hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ result = hibQuery.Enumerable().GetEnumerator();
+
+ Assert.IsFalse(result.MoveNext());
+ s.Delete("from System.Object");
+ tx.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void MultipleEntityPerIndex()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ Clock clock = new Clock(1, "Seiko");
+ s.Save(clock);
+ Book book = new Book(1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah");
+ s.Save(book);
+ AlternateBook alternateBook = new AlternateBook(1, "La chute de la petite reine a travers les yeux de Festina");
+ s.Save(alternateBook);
+ tx.Commit();
+ s.Clear();
+ tx = s.BeginTransaction();
+ QueryParser parser = new QueryParser("Title", new StopAnalyzer());
+
+ Query query = parser.Parse("Summary:Festina");
+ IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ IList result = hibQuery.List();
+
+ Assert.AreEqual(1, result.Count, "Query with explicit class filter");
+
+ query = parser.Parse("Summary:Festina");
+ hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ IEnumerator it = hibQuery.Enumerable().GetEnumerator();
+ Assert.IsTrue(it.MoveNext());
+ Assert.IsNotNull(it.Current);
+ Assert.IsFalse(it.MoveNext());
+
+ query = parser.Parse("Summary:Festina OR Brand:seiko");
+ hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
+ hibQuery.SetMaxResults(2);
+ result = hibQuery.List();
+ Assert.AreEqual(2, result.Count, "Query with explicit class filter and limit");
+
+ query = parser.Parse("Summary:Festina");
+ hibQuery = s.CreateFullTextQuery(query);
+ result = hibQuery.List();
+ Assert.AreEqual(2, result.Count, "Query with no class filter");
+ foreach (Object element in result)
+ {
+ Assert.IsTrue(NHibernateUtil.IsInitialized(element));
+ s.Delete(element);
+ }
+ s.Delete("from System.Object");
+ tx.Commit();
+ s.Close();
+ }
+
+
+ protected override IList Mappings
+ {
+ get
+ {
+ return new string[]
+ {
+ "Queries.Book.hbm.xml",
+ "Queries.AlternateBook.hbm.xml",
+ "Queries.Clock.hbm.xml"
+ };
+ }
+ }
+ }
+}
View
43 src/NHibernate.Search.Tests/SearchTestCase.cs
@@ -0,0 +1,43 @@
+using Lucene.Net.Analysis;
+using Lucene.Net.Store;
+using NHibernate.Cfg;
+using NHibernate.Search.Impl;
+using NHibernate.Search.Storage;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests
+{
+ [TestFixture]
+ public abstract class SearchTestCase : NHibernate.Test.TestCase
+ {
+ protected Directory GetDirectory(System.Type clazz)
+ {
+ return SearchFactory.GetSearchFactory(sessions).GetDirectoryProvider(clazz).Directory;
+ }
+
+ protected override void Configure(Configuration configuration)
+ {
+ cfg.SetProperty("hibernate.search.default.directory_provider", typeof (RAMDirectoryProvider).AssemblyQualifiedName);
+ cfg.SetProperty(Environment.AnalyzerClass, typeof (StopAnalyzer).AssemblyQualifiedName);
+ }
+
+
+ protected override ISession OpenSession()
+ {
+ lastOpenedSession = sessions.OpenSession(new SearchInterceptor());
+ return lastOpenedSession;
+ }
+
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Search.Tests"; }
+ }
+
+ protected override void BuildSessionFactory()
+ {
+ base.BuildSessionFactory();
+ SearchFactory.Initialize(cfg, sessions);
+ }
+
+ }
+}
View
56 src/NHibernate.Search.Tests/Sessions/Email.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Sessions
+{
+ [Indexed]
+ public class Email
+ {
+ private int id;
+ private string title;
+ private string body;
+ private string header;
+
+ public Email()
+ {
+
+ }
+
+
+ public Email(int id, string title, string body)
+ {
+ this.id = id;
+ this.title = title;
+ this.body = body;
+ }
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized)]
+ public virtual string Title
+ {
+ get { return title; }
+ set { title = value; }
+ }
+
+ [Field(Index.Tokenized)]
+ public virtual string Body
+ {
+ get { return body; }
+ set { body = value; }
+ }
+
+ public virtual string Header
+ {
+ get { return header; }
+ set { header = value; }
+ }
+ }
+}
View
13 src/NHibernate.Search.Tests/Sessions/Email.hbm.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Sessions"
+ assembly="NHibernate.Search.Tests">
+ <class name="Email">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="Title"/>
+ <property name="Header"/>
+ <property name="Body"/>
+ </class>
+</hibernate-mapping>
View
96 src/NHibernate.Search.Tests/Sessions/MassIndexTest.cs
@@ -0,0 +1,96 @@
+using System;
+using System.Collections;
+using System.Data;
+using Lucene.Net.Analysis;
+using Lucene.Net.QueryParsers;
+using NHibernate.Search.Impl;
+using NUnit.Framework;
+
+namespace NHibernate.Search.Tests.Sessions
+{
+ public class MassIndexTest : SearchTestCase
+ {
+ [Test]
+ public void Transactional()
+ {
+ IFullTextSession s = Search.CreateFullTextSession(OpenSession());
+ ITransaction tx = s.BeginTransaction();
+ int loop = 4;
+ for (int i = 0; i < loop; i++)
+ {
+ s.Save(new Email(i + 1, "JBoss World Berlin", "Meet the guys who wrote the software"));
+ }
+ tx.Commit();
+ s.Close();
+
+ //check non created object does get found!!1
+ s = new FullTextSessionImpl(OpenSession());
+ tx = s.BeginTransaction();
+ QueryParser parser = new QueryParser("id", new StopAnalyzer());
+ IList result = s.CreateFullTextQuery(parser.Parse("Body:create")).List();
+ Assert.IsEmpty(result);
+ tx.Commit();
+ s.Close();
+
+ s = new FullTextSessionImpl(OpenSession());
+ s.Transaction.Begin();
+ using (IDbCommand cmd = s.Connection.CreateCommand())
+ {
+ s.Transaction.Enlist(cmd);
+ cmd.CommandText = "update Email set body='Meet the guys who write the software'";
+ cmd.ExecuteNonQuery();
+
+ cmd.CommandText = "insert into Email(id, title, body, header) values( + "
+ + (loop + 1) + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope')";
+ cmd.ExecuteNonQuery();
+ }
+
+ s.Transaction.Commit();
+ s.Close();
+
+ s = new FullTextSessionImpl(OpenSession());
+ tx = s.BeginTransaction();
+ parser = new QueryParser("id", new StopAnalyzer());
+ result = s.CreateFullTextQuery(parser.Parse("Body:write")).List();
+ Assert.IsEmpty(result);
+ result = s.CreateCriteria(typeof (Email)).List();
+ for (int i = 0; i < loop/2; i++)
+ s.Index(result[i]);
+ tx.Commit(); //do the process
+ s.Index(result[(loop/2)]); //do the process out of tx
+ tx = s.BeginTransaction();
+ for (int i = loop/2 + 1; i < loop; i++)
+ s.Index(result[i]);
+ tx.Commit(); //do the process
+ s.Close();
+
+ s = Search.CreateFullTextSession(OpenSession());
+ tx = s.BeginTransaction();
+ //object never indexed
+ Email email = (Email) s.Get(typeof (Email), loop + 1);
+ s.Index(email);
+ tx.Commit();
+ s.Close();
+
+ //check non indexed object get indexed by s.index
+ s = new FullTextSessionImpl(OpenSession());
+ tx = s.BeginTransaction();
+ result = s.CreateFullTextQuery(parser.Parse("Body:create")).List();
+ Assert.AreEqual(1, result.Count);
+ tx.Commit();
+
+ s.Delete("from System.Object");
+ s.Flush();
+
+ s.Close();
+
+
+ }
+
+
+ protected override IList Mappings
+ {
+ get { return new string[] {"Sessions.Email.hbm.xml"}; }
+ }
+ }
+}
View
27 src/NHibernate.Search.Tests/Workers/Employee.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Workers
+{
+ public class Employee
+ {
+ private int id;
+ private string name;
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized)]
+ public virtual string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+ }
+}
View
11 src/NHibernate.Search.Tests/Workers/Employee.hbm.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Workers"
+ assembly="NHibernate.Search.Tests">
+ <class name="Employee">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
View
24 src/NHibernate.Search.Tests/Workers/Employer.cs
@@ -0,0 +1,24 @@
+using NHibernate.Search.Attributes;
+
+namespace NHibernate.Search.Tests.Workers
+{
+ public class Employer
+ {
+ private int id;
+ private string name;
+
+ [DocumentId]
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Field(Index.Tokenized)]
+ public virtual string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+ }
+}
View
11 src/NHibernate.Search.Tests/Workers/Employer.hbm.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Search.Tests.Workers"
+ assembly="NHibernate.Search.Tests">
+ <class name="Employer">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
View
166 src/NHibernate.Search.Tests/Workers/WorkerTestCase.cs
@@ -0,0 +1,166 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;