I have a large XML file (around 20MB, but suppose to grow) and I have search form where I can enter searched keyword(s). I try to use DOMXPath::query
to find what I need. Search is going through all nodes and if match is found it returns publication
element (see XML below). It works fine but if I have 10 000 publications searching lasts 4 seconds which is very slow (I expect to have milions of publications).
XML file:
<publication>
<identificators>
<identificator type="isbn">978-1-101-61439-8</identificator>
</identificators>
<title>Secured foreground capacity</title>
<abstract>Illo dignissimos nulla libero ut ut. Inventore voluptas mollitia et officia. In quidem inventore voluptatem quas maxime. Et similique aliquam et sunt nulla.
Quae molestiae dolor architecto dicta non. Quia illo quia tempore architecto pariatur quo commodi cumque. Cumque nemo qui sunt.
Corporis quia reprehenderit modi neque architecto perferendis eligendi. Eveniet nobis illum totam possimus modi assumenda. Quia sed hic sit sequi. Doloremque temporibus eaque velit sed enim.</abstract>
<dates>
<date type="release">18.09.1995</date>
<date type="added">17.07.1991</date>
</dates>
<language>Bajan</language>
<release-number>2</release-number>
<publisher>Kub PLC</publisher>
<filepath/to/file.pdf</file>
<type>Note</type>
<categories>
<category>Health Professions</category>
<category>Computer Science</category>
<category>Agricultural and Biological Sciences</category>
<category>Chemical Engineering</category>
<category>Materials Science</category>
</categories>
<keywords>
<keyword>quia</keyword>
<keyword>placeat</keyword>
</keywords>
<authors>
<main-author>Nannie Klocko</main-author>
<co-authors>
<co-author>Name Surname</co-author>
</co-authors>
</authors>
<affiliation>
<name>Rippin, Stehr and Ryan</name>
<type>Organisation</type>
<address>
<street>Rath Corner</street>
<city>San Nicolás de los Garza</city>
<country/>
</address>
</affiliation>
</publication>
So I read about XMLReader
how fast it is and so on but I found only examples how to read whole file and I need to know if I can use it to speed up my searching? If so can you provide some simple example?
Here is my XPath query now:
$xpath_query = "//publications/publication[contains(translate(., 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'), '$search_keyword')]";
Can I use something like this with XMLReader? Thank you very much for every hint.