最快的基于索引的XML搜索 [英] Fastest Index-Based XML Search

查看:99
本文介绍了最快的基于索引的XML搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含20个拉赫斯记录的XML文件.
我希望为textBox生成一个自动完成方法.
对于在XML文件中执行更快的基于索引的搜索,这将是更好的选择.
1.)XPath(或)
2.)LINQ
还是有其他技术可以使搜索更快? Plz建议并解释...

I have an XML-file with around 20Lakhs records.
I wish generate an Auto-Complete method for a textBox.
For Performing faster Index-based-Search in XML-file which will be the better option.
1.) XPath (or)
2.) LINQ
Or Any other technique is there.. for more faster search? Plz suggest and Explain...

推荐答案

如果您正在XML文档中搜索一小部分数据,我会说使用 XmlReader [ HashSet [
If you''re searching for a small portion of data in you XML document, I''d say that using XmlReader[^] provides the fastest access to the data.

However since you''re using it to create an auto-complete text box I guess that the search is going to be repeated often. Because of this it could be reasonable to load and parse the XML document and have an in-memory copy of the data in such format which is both fast to search and compact in size. Utilizing a HashSet[^] could be one option.



自动完成扩展程序可与Web服务或装饰有Web服务方法和脚本服务方法属性的页面方法一起使用.要从文件中读取具有大量记录的XML并搜索键入的每个字符是一项艰巨的工作.内存中的收集可能会有所帮助.无论是xpath还是linq,都必须在数据加载到内存后执行.因此,如果您已经在内存中,则可以避免这种开销.但是请记住,这又是速度和内存消耗之间的权衡.内存中的集合永久占用一些内存空间.再次它是一个字符串集合,肯定会占用更多空间.您可以在自动完成标记中设置的关键参数是MinimumPrefixLength.至少应为3,以避免进行昂贵的搜索.

另一种方法将xml存储在sql服务器中,并在需要时检索它并可以使用xpath.这将比基于文件的速度更快.请参考此链接.
http://msdn.microsoft.com/en-us/library/ms187508%28v = sql.90%29.aspx [ ^ ]

如果您使用关键字"ado.net xml最佳实践",那么google会提供更多信息.

您要求输入密码.好了,这里是内存集合中的代码

Hi
The autocomplete extender works with a webservice or a page method decorated with webservice method and script service method attributes. To read an XML with that much record from file and search for each character typed is a huge work. An in memory collection may help a little. Whether xpath or linq, it has to be executed after the data loaded into memory. So if you have that already in memory this overhead can be avoided. But remember this is again a trade off between speed and memory consumption. The in memory collection permanently occupy some memory space. Again it is a string collection definitely occupy more space. The key parameter you can set in the autocomplete markup is MinimumPrefixLength. It should be minimum 3 to avoid a costly search.

Another way store the xml in sql server and when needed retrieve it and can use the xpath. Which will be more faster than file based. Refer this link. http://msdn.microsoft.com/en-us/library/ms187508%28v=sql.90%29.aspx[^]

Well google give more information if you use key words "ado.net xml best practice".

You asked for a code. Well here is the code for in memory collection

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class TestService : System.Web.Services.WebService {
    //it is a static array which will be available at the application scope. Not session based.
    private static string[] suggestions;

    [WebMethod]
    public string[] getSuggestions(string prefixText, int count)
    {
        //static array will be populated only one time.
        if (suggestions == null)
        {
            setSuggestions();
        }
        return suggestions.Where(x => x.StartsWith(prefixText)).ToArray<string>();
    }
    //if some instance the list corrupted can be reset.
    [WebMethod]
    public void ResetSuggestions()
    {
        setSuggestions();
    }
    private void setSuggestions()
    {
        IList<string> templist = new List<string>();
        //have your xml reading code here to populate the array.
        templist.Add("happy");
        templist.Add("world");
        suggestions = templist.ToArray();
    }
}



但是重要的是 don''t just rely on the code blindly. Follow my guidelines above, read more and decide which one fit for your case. Try yourself and then come back if you have any problem with code.



But the important thing don''t just rely on the code blindly. Follow my guidelines above, read more and decide which one fit for your case. Try yourself and then come back if you have any problem with code.


这篇关于最快的基于索引的XML搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆