javascript - search xml file for any occurrence in search string -
When searchterm is one of the keywords (like 'driver' or 'white)' gives this result and it looks okay, But whenever SEARCHTERM has been extended to 'Driver 102' or 'R-22 red' is not something.
(tried to loop on the quote from the regular expression, avoiding spaces, but SEARCHTERM - it goes through each letter) <
Any idea about how to get results from keywords in many keywords (like 'Driver 102' or 'R-22 red')
* XML Doc: * & Lt; Find_index & gt; & Lt; Search & gt; & Lt; Title & gt; Driver & lt; / Title & gt; & Lt; Keyword & gt; 101 101 & lt; / Keyword & gt; & Lt; Link & gt; R-12 & lt; / Link & gt; & Lt; Color & gt; White & lt; / Color & gt; & Lt; Itemid & gt; Trial & lt; / Itemid & gt; & Lt; / Search & gt; & Lt; Search & gt; & Lt; Title & gt; Driver & lt; / Title & gt; & Lt; Keyword & gt; 102 & lt; / Keyword & gt; & Lt; Link & gt; R-22 & lt; / Link & gt; & Lt; Color & gt; Red & lt; / Color & gt; & Lt; Itemid & gt; 1test & lt; / Itemid & gt; & Lt; / Search & gt; & Lt; / Searchable_index & gt; * Javascript: * function loadIndex () {if (document.implementation & amp; document.implementation.createDocument) {xmlDoc = document.implementation.createDocument ("", "", tap); XmlDoc.load ("index9.xml"); } And if (window.ActiveXObject) {xmlDoc = New ActiveXObject ("Microsoft.XMLDOM"); XmlDoc.async = "false"; XmlDoc.load ("index9.xml"); }} Function searchIndex () {if (! XmlDoc) {loadIndex (); } Var searchterm = document.getElementById ("search"). Values; Searchtermconvert = searchterm.toString (); Var arrsearch = xmlDoc.getElementsByTagName ("search"); Result = new array; If (searchtermconvert.length & lt; 3) {warnings ("enter at least three characters"); } Else {for (var i = 0; i & lt; arrsearch.length; i ++) {var variables = arc [i] .textcontent; Var exp = New RegExp (Search MMM, "G"); If (variable.match (exp)! = Null) {results.push (arrsearch [i]); }} ShowResults (result, searchtermconvert); }}
Extra parts that provide search results for multiple search terms: var exp = New RegExp (res [0], "i"); Var exp2 = new RegExp (res [1], "i"); Var exp3 = new RegExp (res [2], "i"); Var exp4 = new RegExp (res [3], "i"); Var exp5 = new RegExp (res [4], "i");
Then add additional terms for if statement
if (variable.match (exp)! = Null & amp; variable.match (exp2)! = Null & amp; variable.match (exp3) = Null & amp;! And variable.match (exp4) = Null & amp;! Variable.match (exp5) = null)
And the result is that you can search with many search terms.
Comments
Post a Comment