我有一个视图模型:
var prop1 = ko.observable().extend{ required: true },
prop2 = ko.observable().extend{ required: true };
var validation = ko.validatedObservable([prop1, prop2]);
function resetFields() {
prop1(undefined);
prop2(undefined);
}
var vm = {
prop1: prop1,
prop2: prop2,
validation: validation,
reset: resetFields
};
Run Code Online (Sandbox Code Playgroud)
属性prop1和prop2正在通过validatedObservable正确验证,但是当我执行resetFields时,这些属性会因为它们已经被修改并且是必需的而有错误.
有没有办法重置已验证的observable,好像它没有被更改?
更新:我从NuGet采购knockout.validation,并使用v1.0.1
我开始使用EF Code First和MVC,我有点难过.我有以下数据库结构(很抱歉,我不允许发布图片):
表 - 产品
表 - 相关产品
Products.ProductID上的1-Many - > RelatedProducts.ProductID
1 - Products.ProductID上的很多 - > RelatedProducts.RelatedProductID
基本上我有一个产品,可以有一系列与之相关的产品.它们保存在RelatedProducts表中,其中包含ProductID和相关产品的ProductID定义的关系,我将其命名为RelatedProductID.在我的代码中,我生成了以下类:
public class MyDBEntities : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<RelatedProduct> RelatedProducts { get; set; }
}
public class Product
{
public Guid ProductID { get; set; }
public string Name { get; set; }
public string Heading { get; set; }
public string Description { get; set; }
public decimal Price { get; set; } …Run Code Online (Sandbox Code Playgroud) many-to-many entity-framework-4 self-reference entity-framework-ctp5
我正在尝试使用elasticsearch/NEST索引pdf文档.
该文件已编制索引,但搜索结果返回0次点击.
我需要搜索结果只返回文档ID和突出显示结果
(没有base64内容)
这是代码:
我会感激任何帮助,
谢谢,
class Program
{
static void Main(string[] args)
{
// create es client
string index = "myindex";
var settings = new ConnectionSettings("localhost", 9200)
.SetDefaultIndex(index);
var es = new ElasticClient(settings);
// delete index if any
es.DeleteIndex(index);
// index document
string path = "test.pdf";
var doc = new Document()
{
Id = 1,
Title = "test",
Content = Convert.ToBase64String(File.ReadAllBytes(path))
};
var parameters = new IndexParameters() { Refresh = true };
if (es.Index<Document>(doc, parameters).OK)
{
// search …Run Code Online (Sandbox Code Playgroud) 我已经使用Nest成功获得了结果和重点,但是如果我包含两个要搜索高亮的字段,它只使用构造elasticsearch查询的最后一个字段.例如以下
.Query(qry => qry
.QueryString(qs => qs
.Query(qString)
)
)
.Highlight(h => h
.PreTags("<b>")
.PostTags("</b>")
.OnFields(f => f
.OnField("Title")
.OnField("Summary")
)
)
Run Code Online (Sandbox Code Playgroud)
意味着我只获得从"摘要"字段返回的高亮显示.如果我使用等效查询直接查询elasticsearch,我可以从两个字段中检索突出显示.例如
{
"query": {
"query_string": {
"query": "apple"
}
},
"highlight": {
"pre_tags": ["<b>"],
"post_tags": ["</b>"],
"fields": {
"Title": {},
"Summary": {}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有可能用Nest做到这一点吗?难道我做错了什么?
作为基于asp.net,c#,silverlight,XBAP的应用程序国际化的一部分,我正在评估开始的方法.我必须在GNU gettext()(PO文件)和Microsoft的资源(resx)方法之间进行选择.所以在这个时刻,我试图了解如果我必须采用MS方式,从.cs文件,aspx,ascx,xaml(silverlight)文件到资源文件(resx)自动提取可本地化字符串的最佳方法是什么.
我有以下选项:
我知道必须进行一些人工干预,但任何建议都有助于在gettext()(gnu gettext()c#或者相当本地化或MS本地化方法之间选择正确的方向.
如何使用Mpdreamz/NEST Elasticsearch客户端基于嵌套字段的属性列出构面?
我查看了Nest文档,但目前尚不清楚如何操作.
这是我尝试的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using Nest;
namespace Demo
{
class Program
{
public class Movie
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
[ElasticProperty(Index = FieldIndexOption.analyzed, Type = FieldType.nested)]
public List<Genre> Genres { get; set; }
public int Year { get; set; }
}
public class Genre
{
// public int Id { get; set; }
[ElasticProperty(Index = FieldIndexOption.analyzed)]
public …Run Code Online (Sandbox Code Playgroud) 我是弹性搜索的完全初学者,我一直在尝试使用elasticsearch的完成建议,使用Nest来自动完成属性.
这是我的映射(如下所述:):
var createResult = client.CreateIndex(indexName, index => index
.AddMapping<Contact>(tmd => tmd
.Properties(props => props
.Completion(s =>
s.Name(p => p.CompanyName.Suffix("completion"))
.IndexAnalyzer("standard")
.SearchAnalyzer("standard")
.MaxInputLength(20)
.Payloads()
.PreservePositionIncrements()
.PreserveSeparators())
)
)
);
var resultPerson = client.IndexMany(documents.OfType<Person>(), new SimpleBulkParameters { Refresh = true });
var resultCompany = client.IndexMany(documents.OfType<Company>(), new SimpleBulkParameters { Refresh = true });
Run Code Online (Sandbox Code Playgroud)
索引时我只是使用IndexMany方法并传递IEnumberable<Contact>(Contact有一个名称为CompanyName的属性,Contact是一个抽象类,Person和Company都是它的具体实现).搜索引发异常,说ElasticSearchException [Field [companyName]不是完成建议字段].查询如下所示:
SearchDescriptor<Contact> descriptor = new SearchDescriptor<Contact>();
descriptor = descriptor.SuggestCompletion("suggest", c => c.OnField(f => f.CompanyName).Text(q));
var result = getElasticClientInstance("contacts").Search<Contact>(body => …Run Code Online (Sandbox Code Playgroud) 我在按特定术语搜索文档时遇到困难.我每次都得到零结果.
这是一个代码示例:
var customers = new List<SampleCustomer>();
customers.Add(new SampleCustomer(){id=1,firstname="John", surname="Smith", country = "UK", sex = "Male", age=30});
customers.Add(new SampleCustomer(){id=2,firstname="Steve", surname="Jones", country ="UK", sex = "Male", age=22});
customers.Add(new SampleCustomer(){id=3,firstname="Kate", surname="Smith", country ="UK", sex = "Female", age=50});
customers.Add(new SampleCustomer(){id=4,firstname="Mark", surname="Jones", country ="USA", sex = "Male", age=45});
customers.Add(new SampleCustomer(){id=5,firstname="Emma", surname="Jonson", country ="USA", sex = "Female", age=25});
customers.Add(new SampleCustomer(){id=6,firstname="Tom", surname="Jones", country ="France", sex = "Male", age=30});
customers.Add(new SampleCustomer(){id=7,firstname="Liz", surname="Web", country ="France", sex = "Female", age=45});
foreach (var customer in customers)
{
_elasticClient.DeleteById("sample", "SampleCustomers",customer.id);
_elasticClient.Index(customer, …Run Code Online (Sandbox Code Playgroud)