Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{66C13054-FF41-4C1D-BD0D-8DA009D1DFFD}</ProjectGuid>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Lucene.Net.Index.Memory.Test</RootNamespace>
<AssemblyName>Lucene.Net.Contrib.Memory.Test</AssemblyName>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\build\bin\contrib\Memory\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
<DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug35|AnyCPU' ">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\build\bin\contrib\Memory\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
<DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\build\bin\contrib\Memory\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
<DefineConstants>TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release35|AnyCPU' ">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\build\bin\contrib\Memory\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
<DefineConstants>TRACE;$(Framework)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\lib\NUnit.org\NUnit\2.5.9\bin\net-2.0\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Condition="'$(Framework)' == 'NET35'" Include="System.Core" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="MemoryIndexTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\contrib\Memory\Contrib.Memory.csproj">
<Project>{112b9a7c-29cc-4539-8f5a-45669c07cd4d}</Project>
<Name>Contrib.Memory</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\core\Lucene.Net.csproj">
<Project>{5d4ad9be-1ffb-41ab-9943-25737971bf57}</Project>
<Name>Lucene.Net</Name>
</ProjectReference>
<ProjectReference Include="..\..\core\Lucene.Net.Test.csproj">
<Project>{aaf68bcf-f781-45fc-98b3-2b9cee411e01}</Project>
<Name>Lucene.Net.Test</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="testqueries.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="testqueries2.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\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 File

@@ -0,0 +1,248 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Lucene.Net.Test.Analysis;
using NUnit.Framework;
using Version = Lucene.Net.Util.Version;
namespace Lucene.Net.Index.Memory.Test
{
/*
* Verifies that Lucene MemoryIndex and RAMDirectory have the same behaviour,
* returning the same results for queries on some randomish indexes.
*/
public class MemoryIndexTest : BaseTokenStreamTestCase
{
private readonly HashSet<String> _queries = new HashSet<String>();
private Random random;
public static int ITERATIONS = 100;
[SetUp]
public override void SetUp()
{
base.SetUp();
_queries.UnionWith(ReadQueries("testqueries.txt"));
_queries.UnionWith(ReadQueries("testqueries2.txt"));
random = NewRandom();
}
/*
* read a set of queries from a resource file
*/
private IEnumerable<string> ReadQueries(String resource)
{
var queries = new HashSet<String>();
using (var fs = File.Open(resource, FileMode.Open, FileAccess.Read))
using (var reader = new StreamReader(fs, Encoding.UTF8))
{
string line;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.Length > 0 && !line.StartsWith("#") && !line.StartsWith("//"))
{
queries.Add(line);
}
}
return queries;
}
}
/*
* runs random tests, up to ITERATIONS times.
*/
[Test]
public void TestRandomQueries()
{
for (int i = 0; i < ITERATIONS; i++)
AssertAgainstRAMDirectory();
}
/*
* Build a randomish document for both RAMDirectory and MemoryIndex,
* and run all the queries against it.
*/
public void AssertAgainstRAMDirectory()
{
var fooField = new StringBuilder();
var termField = new StringBuilder();
// add up to 250 terms to field "foo"
for (int i = 0; i < random.Next(250); i++)
{
fooField.Append(" ");
fooField.Append(RandomTerm());
}
// add up to 250 terms to field "term"
for (int i = 0; i < random.Next(250); i++)
{
termField.Append(" ");
termField.Append(RandomTerm());
}
var ramdir = new RAMDirectory();
var analyzer = RandomAnalyzer();
var writer = new IndexWriter(ramdir, analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
var doc = new Document();
var field1 = new Field("foo", fooField.ToString(), Field.Store.NO, Field.Index.ANALYZED);
var field2 = new Field("term", termField.ToString(), Field.Store.NO, Field.Index.ANALYZED);
doc.Add(field1);
doc.Add(field2);
writer.AddDocument(doc);
writer.Close();
var memory = new MemoryIndex();
memory.AddField("foo", fooField.ToString(), analyzer);
memory.AddField("term", termField.ToString(), analyzer);
AssertAllQueries(memory, ramdir, analyzer);
}
/*
* Run all queries against both the RAMDirectory and MemoryIndex, ensuring they are the same.
*/
public void AssertAllQueries(MemoryIndex memory, RAMDirectory ramdir, Analyzer analyzer)
{
var ram = new IndexSearcher(ramdir);
var mem = memory.CreateSearcher();
var qp = new QueryParser(Version.LUCENE_CURRENT, "foo", analyzer);
foreach (String query in _queries)
{
var ramDocs = ram.Search(qp.Parse(query), 1);
var memDocs = mem.Search(qp.Parse(query), 1);
Assert.AreEqual(ramDocs.TotalHits, memDocs.TotalHits);
}
}
/*
* Return a random analyzer (Simple, Stop, Standard) to analyze the terms.
*/
private Analyzer RandomAnalyzer()
{
switch (random.Next(3))
{
case 0:
return new SimpleAnalyzer();
case 1:
return new StopAnalyzer(Version.LUCENE_CURRENT);
default:
return new StandardAnalyzer(Version.LUCENE_CURRENT);
}
}
/*
* Some terms to be indexed, in addition to random words.
* These terms are commonly used in the queries.
*/
private static readonly string[] TEST_TERMS = {
"term", "Term", "tErm", "TERM",
"telm", "stop", "drop", "roll", "phrase", "a", "c", "bar",
"blar",
"gack", "weltbank", "worlbank", "hello", "on", "the", "apache"
, "Apache",
"copyright", "Copyright"
};
/*
* half of the time, returns a random term from TEST_TERMS.
* the other half of the time, returns a random unicode string.
*/
private String RandomTerm()
{
if (random.Next(2) == 1)
{
// return a random TEST_TERM
return TEST_TERMS[random.Next(TEST_TERMS.Length)];
}
else
{
// return a random unicode term
return RandomString();
}
}
/*
* Return a random unicode term, like TestStressIndexing.
*/
private String RandomString()
{
int end = random.Next(20);
if (buffer.Length < 1 + end)
{
char[] newBuffer = new char[(int) ((1 + end)*1.25)];
Array.Copy(buffer, 0, newBuffer, 0, buffer.Length);
buffer = newBuffer;
}
for (int i = 0; i < end - 1; i++)
{
int t = random.Next(6);
if (0 == t && i < end - 1)
{
// Make a surrogate pair
// High surrogate
buffer[i++] = (char) NextInt(0xd800, 0xdc00);
// Low surrogate
buffer[i] = (char) NextInt(0xdc00, 0xe000);
}
else if (t <= 1) buffer[i] = (char) random.Next(0x80);
else if (2 == t) buffer[i] = (char) NextInt(0x80, 0x800);
else if (3 == t) buffer[i] = (char) NextInt(0x800, 0xd7ff);
else if (4 == t) buffer[i] = (char) NextInt(0xe000, 0xffff);
else if (5 == t)
{
// Illegal unpaired surrogate
if (random.Next(1) == 1) buffer[i] = (char) NextInt(0xd800, 0xdc00);
else buffer[i] = (char) NextInt(0xdc00, 0xe000);
}
}
return new String(buffer, 0, end);
}
private char[] buffer = new char[20];
// start is inclusive and end is exclusive
private int NextInt(int start, int end)
{
return start + random.Next(end - start);
}
}
}

View File

@@ -0,0 +1,57 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Memory")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Memory")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("97c0467a-0d9d-49c0-89c0-5e8d9356cccc")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,129 @@
#
# queries extracted from TestQueryParser.java
#
Apache
Apach~ AND Copy*
a AND b
(a AND b)
c OR (a AND b)
a AND NOT b
a AND -b
a AND !b
a && b
a && ! b
a OR b
a || b
a OR !b
a OR ! b
a OR -b
+term -term term
foo:term AND field:anotherTerm
term AND "phrase phrase"
"hello there"
germ term^2.0
(term)^2.0
(germ term)^2.0
term^2.0
term^2
"germ term"^2.0
"term germ"^2
(foo OR bar) AND (baz OR boo)
((a OR b) AND NOT c) OR d
+(apple "steve jobs") -(foo bar baz)
+title:(dog OR cat) -author:"bob dole"
a&b
a&&b
.NET
"term germ"~2
"term germ"~2 flork
"term"~2
"~2 germ"
"term germ"~2^2
3
term 1.0 1 2
term term1 term2
term*
term*^2
term~
term~0.7
term~^2
term^2~
term*germ
term*germ^3
term*
Term*
TERM*
term*
Term*
TERM*
// Then 'full' wildcard queries:
te?m
Te?m
TE?M
Te?m*gerM
te?m
Te?m
TE?M
Te?m*gerM
term term term
term +stop term
term -stop term
drop AND stop AND roll
term phrase term
term AND NOT phrase term
stop
[ a TO c]
[ a TO c ]
{ a TO c}
{ a TO c }
{ a TO c }^2.0
[ a TO c] OR bar
[ a TO c] AND bar
( bar blar { a TO c})
gack ( bar blar { a TO c})
+weltbank +worlbank
+weltbank\n+worlbank
weltbank \n+worlbank
weltbank \n +worlbank
+weltbank\r+worlbank
weltbank \r+worlbank
weltbank \r +worlbank
+weltbank\r\n+worlbank
weltbank \r\n+worlbank
weltbank \r\n +worlbank
weltbank \r \n +worlbank
+weltbank\t+worlbank
weltbank \t+worlbank
weltbank \t +worlbank
term term term
term +term term
term term +term
term +term +term
-term term term
on^1.0
"hello"^2.0
hello^2.0
"on"^1.0
the^3

View File

@@ -0,0 +1,5 @@
term
term*
term~
Apache
Apach~ AND Copy*