lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1127609 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch: ./ Properties/ Properties/AssemblyInfo.cs SimpleFacetedSearch.Test.csproj TestSimpleFacetedSearch.cs
Date Wed, 25 May 2011 18:11:57 GMT
Author: digy
Date: Wed May 25 18:11:57 2011
New Revision: 1127609

URL: http://svn.apache.org/viewvc?rev=1127609&view=rev
Log:
[LUCENENET-415] SimpleFacetedSearch

Added:
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/Properties/
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs

Added: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs?rev=1127609&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
(added)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
Wed May 25 18:11:57 2011
@@ -0,0 +1,35 @@
+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("Test for Lucene.Net.Search.SimpleFacetedSearch")]
+[assembly: AssemblyDescription("Test for SimpleFacetedSearch for Lucene.Net")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Lucene.Net.SimpleFacetedSearch")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2011 The Apache Software Foundation")]
+[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("df0ddee7-24b4-48bd-ba39-21bbd4fc39c3")]
+
+// 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 Revision and Build Numbers 
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("2.9.4")]
+[assembly: AssemblyFileVersion("2.9.4")]

Added: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj?rev=1127609&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj
(added)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj
Wed May 25 18:11:57 2011
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{D8CC9461-64E0-416E-BA6E-1DF6FA66CBF5}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Lucene.Net.Search.SimpleFacetedSearch</RootNamespace>
+    <AssemblyName>Lucene.Net.Search.SimpleFacetedSearch.Test</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </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\contrib\SimpleFacetedSearch\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\lib\NUnit.org\NUnit\2.5.9\bin\net-2.0\nunit.framework.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="TestSimpleFacetedSearch.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\src\contrib\SimpleFacetedSearch\SimpleFacetedSearch.csproj">
+      <Project>{66772190-FB3F-48F5-8E05-0B302BACEA73}</Project>
+      <Name>SimpleFacetedSearch</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\src\core\Lucene.Net.csproj">
+      <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
+      <Name>Lucene.Net</Name>
+    </ProjectReference>
+  </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>
\ No newline at end of file

Added: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs?rev=1127609&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs
(added)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs
Wed May 25 18:11:57 2011
@@ -0,0 +1,244 @@
+/* 
+ * 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.Linq;
+using System.Text;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+
+using NUnit.Framework;
+
+namespace Lucene.Net.Search
+{
+    [TestFixture]
+    public class TestSimpleFacetedSearch
+    {
+        Directory _Dir = new RAMDirectory();
+        IndexReader _Reader;
+
+        [SetUp]
+        public void Setup()
+        {
+
+            IndexWriter writer = new IndexWriter(_Dir, new StandardAnalyzer(), true);
+
+            AddDoc(writer, "us", "CCN", "politics", "The White House doubles down on social
media");
+            AddDoc(writer, "us", "CCN", "politics", "Senate Dems fail to block filibuster
over judicial nominee");
+            AddDoc(writer, "us", "BCC", "politics", "A frozen pig's foot and a note laced
with anti-Semitic rants were sent to Rep. Peter King's Capitol Hill office, a congressional
source familiar with the situation confirmed to CNN Monday");
+            AddDoc(writer, "us", "CCN", "sport", "But when all was said and done, Haslem's
13 points, five rebounds, two assists, one block and one steal in the course of 23 minutes");
+            AddDoc(writer, "en", "CCN", "tech", "blockingQueue<T> contains two private
fields and exposes two public methods.");
+            AddDoc(writer, "en", "BCC", "tech", "An Argentine court this week granted an
injunction that blocks the Internet giant from 'suggesting' searches that lead to certain
sites that have been deemed anti-Semitic, and removes the sites from the search engine's index");
+            AddDoc(writer, "en", "CCN", "dummy", "oooooooooooooooooooooo");
+            writer.Close();
+
+            _Reader = IndexReader.Open(_Dir);
+        }
+
+        void AddDoc(IndexWriter writer, string lang, string source, string group, string
text)
+        {
+            Field f0 = new Field("lang", lang, Field.Store.YES, Field.Index.NOT_ANALYZED);
+            Field f1 = new Field("source", source, Field.Store.YES, Field.Index.NOT_ANALYZED);
+            Field f2 = new Field("category", group, Field.Store.YES, Field.Index.NOT_ANALYZED);
+            Field f3 = new Field("text", text, Field.Store.YES, Field.Index.ANALYZED);
+            Document doc = new Document();
+            doc.Add(f0);
+            doc.Add(f1);
+            doc.Add(f2);
+            doc.Add(f3);
+            writer.AddDocument(doc);
+        }
+
+        [Test]
+        public void Test1()
+        {
+            //See, Is there an exception
+            HowToUse("block*");
+            HowToUse("qwertyuiop");
+            //OK. No exception
+        }
+
+        [Test]
+        public void Test2()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new
StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(4, hits.HitsPerGroup.Length);
+
+            foreach (SimpleFacetedSearch.HitsPerGroup hpg in hits.HitsPerGroup)
+            {
+                if (hpg.Name[0] == "politics")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "tech")
+                {
+                    Assert.AreEqual(2, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "sport")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                {
+                    Assert.AreEqual(0, hpg.HitCount);
+                }
+            }
+
+            Assert.AreEqual(4, hits.TotalHitCount);
+
+            foreach (SimpleFacetedSearch.HitsPerGroup hpg in hits.HitsPerGroup)
+            {
+                foreach (Document doc in hpg.Documents)
+                {
+                    string text = doc.GetField("text").StringValue();
+                    Assert.IsTrue(text.Contains("block"));
+                }
+            }
+        }
+
+        [Test]
+        public void Test3()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new
StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "lang",
"source", "category" });
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(6, hits.HitsPerGroup.Length);
+            int nohit = 0;
+
+            foreach (SimpleFacetedSearch.HitsPerGroup hpg in hits.HitsPerGroup)
+            {
+                if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2]
== "politics")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "en" && hpg.Name[1] == "BCC" && hpg.Name[2]
== "tech")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2]
== "sport")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "en" && hpg.Name[1] == "CCN" && hpg.Name[2]
== "tech")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                {
+                    nohit++;
+                    Assert.AreEqual(0, hpg.HitCount);
+                }
+            }
+            Assert.AreEqual(2, nohit);
+            Assert.AreEqual(4, hits.TotalHitCount);
+
+            foreach (SimpleFacetedSearch.HitsPerGroup hpg in hits.HitsPerGroup)
+            {
+                foreach (Document doc in hpg.Documents)
+                {
+                    string text = doc.GetField("text").StringValue();
+                    Assert.IsTrue(text.Contains("block"));
+                }
+            }
+        }
+
+        [Test]
+        public void Test4()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new
StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("xxxxxxxxxxxxx");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(4, hits.HitsPerGroup.Length);
+            Assert.AreEqual(0, hits.HitsPerGroup[0].HitCount);
+            Assert.AreEqual(0, hits.HitsPerGroup[1].HitCount);
+            Assert.AreEqual(0, hits.HitsPerGroup[2].HitCount);
+        }
+
+        [Test]
+        public void Test5()
+        {
+            Query query = new MatchAllDocsQuery();
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(7, hits.TotalHitCount);
+        }
+
+        [Test]
+        public void Test6()
+        {
+            Query query = new MatchAllDocsQuery();
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "nosuchfield");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(0, hits.TotalHitCount);
+            Assert.AreEqual(0, hits.HitsPerGroup.Length);
+        }
+
+        /// <summary>
+        /// *****************************************************
+        /// * SAMPLE USAGE                                      *
+        /// *****************************************************
+        /// </summary>
+        void HowToUse(string searchString)
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new
StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse(searchString);
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "source",
"category" });
+            SimpleFacetedSearch.Hits hits = sfs.Search(query, 10);
+
+            //If you need performance, don't invoke "TotalHitCount"
+            long totalHits = hits.TotalHitCount;
+            foreach (SimpleFacetedSearch.HitsPerGroup hpg in hits.HitsPerGroup)
+            {
+                //If you need performance, don't invoke "HitCount"
+                long hitCountPerGroup = hpg.HitCount;
+                SimpleFacetedSearch.GroupName groupName = hpg.Name;
+                foreach (Document doc in hpg.Documents)
+                {
+                    string text = doc.GetField("text").StringValue();
+                    System.Diagnostics.Debug.WriteLine(">>" + groupName + ": " + text);
+                }
+            }
+        }
+
+    }
+}
+



Mime
View raw message