Commit 32cec826 by mahaisong

fix:多个index向上封装的完善

parent 32ecdaa1
using System; using System;
...@@ -14,7 +14,7 @@ namespace HTCommon.Data ...@@ -14,7 +14,7 @@ namespace HTCommon.Data
/// </summary> /// </summary>
[Serializable] [Serializable]
[ElasticsearchType(Name = "authors")] [ElasticsearchType(Name = "author")]
public class Author public class Author
{ {
/// <summary> /// <summary>
...@@ -406,7 +406,7 @@ namespace HTCommon.Data ...@@ -406,7 +406,7 @@ namespace HTCommon.Data
/// </summary> /// </summary>
[Serializable] [Serializable]
[ElasticsearchType(Name = "authorrelations")] [ElasticsearchType(Name = "authorrelation")]
public class AuthorRelation public class AuthorRelation
{ {
/// <summary> /// <summary>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -294,6 +294,7 @@ ...@@ -294,6 +294,7 @@
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="ReadMe.md" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
\ No newline at end of file


注意:此类库不允许TestUnit项目之外的使用,因为大量代码为了测试被改动。
需要引用,可以参考其他的解决方案中的Common,推荐palas.common
\ No newline at end of file
D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\ImportLocalES\HTCommon\bin\Debug\HTCommon.dll.config D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\ImportLocalES\HTCommon\bin\Debug\HTCommon.dll.config
...@@ -264,6 +264,9 @@ D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.csproj.CoreCompile ...@@ -264,6 +264,9 @@ D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.csproj.CoreCompile
D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.dll D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.dll
D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.pdb D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.pdb
D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\MinderES\HTCommon\obj\Debug\HTCommon.csprojResolveAssemblyReference.cache D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\MinderES\HTCommon\obj\Debug\HTCommon.csprojResolveAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Nashorn.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXmlFormats.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll.config D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll.config
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.pdb D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.pdb
...@@ -293,7 +296,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK ...@@ -293,7 +296,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Media.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Media.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Misc.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Misc.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Naming.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Naming.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Nashorn.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Remoting.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Remoting.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Security.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Security.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.SwingAWT.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.SwingAWT.dll
...@@ -316,7 +318,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.J ...@@ -316,7 +318,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.J
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OOXML.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OOXML.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXml4Net.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXml4Net.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXmlFormats.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.ScratchPad.HWPF.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.ScratchPad.HWPF.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\pdfbox-app-2.0.7.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\pdfbox-app-2.0.7.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.dll
...@@ -339,11 +340,11 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.pdb ...@@ -339,11 +340,11 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest2_5_8.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.Json.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.Json.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Text.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Text.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.resources.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.resources.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.SqlServer.resources.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.SqlServer.resources.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csprojAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CoreCompileInputs.cache D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CoreCompileInputs.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CopyComplete D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CopyComplete
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.dll
......
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
...@@ -6,12 +6,15 @@ ...@@ -6,12 +6,15 @@
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留--> <!--20187150点迁移完成前保留--><!--
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" /> <add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=0:1:00;version=2;" />-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) --> <!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<!--<add name="ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" />--> <add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=palas_;" />
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=30000;version=6;indexprefix=palas_;" />
</connectionStrings> </connectionStrings>
......
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESAuthorAccess : ESAccess
{
public static Author SearchByAuthorID(String id)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, id))));
return SearchTop(builder);
}
public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(start)
.Size(count)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorName, name)
)
)
);
return Search(builder);
}
public static Author SearchByLocationHistoryTask(DateTime since)
{
//SearchBuilder<Author> builder = new SearchBuilder<Author>();
//builder.Query.Must
// .AddQuery(o => o.Location_NextRefreshTime, ActionType.LessEqual, since)
// .AddQuery(o => o.Location_RefreshStatus, ActionType.Equal, (int)Enums.CrawlStatus.Normal);
//return SearchTop(builder);
try
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.RefreshStatus, 0)
&& m.DateRange(r => r
.Field(f => f.NextRefreshTime)
.GreaterThan(DateTime.MinValue)
.LessThanOrEquals(DateTime.Now)
)
)
)
);
return ESAccess.SearchTop(builder);
}
catch
{
return null;
}
}
public static Boolean DeleteByAuthorID(String id)
{
//QueryContainer query = new TermQuery()
//{
// Field = Property.Path<Author>(p => p.AuthorID),
// Value = id
//};
//DeleteByQueryRequest<Author> builder = new DeleteByQueryRequest<Author>()
//{
// Query = query
//};
//return Delete(builder);
return false;
}
[Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static Boolean IndexOrUpdate(Author result)
{
return ESAccess.IndexOrUpdate(result);
}
public static String SearchAuthorTag(String resultID)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Source(s => s.Includes(f => f.Field(o => o.Tags)))
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, resultID)
)
)
);
Author result = SearchTop(builder);
return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags);
}
public static AuthorRelation SearchRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
return ESAccess.SearchTop(builder);
}
public static Boolean IndexOrUpdateRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
Int32 count = ESAccess.Count(builder);
AuthorRelation relation = new AuthorRelation()
{
TargetID = targetID,
FollowerID = followerID,
UpdateTime = DateTime.Now,
IsDeleted = false,
};
if (count > 0)
{
//return ESAuthorUpdateAccess.Update(relation);
return false;
}
else
{
relation.CreateTime = relation.UpdateTime;
return ESAccess.IndexOrUpdate(relation);
}
}
public static Boolean Update(Author result, String id = null)
{
//return ESAuthorUpdateAccess.Update(result, id);
return false;
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESAuthorUpdateAccess
{
//public static Boolean Update(Author author, Action<UpdateScriptBuilder<Author>> scriptBuilder, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(Author author, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// return false;
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, author);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(AuthorRelation relation, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorRelationIndexID(relation);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore<AuthorRelation>(id, o =>
// {
// o.AddScript<DateTime>(p => p.UpdateTime, UpdateType.Assign, relation.UpdateTime);
// o.AddScript<Boolean>(p => p.IsDeleted, UpdateType.Assign, relation.IsDeleted);
// });
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
private static String GetAuthorIndexID(Author author)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, author.AuthorID)
)
)
);
return ESAccess.SearchESInternalID<Author>(builder);
}
private static String GetAuthorRelationIndexID(AuthorRelation relation)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, relation.FollowerID)
&& m.Term(f => f.TargetID, relation.TargetID)
)
)
);
return ESAccess.SearchESInternalID(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon;
using HTCommon.Data6;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESItemUpdateAccess
{
public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
public static Boolean Update(Item item, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, item);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
private static String GetItemIndexID(Item item)
{
SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.ItemID, item.ItemID)
)
)
);
return ESAccess.SearchESInternalID<Item>(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESUpdateAccess
{
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, Action<UpdateScriptBuilder<T>> scriptBuilder) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// UpdateScriptBuilder<T> builder = new UpdateScriptBuilder<T>();
// scriptBuilder(builder);
// String script = null;
// var func = builder.GetScript(out script);
// Func<UpdateDescriptor<ScriptDescriptor, IScript>> d = new UpdateDescriptor<ScriptDescriptor, IScript>("Index","Type","ID");
// IUpdateResponse<T> resp = ec.Update<T>(id,u => u.Index(id).Script(d).Params(func));
// return resp;
//}
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, T item) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// return ec.Update<T>(id, o => o
// .Index(id)
// .Doc(item)
// );
//}
//public static IUpdateResponse<T> UpdateBulkCore<T>() where T : class
//{
// return null;
//}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
/// <summary>
/// Update方法支持三种更新方式, =, +=, -=
/// 日期类型只支持=
/// </summary>
public enum UpdateType
{
/// <summary>
/// =
/// </summary>
Assign = 0,
/// <summary>
/// +=
/// </summary>
Add,
/// <summary>
/// -=
/// </summary>
Subtract,
}
public class UpdateScriptBuilder<T> where T : class
{
private Dictionary<String, Tuple<String, Object>> _maps = new Dictionary<String, Tuple<String, Object>>();
//private PropertyNameResolver resolver = new PropertyNameResolver(ESClientConfigureManager.ConnectSetting);
/// <summary>
/// 只能修改第一级内容,嵌套的内容请写RawScript
/// </summary>
/// <typeparam name="K">修改项的类型</typeparam>
/// <param name="expr">第一级项目的表达式</param>
/// <param name="update">如何修改项目</param>
/// <param name="value">修改值</param>
/// <returns>返回自己,方便嵌套调用</returns>
public UpdateScriptBuilder<T> AddScript<K>(Expression<Func<T, K>> expr, UpdateType update, K value, Boolean resolve = true)
{
if (resolve)
{
//return AddScript(resolver.Resolve(expr), update, value);
return null;
}
else
{
IEnumerable<String> rawExprs = expr.Body.ToString().Split('.').Skip(1);
StringBuilder esExpr = new StringBuilder();
rawExprs.Aggregate(esExpr, (sb, v) =>
{
String esStr = v.Substring(0, 1).ToLower() + v.Substring(1);
(sb.Length > 0 ? sb.Append('.') : sb).Append(esStr);
return sb;
});
return AddScript(esExpr.ToString(), update, value);
}
}
public UpdateScriptBuilder<T> AddScript<K>(String rawExpr, UpdateType update, K value)
{
if (typeof(K) == typeof(DateTime) && update != UpdateType.Assign)
{
throw new ArgumentException("日期类型的更新只支持赋值操作", "update");
}
String updateType = null;
switch (update)
{
case UpdateType.Assign:
updateType = "=";
break;
case UpdateType.Add:
updateType = "+=";
break;
default:
updateType = "-=";
break;
}
Tuple<String, Object> tuple = new Tuple<String, Object>(updateType, value);
_maps[rawExpr] = tuple;
return this;
}
public Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> GetScript(out String script)
{
List<String> scriptStubs = new List<String>();
Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> func;
Dictionary<Int32, Object> paramDic = new Dictionary<int, object>();
Int32 vCount = 0;
foreach (var pair in _maps)
{
String left = String.Format("ctx._source.{0}", pair.Key);
paramDic[vCount] = pair.Value.Item2;
scriptStubs.Add(String.Format("{0}{1}value{2}", left, pair.Value.Item1, vCount++));
}
func = f =>
{
foreach (var p in paramDic)
{
f.Add(String.Format("value{0}", p.Key), p.Value);
}
return f;
};
script = String.Join(";", scriptStubs);
return func;
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESAuthorAccess : ESAccess
{
public static Author SearchByAuthorID(String id)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, id))));
return SearchTop(builder);
}
public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(start)
.Size(count)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorName, name)
)
)
);
return Search(builder);
}
public static Author SearchByLocationHistoryTask(DateTime since)
{
//SearchBuilder<Author> builder = new SearchBuilder<Author>();
//builder.Query.Must
// .AddQuery(o => o.Location_NextRefreshTime, ActionType.LessEqual, since)
// .AddQuery(o => o.Location_RefreshStatus, ActionType.Equal, (int)Enums.CrawlStatus.Normal);
//return SearchTop(builder);
try
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.RefreshStatus, 0)
&& m.DateRange(r => r
.Field(f => f.NextRefreshTime)
.GreaterThan(DateTime.MinValue)
.LessThanOrEquals(DateTime.Now)
)
)
)
);
return ESAccess.SearchTop(builder);
}
catch
{
return null;
}
}
public static Boolean DeleteByAuthorID(String id)
{
//QueryContainer query = new TermQuery()
//{
// Field = Property.Path<Author>(p => p.AuthorID),
// Value = id
//};
//DeleteByQueryRequest<Author> builder = new DeleteByQueryRequest<Author>()
//{
// Query = query
//};
//return Delete(builder);
return false;
}
[Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static Boolean IndexOrUpdate(Author result)
{
return ESAccess.IndexOrUpdate(result);
}
public static String SearchAuthorTag(String resultID)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Source(s => s.Includes(f => f.Field(o => o.Tags)))
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, resultID)
)
)
);
Author result = SearchTop(builder);
return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags);
}
public static AuthorRelation SearchRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
return ESAccess.SearchTop(builder);
}
public static Boolean IndexOrUpdateRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
Int32 count = ESAccess.Count(builder);
AuthorRelation relation = new AuthorRelation()
{
TargetID = targetID,
FollowerID = followerID,
UpdateTime = DateTime.Now,
IsDeleted = false,
};
if (count > 0)
{
//return ESAuthorUpdateAccess.Update(relation);
return false;
}
else
{
relation.CreateTime = relation.UpdateTime;
return ESAccess.IndexOrUpdate(relation);
}
}
public static Boolean Update(Author result, String id = null)
{
//return ESAuthorUpdateAccess.Update(result, id);
return false;
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESAuthorUpdateAccess
{
//public static Boolean Update(Author author, Action<UpdateScriptBuilder<Author>> scriptBuilder, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(Author author, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// return false;
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, author);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(AuthorRelation relation, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorRelationIndexID(relation);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore<AuthorRelation>(id, o =>
// {
// o.AddScript<DateTime>(p => p.UpdateTime, UpdateType.Assign, relation.UpdateTime);
// o.AddScript<Boolean>(p => p.IsDeleted, UpdateType.Assign, relation.IsDeleted);
// });
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
private static String GetAuthorIndexID(Author author)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, author.AuthorID)
)
)
);
return ESAccess.SearchESInternalID<Author>(builder);
}
private static String GetAuthorRelationIndexID(AuthorRelation relation)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, relation.FollowerID)
&& m.Term(f => f.TargetID, relation.TargetID)
)
)
);
return ESAccess.SearchESInternalID(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon;
using HTCommon.Data6;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESItemUpdateAccess
{
public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
public static Boolean Update(Item item, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, item);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
private static String GetItemIndexID(Item item)
{
SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.ItemID, item.ItemID)
)
)
);
return ESAccess.SearchESInternalID<Item>(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESUpdateAccess
{
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, Action<UpdateScriptBuilder<T>> scriptBuilder) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// UpdateScriptBuilder<T> builder = new UpdateScriptBuilder<T>();
// scriptBuilder(builder);
// String script = null;
// var func = builder.GetScript(out script);
// Func<UpdateDescriptor<ScriptDescriptor, IScript>> d = new UpdateDescriptor<ScriptDescriptor, IScript>("Index","Type","ID");
// IUpdateResponse<T> resp = ec.Update<T>(id,u => u.Index(id).Script(d).Params(func));
// return resp;
//}
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, T item) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// return ec.Update<T>(id, o => o
// .Index(id)
// .Doc(item)
// );
//}
//public static IUpdateResponse<T> UpdateBulkCore<T>() where T : class
//{
// return null;
//}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
/// <summary>
/// Update方法支持三种更新方式, =, +=, -=
/// 日期类型只支持=
/// </summary>
public enum UpdateType
{
/// <summary>
/// =
/// </summary>
Assign = 0,
/// <summary>
/// +=
/// </summary>
Add,
/// <summary>
/// -=
/// </summary>
Subtract,
}
public class UpdateScriptBuilder<T> where T : class
{
private Dictionary<String, Tuple<String, Object>> _maps = new Dictionary<String, Tuple<String, Object>>();
//private PropertyNameResolver resolver = new PropertyNameResolver(ESClientConfigureManager.ConnectSetting);
/// <summary>
/// 只能修改第一级内容,嵌套的内容请写RawScript
/// </summary>
/// <typeparam name="K">修改项的类型</typeparam>
/// <param name="expr">第一级项目的表达式</param>
/// <param name="update">如何修改项目</param>
/// <param name="value">修改值</param>
/// <returns>返回自己,方便嵌套调用</returns>
public UpdateScriptBuilder<T> AddScript<K>(Expression<Func<T, K>> expr, UpdateType update, K value, Boolean resolve = true)
{
if (resolve)
{
//return AddScript(resolver.Resolve(expr), update, value);
return null;
}
else
{
IEnumerable<String> rawExprs = expr.Body.ToString().Split('.').Skip(1);
StringBuilder esExpr = new StringBuilder();
rawExprs.Aggregate(esExpr, (sb, v) =>
{
String esStr = v.Substring(0, 1).ToLower() + v.Substring(1);
(sb.Length > 0 ? sb.Append('.') : sb).Append(esStr);
return sb;
});
return AddScript(esExpr.ToString(), update, value);
}
}
public UpdateScriptBuilder<T> AddScript<K>(String rawExpr, UpdateType update, K value)
{
if (typeof(K) == typeof(DateTime) && update != UpdateType.Assign)
{
throw new ArgumentException("日期类型的更新只支持赋值操作", "update");
}
String updateType = null;
switch (update)
{
case UpdateType.Assign:
updateType = "=";
break;
case UpdateType.Add:
updateType = "+=";
break;
default:
updateType = "-=";
break;
}
Tuple<String, Object> tuple = new Tuple<String, Object>(updateType, value);
_maps[rawExpr] = tuple;
return this;
}
public Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> GetScript(out String script)
{
List<String> scriptStubs = new List<String>();
Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> func;
Dictionary<Int32, Object> paramDic = new Dictionary<int, object>();
Int32 vCount = 0;
foreach (var pair in _maps)
{
String left = String.Format("ctx._source.{0}", pair.Key);
paramDic[vCount] = pair.Value.Item2;
scriptStubs.Add(String.Format("{0}{1}value{2}", left, pair.Value.Item1, vCount++));
}
func = f =>
{
foreach (var p in paramDic)
{
f.Add(String.Format("value{0}", p.Key), p.Value);
}
return f;
};
script = String.Join(";", scriptStubs);
return func;
}
}
}
using Nest; using Nest;
...@@ -11,17 +11,17 @@ namespace TestES6_2 ...@@ -11,17 +11,17 @@ namespace TestES6_2
{ {
public class ESAuthorAccess : ESAccess public class ESAuthorAccess : ESAccess
{ {
public static Author SearchByAuthorID(String id) public static Author SearchByAuthorID(String id, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Query(q => q .Query(q => q
.Bool(b => b .Bool(b => b
.Must(m => m .Must(m => m
.Term(f => f.AuthorID, id)))); .Term(f => f.AuthorID, id))));
return SearchTop(builder); return SearchTop(builder, index);
} }
public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10) public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(start) .From(start)
...@@ -34,10 +34,10 @@ namespace TestES6_2 ...@@ -34,10 +34,10 @@ namespace TestES6_2
) )
); );
return Search(builder); return Search(builder, index);
} }
public static Author SearchByLocationHistoryTask(DateTime since) public static Author SearchByLocationHistoryTask(DateTime since, string index = null)
{ {
//SearchBuilder<Author> builder = new SearchBuilder<Author>(); //SearchBuilder<Author> builder = new SearchBuilder<Author>();
//builder.Query.Must //builder.Query.Must
...@@ -60,7 +60,7 @@ namespace TestES6_2 ...@@ -60,7 +60,7 @@ namespace TestES6_2
) )
) )
); );
return ESAccess.SearchTop(builder); return ESAccess.SearchTop(builder, index);
} }
catch catch
{ {
...@@ -68,7 +68,7 @@ namespace TestES6_2 ...@@ -68,7 +68,7 @@ namespace TestES6_2
} }
} }
public static Boolean DeleteByAuthorID(String id) public static Boolean DeleteByAuthorID(String id, string index = null)
{ {
//QueryContainer query = new TermQuery() //QueryContainer query = new TermQuery()
//{ //{
...@@ -87,12 +87,12 @@ namespace TestES6_2 ...@@ -87,12 +87,12 @@ namespace TestES6_2
} }
[Obsolete("使用ESAccess.IndexOrUpdate代替")] [Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static Boolean IndexOrUpdate(Author result) public static Boolean IndexOrUpdate(Author result, string index = null)
{ {
return ESAccess.IndexOrUpdate(result); return ESAccess.IndexOrUpdate(result, index);
} }
public static String SearchAuthorTag(String resultID) public static String SearchAuthorTag(String resultID, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
...@@ -106,11 +106,11 @@ namespace TestES6_2 ...@@ -106,11 +106,11 @@ namespace TestES6_2
); );
Author result = SearchTop(builder); Author result = SearchTop(builder, index);
return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags); return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags);
} }
public static AuthorRelation SearchRelation(String followerID, String targetID) public static AuthorRelation SearchRelation(String followerID, String targetID, string index = null)
{ {
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>() SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q .Query(q => q
...@@ -122,10 +122,10 @@ namespace TestES6_2 ...@@ -122,10 +122,10 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchTop(builder); return ESAccess.SearchTop(builder, index);
} }
public static Boolean IndexOrUpdateRelation(String followerID, String targetID) public static Boolean IndexOrUpdateRelation(String followerID, String targetID, string index = null)
{ {
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>() SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q .Query(q => q
...@@ -137,7 +137,7 @@ namespace TestES6_2 ...@@ -137,7 +137,7 @@ namespace TestES6_2
) )
); );
Int32 count = ESAccess.Count(builder); Int32 count = ESAccess.Count(builder, index);
AuthorRelation relation = new AuthorRelation() AuthorRelation relation = new AuthorRelation()
{ {
TargetID = targetID, TargetID = targetID,
...@@ -154,11 +154,11 @@ namespace TestES6_2 ...@@ -154,11 +154,11 @@ namespace TestES6_2
else else
{ {
relation.CreateTime = relation.UpdateTime; relation.CreateTime = relation.UpdateTime;
return ESAccess.IndexOrUpdate(relation); return ESAccess.IndexOrUpdate(relation, index);
} }
} }
public static Boolean Update(Author result, String id = null) public static Boolean Update(Author result, String id = null, string index = null)
{ {
//return ESAuthorUpdateAccess.Update(result, id); //return ESAuthorUpdateAccess.Update(result, id);
return false; return false;
......
using Nest; using Nest;
...@@ -70,7 +70,7 @@ namespace TestES6_2 ...@@ -70,7 +70,7 @@ namespace TestES6_2
// return true; // return true;
//} //}
private static String GetAuthorIndexID(Author author) private static String GetAuthorIndexID(Author author, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(0) .From(0)
...@@ -83,10 +83,10 @@ namespace TestES6_2 ...@@ -83,10 +83,10 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchESInternalID<Author>(builder); return ESAccess.SearchESInternalID<Author>(builder, index);
} }
private static String GetAuthorRelationIndexID(AuthorRelation relation) private static String GetAuthorRelationIndexID(AuthorRelation relation, string index = null)
{ {
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>() SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q .Query(q => q
...@@ -98,7 +98,7 @@ namespace TestES6_2 ...@@ -98,7 +98,7 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchESInternalID(builder); return ESAccess.SearchESInternalID(builder, index);
} }
} }
} }
using Nest; using Nest;
...@@ -11,11 +11,11 @@ namespace TestES6_2 ...@@ -11,11 +11,11 @@ namespace TestES6_2
{ {
public class ESItemUpdateAccess public class ESItemUpdateAccess
{ {
public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null) public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null, string index = null)
{ {
if (String.IsNullOrEmpty(id)) if (String.IsNullOrEmpty(id))
{ {
id = GetItemIndexID(item); id = GetItemIndexID(item, index);
if (id == null) if (id == null)
{ {
...@@ -31,11 +31,11 @@ namespace TestES6_2 ...@@ -31,11 +31,11 @@ namespace TestES6_2
return true; return true;
} }
public static Boolean Update(Item item, String id = null) public static Boolean Update(Item item, String id = null, string index = null)
{ {
if (String.IsNullOrEmpty(id)) if (String.IsNullOrEmpty(id))
{ {
id = GetItemIndexID(item); id = GetItemIndexID(item, index);
if (id == null) if (id == null)
{ {
...@@ -51,7 +51,7 @@ namespace TestES6_2 ...@@ -51,7 +51,7 @@ namespace TestES6_2
return true; return true;
} }
private static String GetItemIndexID(Item item) private static String GetItemIndexID(Item item, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.From(0) .From(0)
...@@ -64,7 +64,7 @@ namespace TestES6_2 ...@@ -64,7 +64,7 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchESInternalID<Item>(builder); return ESAccess.SearchESInternalID<Item>(builder, index);
} }
} }
} }
using System; using HTCommon.Data;
using System; using HTCommon.Data;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Nest;
namespace TestES6_2 namespace TestES6_2
{ {
...@@ -10,7 +12,53 @@ namespace TestES6_2 ...@@ -10,7 +12,53 @@ namespace TestES6_2
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
ESClientConfigureManager es = new ESClientConfigureManager(); //测试语句
// ESClientConfigureManager es = new ESClientConfigureManager();
// SearchDescriptor<HTCommon.Data6.Item> builder6 = new SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.MatchAll());
// var result1 = ESAccess.Search<HTCommon.Data6.Item>(builder6);
// Author model = new Author();
// model.AuthorID = "123123";
// SearchDescriptor<Author> builder2 = new SearchDescriptor<Author>()
// .From(0)
// .Size(1)
// .Query(q => q
// .Bool(b => b
// .Must(m => m
// .Term(f => f.AuthorID, model.AuthorID)
// )
// )
// );
// string result2 = ESAccess.SearchESInternalID<Author>(builder2);
// AuthorRelation relation = new AuthorRelation();
// relation.FollowerID = "xxx";
// relation.TargetID = "yyy";
// SearchDescriptor<AuthorRelation> builder3 = new SearchDescriptor<AuthorRelation>()
// .Query(q => q
// .Bool(b => b
// .Must(m => m
// .Term(f => f.FollowerID, relation.FollowerID)
// && m.Term(f => f.TargetID, relation.TargetID)
// )
// )
// );
// string result3 = ESAccess.SearchESInternalID(builder3);
} }
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -63,16 +63,6 @@ ...@@ -63,16 +63,6 @@
<Compile Include="ESClientConfigureManager2.cs" /> <Compile Include="ESClientConfigureManager2.cs" />
<Compile Include="LimitTime.cs" /> <Compile Include="LimitTime.cs" />
<Compile Include="Util\DebugCheck.cs" /> <Compile Include="Util\DebugCheck.cs" />
<Compile Include="ES2\ESAuthorAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\ESAuthorUpdateAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\ESItemUpdateAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\ESUpdateAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\UpdateScriptBuilder.cs" />
<Compile Include="ES6\ESAuthorAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\ESAuthorUpdateAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\ESItemUpdateAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\ESUpdateAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\UpdateScriptBuilder.cs" />
<Compile Include="ESAccess.cs" /> <Compile Include="ESAccess.cs" />
<Compile Include="ESAuthorAccess.cs" /> <Compile Include="ESAuthorAccess.cs" />
<Compile Include="ESClientConfigureManager.cs" /> <Compile Include="ESClientConfigureManager.cs" />
...@@ -89,6 +79,7 @@ ...@@ -89,6 +79,7 @@
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="ReadMe.md" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\HTCommon\HTCommon.csproj"> <ProjectReference Include="..\..\HTCommon\HTCommon.csproj">
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
</startup> </startup>
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留--> <!--20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" /> <!--
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=0:1:00;version=2;" />-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) --> <!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<!--<add name="ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" />--> <add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=palas_;" />
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=30000;version=6;indexprefix=palas_;" />
</connectionStrings> </connectionStrings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
......
18661e3d123ed5ef8f1402be73de51c43ad386d8 dbc2ec9cbbd20a6415cd45c9ecb9d03738854590
18661e3d123ed5ef8f1402be73de51c43ad386d8 dbc2ec9cbbd20a6415cd45c9ecb9d03738854590
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\TestES6-2.exe.config D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\TestES6-2.exe.config
...@@ -45,7 +45,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Ht ...@@ -45,7 +45,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Ht
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Nest2_5_8.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Nest2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\NPOI.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Elasticsearch.Net2_5_8.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Elasticsearch.Net2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csprojAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.exe.config D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.exe.config
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CoreCompileInputs.cache D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CoreCompileInputs.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CopyComplete D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CopyComplete
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
</startup> </startup>
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留--> <!--20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" /> <!--
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=0:1:00;version=2;" />-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) --> <!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<!--<add name="ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" />--> <add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=palas_;" />
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=30000;version=6;indexprefix=palas_;" />
</connectionStrings> </connectionStrings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
......
 
...@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "..\UnitT ...@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "..\UnitT
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestES6-2", "TestES6-2\TestES6-2.csproj", "{107F4379-D24E-47D6-B4BF-00D49F8F49B7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestES6-2", "TestES6-2\TestES6-2.csproj", "{107F4379-D24E-47D6-B4BF-00D49F8F49B7}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "前期测试", "前期测试", "{D6483C25-7140-45A8-9C92-9732997D14EB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -143,6 +145,14 @@ Global ...@@ -143,6 +145,14 @@ Global
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A1ECE553-F7F3-4E6A-AD8B-E1E88D2445CC} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{B4E898CD-73D9-4B8B-B7C4-650851B33BF7} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{17B93E80-9267-4F75-8423-63E5291A3A8F} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{B3B09BBA-6F8E-4D12-BDCC-36BD847C730E} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{4E2ECE6B-5527-4BCB-819C-5387FED6DAC3} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{3FF2A03B-8F84-41C9-9888-2923FEB814D0} = {D6483C25-7140-45A8-9C92-9732997D14EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DED7A8C5-FA88-49D7-B047-A0B18BB7D103} SolutionGuid = {DED7A8C5-FA88-49D7-B047-A0B18BB7D103}
EndGlobalSection EndGlobalSection
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -4,25 +4,37 @@ ...@@ -4,25 +4,37 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup> </startup>
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=test_;" />
</connectionStrings>
<!--<connectionStrings>
<!--<add name="2localESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />-->
--><!--<add name="2localESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />--><!--
<!--<add name="2localESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" />--> --><!--<add name="2localESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" />--><!--
<add name="6MinderESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" /> <add name="6MinderESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" />
<!--<add name="6MinderESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />--> --><!--<add name="6MinderESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />--><!--
</connectionStrings> </connectionStrings>-->
<runtime> <runtime>
......
using System;
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestES6_2;
namespace UnitTestProject
{
/// <summary>
/// UnitTestES6_2 的摘要说明
/// </summary>
[TestClass]
public class UnitTestES6_2
{
public UnitTestES6_2()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private TestContext testContextInstance;
/// <summary>
///获取或设置测试上下文,该上下文提供
///有关当前测试运行及其功能的信息。
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region 附加测试特性
//
// 编写测试时,可以使用以下附加特性:
//
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// 在运行每个测试之前,使用 TestInitialize 来运行代码
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// 在每个测试运行完之后,使用 TestCleanup 来运行代码
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void Index()
{
try
{
int i = 52;
HTCommon.Data6.Item item6 = new HTCommon.Data6.Item();
//将数据构造为ITEM。
item6.Crawler = "DeleteTestOracleBeigeNEWS";
//item6.Crawler = "Test_Oracle_Beige_NEWS";
item6.CrawlID = "MA_Test_Oracle_Beige_NEWS";
item6.AuthorName = "test2";
item6.CleanTitle = "test";
item6.ClientItemID = "test";
item6.MediaName = "test";
item6.PubDate = DateTime.Now;
item6.Url = "test";
item6.HTMLText = "test";
item6.FetchTime = DateTime.Now;
item6.CleanText = "test";
item6.Tag = "MinderESFromBeigeOracle";
ESAccess.Index()
item6.ItemID = "test" + i3.ToString();
Nest.IIndexResponse rep1 = client.IndexAsync<HTCommon.Data6.Item>(item6, x => x.Index((IndexName)("test_version2"))).Result;
Nest.IIndexResponse rep2 = client.IndexAsync<HTCommon.Data6.Item>(item6, x => x.Index((IndexName)("test_version6"))).Result;
if (i3 == 99)
{
}
Console.WriteLine("测试完毕");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<Compile Include="TestES\TestES2\ESItemAccess.cs" /> <Compile Include="TestES\TestES2\ESItemAccess.cs" />
<Compile Include="TestES\TestES6\ES6.cs" /> <Compile Include="TestES\TestES6\ES6.cs" />
<Compile Include="TestES\TestES6\ESClientConfigureManager.cs" /> <Compile Include="TestES\TestES6\ESClientConfigureManager.cs" />
<Compile Include="UnitTestES6-2.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config"> <None Include="App.config">
...@@ -108,6 +109,10 @@ ...@@ -108,6 +109,10 @@
<Project>{3ff2a03b-8f84-41c9-9888-2923feb814d0}</Project> <Project>{3ff2a03b-8f84-41c9-9888-2923feb814d0}</Project>
<Name>TestTwoES2-6</Name> <Name>TestTwoES2-6</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\TestUnit\TestES6-2\TestES6-2.csproj">
<Project>{107f4379-d24e-47d6-b4bf-00d49f8f49b7}</Project>
<Name>TestES6-2</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Choose> <Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
......
95629e2ac04e9d3473c98b5aefb86d1c73a79a7e c7f551447d788877f1be0cc6ad84da21be455cbb
95629e2ac04e9d3473c98b5aefb86d1c73a79a7e c7f551447d788877f1be0cc6ad84da21be455cbb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment