Skip to content
Browse files

Playing with multi-field searchs (http://ayende.com/blog/152833/order…

…s-search-in-ravendb) in RavenDB probe of concept.
  • Loading branch information...
1 parent 40dc679 commit 8a7ef123f892bbcc260e09b7b9956a82bb7b139d @andresmoschini committed Jan 14, 2012
View
8 CommonJobs.sublime-project
@@ -0,0 +1,8 @@
+{
+ "folders":
+ [
+ {
+ "path": "/C/Users/amoschini/Documents/Projects/CommonJobs"
+ }
+ ]
+}
View
173 CommonJobs.sublime-workspace
@@ -0,0 +1,173 @@
+{
+ "auto_complete":
+ {
+ "selected_items":
+ [
+ ]
+ },
+ "buffers":
+ [
+ {
+ "file": "README.markdown",
+ "settings":
+ {
+ "buffer_size": 22,
+ "line_ending": "Windows"
+ }
+ }
+ ],
+ "build_system": "",
+ "command_palette":
+ {
+ "height": 311.0,
+ "selected_items":
+ [
+ [
+ "list",
+ "Package Control: List Packages"
+ ]
+ ],
+ "width": 512.0
+ },
+ "console":
+ {
+ "height": 743.0
+ },
+ "distraction_free":
+ {
+ "menu_visible": true,
+ "show_minimap": false,
+ "show_open_files": false,
+ "show_tabs": false,
+ "side_bar_visible": false,
+ "status_bar_visible": false
+ },
+ "file_history":
+ [
+ "/C/Users/amoschini/Desktop/borrar"
+ ],
+ "find":
+ {
+ "height": 34.0
+ },
+ "find_in_files":
+ {
+ "height": 0.0,
+ "where_history":
+ [
+ ]
+ },
+ "find_state":
+ {
+ "case_sensitive": false,
+ "find_history":
+ [
+ "ende",
+ "de"
+ ],
+ "highlight": true,
+ "in_selection": false,
+ "preserve_case": false,
+ "regex": false,
+ "replace_history":
+ [
+ ],
+ "reverse": false,
+ "show_context": true,
+ "use_buffer2": true,
+ "whole_word": false,
+ "wrap": true
+ },
+ "groups":
+ [
+ {
+ "sheets":
+ [
+ {
+ "buffer": 0,
+ "file": "README.markdown",
+ "settings":
+ {
+ "buffer_size": 22,
+ "regions":
+ {
+ },
+ "selection":
+ [
+ [
+ 22,
+ 22
+ ]
+ ],
+ "settings":
+ {
+ "syntax": "Packages/Markdown/Markdown.tmLanguage"
+ },
+ "translation.x": 0.0,
+ "translation.y": 0.0,
+ "zoom_level": 1.0
+ },
+ "type": "text"
+ }
+ ]
+ }
+ ],
+ "incremental_find":
+ {
+ "height": 0.0
+ },
+ "input":
+ {
+ "height": 0.0
+ },
+ "layout":
+ {
+ "cells":
+ [
+ [
+ 0,
+ 0,
+ 1,
+ 1
+ ]
+ ],
+ "cols":
+ [
+ 0.0,
+ 1.0
+ ],
+ "rows":
+ [
+ 0.0,
+ 1.0
+ ]
+ },
+ "menu_visible": true,
+ "replace":
+ {
+ "height": 0.0
+ },
+ "save_all_on_build": true,
+ "select_file":
+ {
+ "height": 0.0,
+ "selected_items":
+ [
+ ],
+ "width": 0.0
+ },
+ "select_project":
+ {
+ "height": 500.0,
+ "selected_items":
+ [
+ ],
+ "width": 380.0
+ },
+ "show_minimap": true,
+ "show_open_files": false,
+ "show_tabs": true,
+ "side_bar_visible": true,
+ "side_bar_width": 266.0,
+ "status_bar_visible": true
+}
View
54 spikes/RavenPOC1/RavenPOC1/Demo.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using Raven.Client;
using Raven.Client.Indexes;
+using Raven.Client.Linq;
using RavenPOC1.Domain;
using RavenPOC1.Skills;
@@ -21,16 +22,39 @@ public void CreateData1()
{
using (var session = _documentStore.OpenSession())
{
- var search1 = new Search()
- {
- Date = new DateTime(2011, 10, 5),
- Title = "Programador Javascript",
- Description = "Se necesita un programador de javascript que conozca de arriba a abajo jQuery.",
- Skills = new List<string> { "Javascript", "jQuery", "C#" }
- };
+ var search1 = new WorkerSearch()
+ {
+ Date = new DateTime(2011, 10, 5),
+ Title = "Programador Javascript",
+ Description = "Se necesita un programador de javascript que conozca de arriba a abajo jQuery.",
+ Skills = new List<string> { "Javascript", "jQuery", "C#" }
+ };
session.Store(search1);
+ session.Store(new WorkerSearch()
+ {
+ Date = new DateTime(2011, 11, 15),
+ Title = "Experto en COBOL",
+ Description = "Se necesita un programador de COBOL.",
+ Skills = new List<string> { "COBOL", "OTRONOMBRE1" }
+ });
+
+ session.Store(new WorkerSearch()
+ {
+ Date = new DateTime(2011, 11, 20),
+ Title = "Programador FORTRAN",
+ Description = "Se necesita alguien que conozca al menos algo de FORTRAN 77.",
+ Skills = new List<string> { "FORTRAN", "OTRONOMBRE2" }
+ });
+
+ session.Store(new WorkerSearch()
+ {
+ Date = new DateTime(2011, 11, 20),
+ Title = "Che Pibe",
+ Description = "Se necesita alquien que ayude con cualquier cosa, no es necesario que sepa programar"
+ });
+
var advert1 = new Advertisement()
{
Content =
@@ -75,14 +99,28 @@ internal void Run()
IndexCreation.CreateIndexes(typeof(Skills_All).Assembly, _documentStore);
CreateData1();
SkillsInputAutocomplete();
+ SearchOfWorkerSearcs();
+ }
+
+ private void SearchOfWorkerSearcs()
+ {
+ using (var session = _documentStore.OpenSession())
+ {
+ var a = session.Query<WorkerSearch_Search.ReduceResult, WorkerSearch_Search>().Where(x => x.Query.StartsWith("programador")).As<WorkerSearch>().ToList(); //Generates 'Query:programador*'
+ var b = session.Query<WorkerSearch_Search.ReduceResult, WorkerSearch_Search>().Where(x => x.Query.Contains("programador")).As<WorkerSearch>().ToList(); //RavenDB bug: generates 'Query:programador' in place of 'Query:*programador*'
+ var c = session.Query<WorkerSearch_Search.ReduceResult, WorkerSearch_Search>().Where(x => x.Query == "programador javascript").As<WorkerSearch>().ToList(); //Generates 'Query:"programador javascript"'
+ var d = session.Query<WorkerSearch_Search.ReduceResult, WorkerSearch_Search>().Where(x => x.Query == "OTRONOMBRE1").As<WorkerSearch>().ToList();
+ var e = session.Query<WorkerSearch_Search.ReduceResult, WorkerSearch_Search>().Where(x => x.Query.StartsWith("OTRONOMBRE*")).As<WorkerSearch>().ToList();
+ Console.ReadLine();
+ }
}
private void SkillsInputAutocomplete()
{
using (var session = _documentStore.OpenSession())
{
//Este no aparece en los tags
- var search2 = new Search()
+ var search2 = new WorkerSearch()
{
Date = new DateTime(2011, 10, 5),
Title = "Programador .NET",
View
2 spikes/RavenPOC1/RavenPOC1/Domain/Search.cs → ...avenPOC1/RavenPOC1/Domain/WorkerSearch.cs
@@ -5,7 +5,7 @@
namespace RavenPOC1.Domain
{
- public class Search
+ public class WorkerSearch
{
public int Id { get; set; }
public DateTime Date { get; set; }
View
9 spikes/RavenPOC1/RavenPOC1/RavenPOC1.csproj
@@ -53,6 +53,7 @@
<Reference Include="Lucene.Net.Contrib.SpellChecker">
<HintPath>..\packages\RavenDB-Embedded.1.0.573\lib\net40\Lucene.Net.Contrib.SpellChecker.dll</HintPath>
</Reference>
+ <Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
@@ -82,26 +83,30 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="WorkerSearch_Search.cs" />
<Compile Include="Demo.cs" />
<Compile Include="Domain\AdvertisementResponse.cs" />
<Compile Include="Domain\Applicant.cs" />
<Compile Include="Domain\MaritalStatus.cs" />
- <Compile Include="Domain\Search.cs" />
+ <Compile Include="Domain\WorkerSearch.cs" />
<Compile Include="Domain\Advertisement.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Skills\SkillResult.cs" />
<Compile Include="Skills\Skill_All.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
+ <None Include="app.config">
+ <SubType>Designer</SubType>
+ </None>
<None Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
View
2 spikes/RavenPOC1/RavenPOC1/Skills/Skill_All.cs
@@ -8,7 +8,7 @@ internal class Skills_All : AbstractMultiMapIndexCreationTask<SkillResult>
{
public Skills_All()
{
- AddMap<Search>(searches =>
+ AddMap<WorkerSearch>(searches =>
from search in searches
from skill in search.Skills
select new
View
34 spikes/RavenPOC1/RavenPOC1/WorkerSearch_Search.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Raven.Client.Indexes;
+using RavenPOC1.Domain;
+
+namespace RavenPOC1
+{
+ public class WorkerSearch_Search : AbstractIndexCreationTask<WorkerSearch, WorkerSearch_Search.ReduceResult>
+ {
+ public class ReduceResult
+ {
+ public string Query { get; set; }
+ public DateTime Date { get; set; }
+ }
+
+ public WorkerSearch_Search()
+ {
+ Map = searchs => from search in searchs
+ select new
+ {
+ Query = new object[]
+ {
+ search.Title,
+ search.Description,
+ search.Skills
+ },
+ Date = search.Date
+ };
+ }
+ }
+
+}

0 comments on commit 8a7ef12

Please sign in to comment.
Something went wrong with that request. Please try again.