摘要: 我们知道ajax本身实际上是通过XMLHttpRequest对象来异步进行数据的交互,而浏览器出于安全考虑,不允许js代码进行跨域操作,所以js跨域操作会被拒绝。具体情况有:一、本域和子域的相互访问: http://www.aa.com/和book.aa.com二、本域和其他域的相互访问: http://www.aa.com/和http://www.bb.com/ 用 iframe三、本域和其他域...阅读全文
posted @ 2010-03-12 17:30 ido 阅读(1437) 评论(0) 编辑
摘要: google map默认的标示GMarker,只能使用图片不能使用文字。但是在实际中,我们不可避免的需要在地图上标示文字信息。例如地名等。Google 地图 API 使我们可以通过扩展GMarker实现自定义的GMarker的子类LabelMarker。[代码]在页面上调用的代码:[代码]现在就会在地图上显示我们自定义的GMarker标识了。继承GOverlay的实现自定义GMarker的方法: ...阅读全文
posted @ 2009-12-26 09:25 ido 阅读(5640) 评论(10) 编辑

RewriteFilterPriority HIGH

添加到IirfGlobal.ini。

posted @ 2012-05-08 17:22 ido 阅读(6) 评论(0) 编辑
写过两篇关于LUCENE高性能GROUP BY、DISTINCT的文章,最近在研究LUCENE的过程中发现了一个名为FieldCache的东东,于是乎重新改进Lucene高性能GROUP BY、DISTINCT,发现性能有了数量级别的提升,究竟是因为啥让它有了如此之高的性能提升呢?下面我就来为大家揭开这个谜团!

FieldCache是啥?

我们知道,如果对每一个文档号都用reader 读取域的值会影响速度,所以Lucene 引入了FieldCache 来进行缓存,而FieldCache 并非在存储域中读取,而是在索引域中读取,从而
不必构造Document 对象,然而要求此索引域是不分词的,有且只有一个Token。

讲到这里,我们似乎知道了一些东西,那就是,索引进LUCENE中数据至少会在两个地方有相关的存储,一个就是存储域,一个就是索引域。

即然FieldCache说它是从索引域中读取,速度相对从存储域读取肯定快,为什么不用它呢?

说干就干,经过一番折腾,得到下面的测试结果:

环境:对100W条数据量,取出其中要分组的字段,当然这个字段是不分词索引进去的

第一种方式:从Term区域读取
View Code

Dictionary<int, object> dictionary = new Dictionary<int, object>();
Term startTerm = new Term("CompanyID");
TermEnum te = indexReader.Terms(startTerm);
if (te != null)
{
Term currTerm = te.Term();

while ((currTerm != null) && (currTerm.Field() == startTerm.Field())) //term fieldnames are interned
{
//if (te.DocFreq() > 1)
//{
TermDocs td = indexReader.TermDocs(currTerm);
while (td.Next())
{
dictionary.Add(td.Doc(), currTerm.Text());
}
//}
if (!te.Next())
{
break;
}
currTerm = te.Term();
}
}

取出100W个CompanyID耗时:共耗时20.9291356秒

第二种方式:从FieldCache中读取
View Code

StringIndex stringIndex = FieldCache_Fields.DEFAULT.GetStringIndex(indexReader, "CompanyID");

取出100W个CompanyID耗时:共耗时2.8249935秒

补充:StringIndex有两个属性:lookup、order

string[] lookup:按照字典顺序排列的所有term

int[] order:  其中位置表中文档号,order[i]表示第i个document某个field包含的term在lookup中的位置

获取docid对应的term的值:termValue = lookup[order[doc]]

两者性能一目了然,我也不多说了,快去试试吧!

最后当然也不忘了说一句,如果你的数据量是千万级别或上亿了,那你必须得考虑分布式计算、并行计算这一类的计术了,呵呵。

[by:http://www.cnblogs.com/zengen/archive/2011/04/19/2020681.html]
posted @ 2012-04-20 15:57 ido 阅读(33) 评论(0) 编辑

public Expression<Func<Job, bool>> ToLambda()
        {
            Type type = typeof (Job);
            ParameterExpression parameterExpression = Expression.Parameter(type, "job");

            Expression body = Expression.Equal(Expression.Property(parameterExpression, "MemberId"), Expression.Constant(MemberId));

            if (Key.IsNotNullAndWhiteSpace())
            {
                MemberExpression keyMember = Expression.Property(parameterExpression, "JobName");
                Expression value = Expression.Constant(Key);
                MethodCallExpression keyExpression = Expression.Call(keyMember,
                                                                          typeof (string).GetMethod("Contains"),
                                                                          value);
                body = Expression.And(body, keyExpression);
            }

            if(IsOpen.HasValue)
            {
                MemberExpression isOpenExpression = Expression.Property(parameterExpression, "IsOpen");
                Expression openExpression = Expression.Equal(isOpenExpression, Expression.Constant(IsOpen));
                body = Expression.And(body, openExpression);
            }

            return Expression.Lambda<Func<Job, bool>>(body, parameterExpression);
        }

posted @ 2012-04-12 08:52 ido 阅读(56) 评论(0) 编辑

原文地址:http://www.dovetailsoftware.com/blogs/kmiller/archive/2010/07/02/using-the-tika-java-library-in-your-net-application-with-ikvm?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+KevinMiller+(Kevin+Miller)

Using the Tika Java Library In Your .Net Application With IKVM

This may sound scary and heretical but did you know it is possible to leverage Java libraries from .Net applications with no TCP sockets or web services getting caught in the crossfire? Let me introduce you to IKVM, which is frankly magic:

IKVM.NET is an implementation of Java for Mono and the Microsoft .NET Framework. It includes the following components:

  • A Java Virtual Machine implemented in .NET
  • A .NET implementation of the Java class libraries
  • Tools that enable Java and .NET interoperability

Using IKVM we have been able to successfully integrate our Dovetail Seeker search application with the Tika text extraction library implemented in Java. With Tika we can easily pull text out of rich documents from many supported formats. Why Tika?  Because there is nothing comparable in the .Net world as Tika.

This post will review how we integrated with Tika. If you like code you can find this example in a repo up on Github.

Compiling a Jar Into An Assembly

First thing, we need to get our hands on the latest version of Tika. I downloaded and built the Tika source using Maven as instructed. The result of this was a few jar files. The one we are interested in is tika-app-x.x.jar which has everything we need bundled into one useful container.

Next up we need to convert this jar we’ve built to a .Net assembly. Do this using ikvmc.exe.

tika\build>ikvmc.exe -target:library tika-app-0.7.jar

Unfortunately, you will see tons of troublesome looking warnings but the end result is a .Net assembly wrapping the Java jar which you can reference in your projects. 

Using Tika From .Net

IKVM is pretty transparent. You simply reference the the Tika app assembly and your .Net code is talking to Java types. It is a bit weird at first as you have Java versions of types and .Net versions. Next you’ll want to make sure that all the dependent IKVM runtime assemblies are included with your project. Using Reflector I found that the Tika app assembly referenced a lot of IKVM assemblies which do not appear to be used. I had to figure out through trial and error which assemblies where not being touched by the rich document extractions being done. If need be you could simple include all of the referenced IKVM assemblies with your application. Below I have done the work for you and eliminated all references to all the IKVM assemblies which appear to be in play.

image

16 assemblies down to 5. A much smaller deployment.

Using Tika

To do some text extraction we’ll ask Tika, very nicely, to parse the files we throw at it. For my purposes this involved having Tika automatically determine how to parse the stream and extract the text and metadata about the document.

public TextExtractionResult Extract(string filePath)
{
    var parser = new AutoDetectParser();
    var metadata = new Metadata();
    var parseContext = new ParseContext();
    java.lang.Class parserClass = parser.GetType();
    parseContext.set(parserClass, parser);
  
    try
    {
        var file = new File(filePath);
        var url = file.toURI().toURL();
        using (var inputStream = MetadataHelper.getInputStream(url, metadata))
        {
            parser.parse(inputStream, getTransformerHandler(), metadata, parseContext);
            inputStream.close();
        }
  
        return assembleExtractionResult(_outputWriter.toString(), metadata);
    }
    catch (Exception ex)
    {
        throw new ApplicationException("Extraction of text from the file '{0}' failed.".ToFormat(filePath), ex);
    }
}

One Important Cavet

Java has a concept called a ClassLoader which has something to do with how Java types are found and loaded. There is probably a better way around this but for some reason if you do not implement a custom ClassLoader and also set an application setting cueing the IKVM runtime about which .Net type to use as the ClassLoader.

public class MySystemClassLoader : ClassLoader
{
    public MySystemClassLoader(ClassLoader parent)
        : base(new AppDomainAssemblyClassLoader(typeof(MySystemClassLoader).Assembly))
    {
    }
}

Here is an example app.config telling IKVM where the ClassLoader is found.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="ikvm:java.system.class.loader" value="TikaOnDotNet.MySystemClassLoader, TikaOnDotNet" />
    </appSettings>
</configuration>

This step is very important. If IKVM cannot find a class loader, for some horrible reason, Tika will work fine but extract only empty documents with no metadata. The main reason this is troubling is that no exception is raised. For this reason we actually have a validation step in our application ensuring that the app setting is present and that it resolves to a valid type.

Demo

Here is a test demonstrating an extraction and the result.

[Test]
public void should_extract_from_pdf()
{
    var textExtractionResult = new TextExtractor().Extract("Tika.pdf");
 
    textExtractionResult.Text.ShouldContain("pack of pickled almonds");
 
    Console.WriteLine(textExtractionResult);
}

Put simply rich documents like this go in.

Test PDF

And a TextExtractionResult comes out:

public class TextExtractionResult
{
    public string Text { get; set; }
    public string ContentType { get; set; }
    public IDictionary<string, string> Metadata { get; set; } 
    //toString() override
}

Here is the raw output from Tika:

image

Conclusion

I hope this helps boost your confidence that you can use Java libraries in your .Net code and I hope my example repo will be of assistance if you need to do some work with Tika on the .Net platform. Enjoy.

posted @ 2012-03-26 10:23 ido 阅读(42) 评论(0) 编辑

常见问题:无法更改关系,因为一个或多个外键属性不可以为 null。对关系作出更改后,会将相关的外键属性设置为 null 值。如果外键不支持 null 值,则必须定义新的关系,必须向外键属性分配另一个非 null 值,或必须删除无关的对象。

解决方法:

例如OrderItem和Product是一对多的关系

OrderItem.ProductId是关系的外键

你要先删除对product的引用,比如表OrderItem里有一个到Product.Id的外键的话,需要将其设为空值对应。所以在删除之前要将OrderItem.ProductId设置为0或null

posted @ 2012-02-23 10:01 ido 阅读(130) 评论(2) 编辑
摘要: 对关系使用默认规则与配置In Chapter 3, you learned about convention and configuration that affect attributes of properties and the effects that these have on the database. In this chapter, the focus will be on convention and configuration that affects the relationships between classes. This includes how classes 阅读全文
posted @ 2012-02-22 17:20 ido 阅读(324) 评论(0) 编辑
摘要: Earlier this month the data team shipped the Release Candidate of EF 4.1. The most exciting feature of EF 4.1 is Code First, a new development pattern for EF which provides a really elegant and powerful code-centric way to work with data as well as an alternative to the existing Database First and M阅读全文
posted @ 2011-12-15 16:03 ido 阅读(67) 评论(0) 编辑
摘要: 在asp.net mvc进行身份验证只用在需要验证的Action或者Controller上标记一个[authorization]即可,如果用户没有登陆,此时将返回的ActionResult是HttpUnauthorizedResultCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->publicclassHttpUnauthorizedResult:ActionResult{publicoverridevoidExecuteResult(Con阅读全文
posted @ 2011-11-22 17:29 ido 阅读(134) 评论(0) 编辑
摘要: Why compiled views?First of all I prefer VS.NET to compile the cshtml code at build time because it will notice syntax errors like on any .cs file. Syntax errors are most important when I have to do a quick check-in of all my sources to repository and I need to make sure I will not crash the next te阅读全文
posted @ 2011-10-13 10:47 ido 阅读(56) 评论(0) 编辑
摘要: http://msdn.microsoft.com/en-us/library/bb738523.aspxThis topic provides an example of how to define a transaction that coordinates making changes to objects in an object context with other external operations. For more information, see Managing Connections and Transactions. The example in this t...阅读全文
posted @ 2011-10-11 10:39 ido 阅读(105) 评论(0) 编辑