索引XML文档/文件的最佳方法?

I have a XML document which contains around 4000 entries of data. The data will be used in a PHP environment and is needed for a Web-App. I thought about using "sphinx" ( http://sphinxsearch.com/docs/2.0.1/xmlpipe2.html ) for indexing the data but was wondering, what other, maybe better options are out there.

Thanks in advance, Andy

EDIT: I don't want to write an importer script which loads the XML file into a e.g. MySQL-DB. It should be something like: Load the file into this tool/program/whatever and then it should be searchable from PHP.

#0

If you have 4000 entry's and you want only one, the whole file is read until it finds your entry. That can be a long time. You might want to use a Database like MySQL.


If you want to make your XML-file search able, you'll end up with one of those two options:

  1. You parse the entire file into an Array or something that can be quickly searched (will cause a lot of memory on every call to the PHP-Script)
  2. You iterate through the whole XML file, searching for your desired entry (will be even slower then number one because you'll have to see if it's your desired entry every time before you can continue to search).

For performance-reasons, neither of those options are really acceptable. It gets even more tricky if you want users to edit your XML-file, because they are not multi-thread save (like Databases).

If you want a good performance for your search, you'll want to use a Database. It's just as easy as that.

Yet another thing would be letting the users machine parse the XML-File (using JavaScript) and get something like a id for the desired article (which is then opened from your Server). But depending of your XML-file's size and the power of the user's machine, the Browser might interrupt and cancel the script.

#1

I'll second Lukas: like it or not, you won't escape parsing and normalizing if you're expecting any kind of performance.

You'll make good use of an ORM (SQL or NoSQL) that can import xml or parsed xml (as objects or json) and persist it directly. (I'm pretty certain that Doctrine can do such a thing. Also look into MongoDB and CoucheDB for NoSQL options.)

推荐文章

如何从函数返回变量

如何从函数返回变量

推荐文章

jQgrid下拉菜单未在表单编辑中填充数据

jQgrid下拉菜单未在表单编辑中填充数据

推荐文章

使用缩放功能时Android应用程序按钮单击事件问题

使用缩放功能时Android应用程序按钮单击事件问题

推荐文章

如何删除正文周围的空白或清除默认css样式

如何删除正文周围的空白或清除默认css样式

推荐文章

深度优先搜索-2D游戏地图

深度优先搜索-2D游戏地图

推荐文章

使用SQLAlchemy向相关表添加数据

使用SQLAlchemy向相关表添加数据

推荐文章

如何在Android中显式调用onClick(viewv)方法?有可能吗?

如何在Android中显式调用onClick(viewv)方法?有可能吗?

推荐文章

菲律宾比索_mssql.dll文件不在Wamp2.2d中

菲律宾比索_mssql.dll文件不在Wamp2.2d中

推荐文章

控制台中的adb不工作,但eclipseddms工作正常

控制台中的adb不工作,但eclipseddms工作正常

推荐文章

PHP下拉菜单检索结果

PHP下拉菜单检索结果

推荐文章

在C语言中动态分配变量

在C语言中动态分配变量

推荐文章

如何使用xCode核心数据本地化字符串

如何使用xCode核心数据本地化字符串

推荐文章

软件事务性内存,具有大的共享数据块

软件事务性内存,具有大的共享数据块

推荐文章

重置扫描仪对象读取的字符串

重置扫描仪对象读取的字符串

推荐文章

最基本的分布式Java——我应该使用什么通信方法?

最基本的分布式Java——我应该使用什么通信方法?

推荐文章

视图.player专辑封面

视图.player专辑封面