Getting Sphider to output JSON -
i've added sphider crawler site in order add search functionality. default search.php comes distribution of sphider downloaded plain , doesn't integrate rest of site. have little navigation bar @ top of site has search box in it, , i'd able access sphider's search results through search field using ajax. this, figure need sphider return results in json format.
the way did used "theme" outputs json (sphider supposts "theming" output). found theme on this thread on sphider's site. seems work, more strict json parsers not parse it. here's example json output:
{"result_report":"displaying results 1 - 1 of 1 match (0 seconds) ", "results":[ { "idented":"false", "num":"1", "weight":"[100.00%]", "link":"http://www.avtainsys.com/articles/triple_contraints", "title":"triple contraints", "description":" on 01/06/12 project triple constraints time, cost, , quality. these 3 constraints control performance of project. think triple-constraint three-leg tripod. if 1 of legs elongated or", "link2":"http://www.avtainsys.com/articles/triple_contraints", "size":"3.3kb" }, { "num":"-1" } ], "other_pages":[ { "title":"1", "link":"search.php?query=constraints&start=1&search=1&results=10&type=and&domain=", "active":"true" }, ] } the issue there trailing comma near end. according this, "trailing commas not allowed" when using php's json_decode() function. json failed parse using this online formatter. when took comma out, worked , got better-formatted json:
{ "result_report":"displaying results 1 - 1 of 1 match (0 seconds) ", "results":[ { "idented":"false", "num":"1", "weight":"[100.00%]", "link":"http://www.avtainsys.com/articles/triple_contraints", "title":"triple contraints", "description":" on 01/06/12 project triple constraints time, cost, , quality. these 3 constraints control performance of project. think triple-constraint three-leg tripod. if 1 of legs elongated or", "link2":"http://www.avtainsys.com/articles/triple_contraints", "size":"3.3kb" }, { "num":"-1" } ], "other_pages":[ { "title":"1", "link":"search.php?query=constraints&start=1&search=1&results=10&type=and&domain=", "active":"true" } ] } now, how programmatically? , (perhaps more importantly), there more elegant way of accomplishing this? , should know php language can run on shared hosting account, java solution example not work me.
in search_result.html, can surround , @ end of foreach loop condition print if index strictly less number of pages - 1.
Comments
Post a Comment