Skip to content

Commit

Permalink
Lucene integration, refactorings and more.
Browse files Browse the repository at this point in the history
  • Loading branch information
gokr committed Sep 21, 2009
1 parent d7d4bcf commit ca80faf
Show file tree
Hide file tree
Showing 20 changed files with 1,826 additions and 976 deletions.
56 changes: 30 additions & 26 deletions Divan.sln
@@ -1,26 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Divan", "src\Divan.csproj", "{37AC0B66-5340-4B81-BC62-3EE80233A011}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trivial", "samples\Trivial\Trivial.csproj", "{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Release|Any CPU.Build.0 = Release|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Divan", "src\Divan.csproj", "{37AC0B66-5340-4B81-BC62-3EE80233A011}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trivial", "samples\Trivial\Trivial.csproj", "{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Release|Any CPU.Build.0 = Release|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 0.1
StartupItem = src\Divan.csproj
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
154 changes: 154 additions & 0 deletions samples/Trivial/Makefile
@@ -0,0 +1,154 @@

EXTRA_DIST = Makefile

# Warning: This is an automatically generated file, do not edit!

srcdir=.
top_srcdir=../..

include $(top_srcdir)/config.make

ifeq ($(CONFIG),DEBUG)
ASSEMBLY_COMPILER_COMMAND = gmcs
ASSEMBLY_COMPILER_FLAGS = -noconfig -codepage:utf8 -warn:4 -optimize- -debug "-define:DEBUG;TRACE" "-main:Trivial.Program"
ASSEMBLY = bin/Debug/Trivial.exe
ASSEMBLY_MDB = $(ASSEMBLY).mdb
COMPILE_TARGET = exe
PROJECT_REFERENCES = \
../../src/bin/Debug/Divan.dll
BUILD_DIR = bin/Debug/

NEWTONSOFT_JSON_DLL_SOURCE=../../../../../Divan/bin/Debug/Newtonsoft.Json.dll
NEWTONSOFT_JSON_DLL_MDB_SOURCE=../../../../../Divan/bin/Debug/Newtonsoft.Json.dll.mdb
DIVAN_DLL_MDB_SOURCE=../../src/bin/Debug/Divan.dll.mdb
DIVAN_DLL_MDB=$(BUILD_DIR)/Divan.dll.mdb
DIVAN_DLL_SOURCE=../../src/bin/Debug/Divan.dll
TRIVIAL_EXE_MDB_SOURCE=bin/Debug/Trivial.exe.mdb
TRIVIAL_EXE_MDB=$(BUILD_DIR)/Trivial.exe.mdb

endif

ifeq ($(CONFIG),RELEASE)
ASSEMBLY_COMPILER_COMMAND = gmcs
ASSEMBLY_COMPILER_FLAGS = -noconfig -codepage:utf8 -warn:4 -optimize+ "-define:TRACE" "-main:Trivial.Program"
ASSEMBLY = bin/Release/Trivial.exe
ASSEMBLY_MDB =
COMPILE_TARGET = exe
PROJECT_REFERENCES = \
../../src/bin/Release/Divan.dll
BUILD_DIR = bin/Release/

NEWTONSOFT_JSON_DLL_SOURCE=../../../../../Divan/bin/Debug/Newtonsoft.Json.dll
NEWTONSOFT_JSON_DLL_MDB_SOURCE=../../../../../Divan/bin/Debug/Newtonsoft.Json.dll.mdb
DIVAN_DLL_MDB=
DIVAN_DLL_SOURCE=../../src/bin/Release/Divan.dll
TRIVIAL_EXE_MDB=

endif

AL=al2
SATELLITE_ASSEMBLY_NAME=$(notdir $(basename $(ASSEMBLY))).resources.dll

PROGRAMFILES = \
$(NEWTONSOFT_JSON_DLL) \
$(NEWTONSOFT_JSON_DLL_MDB) \
$(DIVAN_DLL_MDB) \
$(DIVAN_DLL) \
$(TRIVIAL_EXE_MDB)

BINARIES = \
$(TRIVIAL)


RESGEN=resgen2

TRIVIAL = $(BUILD_DIR)/trivial
NEWTONSOFT_JSON_DLL = $(BUILD_DIR)/Newtonsoft.Json.dll
NEWTONSOFT_JSON_DLL_MDB = $(BUILD_DIR)/Newtonsoft.Json.dll.mdb
DIVAN_DLL = $(BUILD_DIR)/Divan.dll

FILES = \
Program.cs \
Properties/AssemblyInfo.cs

DATA_FILES =

RESOURCES =

EXTRAS = \
trivial.in

REFERENCES = \
System \
System.Core \
System.Xml.Linq \
System.Data.DataSetExtensions \
System.Data \
System.Xml

DLL_REFERENCES = \
../../../../../Divan/bin/Debug/Newtonsoft.Json.dll

CLEANFILES = $(PROGRAMFILES) $(BINARIES)

#Targets
all: $(ASSEMBLY) $(PROGRAMFILES) $(BINARIES) $(top_srcdir)/config.make

include $(top_srcdir)/Makefile.include
#include $(srcdir)/custom-hooks.make



$(eval $(call emit-deploy-wrapper,TRIVIAL,trivial,x))
$(eval $(call emit-deploy-target,NEWTONSOFT_JSON_DLL))
$(eval $(call emit-deploy-target,NEWTONSOFT_JSON_DLL_MDB))
$(eval $(call emit-deploy-target,DIVAN_DLL_MDB))
$(eval $(call emit-deploy-target,DIVAN_DLL))


$(eval $(call emit_resgen_targets))
$(build_xamlg_list): %.xaml.g.cs: %.xaml
xamlg '$<'


$(ASSEMBLY) $(ASSEMBLY_MDB): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(PROJECT_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list)
make pre-all-local-hook prefix=$(prefix)
mkdir -p $(shell dirname $(ASSEMBLY))
make $(CONFIG)_BeforeBuild
$(ASSEMBLY_COMPILER_COMMAND) $(ASSEMBLY_COMPILER_FLAGS) -out:$(ASSEMBLY) -target:$(COMPILE_TARGET) $(build_sources_embed) $(build_resources_embed) $(build_references_ref)
make $(CONFIG)_AfterBuild
make post-all-local-hook prefix=$(prefix)

install-local: $(ASSEMBLY) $(ASSEMBLY_MDB)
make pre-install-local-hook prefix=$(prefix)
make install-satellite-assemblies prefix=$(prefix)
mkdir -p '$(DESTDIR)$(libdir)/$(PACKAGE)'
$(call cp,$(ASSEMBLY),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call cp,$(ASSEMBLY_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
mkdir -p '$(DESTDIR)$(bindir)'
$(call cp,$(TRIVIAL),$(DESTDIR)$(bindir))
$(call cp,$(NEWTONSOFT_JSON_DLL),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call cp,$(NEWTONSOFT_JSON_DLL_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call cp,$(DIVAN_DLL_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call cp,$(DIVAN_DLL),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call cp,$(TRIVIAL_EXE_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
make post-install-local-hook prefix=$(prefix)

uninstall-local: $(ASSEMBLY) $(ASSEMBLY_MDB)
make pre-uninstall-local-hook prefix=$(prefix)
make uninstall-satellite-assemblies prefix=$(prefix)
$(call rm,$(ASSEMBLY),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call rm,$(ASSEMBLY_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call rm,$(TRIVIAL),$(DESTDIR)$(bindir))
$(call rm,$(NEWTONSOFT_JSON_DLL),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call rm,$(NEWTONSOFT_JSON_DLL_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call rm,$(DIVAN_DLL_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call rm,$(DIVAN_DLL),$(DESTDIR)$(libdir)/$(PACKAGE))
$(call rm,$(TRIVIAL_EXE_MDB),$(DESTDIR)$(libdir)/$(PACKAGE))
make post-uninstall-local-hook prefix=$(prefix)

install: install-local
uninstall: uninstall-local
clean: clean-local

include $(top_srcdir)/rules.make
16 changes: 3 additions & 13 deletions samples/Trivial/Program.cs
Expand Up @@ -95,9 +95,8 @@ class Program
Console.WriteLine("Loaded all Cars: " + cars.Count);

// Now try some linq
var tempQuery = CreateTempView("if (doc.docType && doc.docType == 'car') emit(doc.Hps, doc);", db);
var linqProvider = new CouchQueryProvider(db, tempQuery);
var linqCars = new CouchLinqQuery<Car>(linqProvider);
var tempView = db.NewTempView("test", "test", "if (doc.docType && doc.docType == 'car') emit(doc.Hps, doc);");
var linqCars = tempView.LinqQuery<Car>();

var fastCars = from c in linqCars where c.HorsePowers >= 175 select c;//.Make + " " + c.Model;
foreach (var fastCar in fastCars)
Expand All @@ -113,7 +112,7 @@ class Program
Console.WriteLine(twoCar);

// cleanup for later
db.DeleteDocument(tempQuery.Doc);
db.DeleteDocument(tempView.Doc);

// Delete some Cars one by one. CouchDB is an MVCC database which means that for every operation that modifies a document
// we need to supply not only its document id, but also the revision that we are aware of. This means that we must supply id/rev
Expand All @@ -138,15 +137,6 @@ class Program
Console.ReadLine();
}

private static CouchViewDefinition CreateTempView(string mapText, CouchDatabase db)
{
var designDoc = new CouchDesignDocument("test", db);
var def = designDoc.AddView("test", "function (doc) {" + mapText + "}");
designDoc.Synch();

return def;
}

/// <summary>
/// The simplest way to deal with domain objects is to subclass CouchDocument
/// and inherit members Id and Rev. You will need to implement WriteJson/ReadJson.
Expand Down
6 changes: 3 additions & 3 deletions samples/Trivial/Trivial.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -31,7 +31,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand Down
3 changes: 3 additions & 0 deletions samples/Trivial/trivial
@@ -0,0 +1,3 @@
#!/bin/sh

exec mono "/usr/local/lib/divan/Trivial.exe" "$@"
3 changes: 3 additions & 0 deletions samples/Trivial/trivial.in
@@ -0,0 +1,3 @@
#!/bin/sh

exec mono "@expanded_libdir@/@PACKAGE@/Trivial.exe" "$@"
2 changes: 1 addition & 1 deletion src/CouchBulkDeleteDocuments.cs
Expand Up @@ -34,4 +34,4 @@ public override void ReadJson(JObject obj)
throw new NotImplementedException();
}
}
}
}
22 changes: 18 additions & 4 deletions src/CouchDatabase.cs
Expand Up @@ -55,6 +55,17 @@ public CouchDesignDocument NewDesignDocument(string aName)
return newDoc;
}

/// <summary>
/// Only to be used when developing.
/// </summary>
public CouchViewDefinition NewTempView(string designDoc, string viewName, string mapText)
{
var doc = NewDesignDocument(designDoc);
var view = doc.AddView(viewName, "function (doc) {" + mapText + "}");
doc.Synch();
return view;
}

/// <summary>
/// Currently the logic is that the code is always the master.
/// And we also do not remove design documents in the database that
Expand Down Expand Up @@ -539,6 +550,11 @@ public CouchQuery Query(CouchViewDefinition view)
return new CouchQuery(view);
}

public CouchLuceneQuery Query(CouchLuceneViewDefinition view)
{
return new CouchLuceneQuery(view);
}

public CouchQuery QueryAllDocuments()
{
return Query(null, "_all_docs");
Expand Down Expand Up @@ -651,8 +667,7 @@ public bool HasDocument(string documentId)
{
try
{
Request(documentId).Get().Send();
// NOTE: Should use HEAD Request(documentId).Head().Send();
Request(documentId).Head().Send();
return true;
}
catch (WebException)
Expand All @@ -665,8 +680,7 @@ public bool HasAttachment(string documentId)
{
try
{
Request(documentId + "/attachment").Get().Send();
// NOTE: Should use HEAD Request(documentId + "/attachment").Head().Send();
Request(documentId + "/attachment").Head().Send();
return true;
}
catch (WebException)
Expand Down

0 comments on commit ca80faf

Please sign in to comment.