Index: trunk/test/test_115/model.bin
===================================================================
--- trunk/test/test_115/model.bin	(revision 2426)
+++ trunk/test/test_115/model.bin	(revision 2427)
@@ -1 +1 @@
-a:1:{i:0;a:10:{i:0;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:4:{i:1;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:3;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:11;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"4";s:11:"total_found";s:1:"4";s:4:"time";s:5:"0.008";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"b";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"c";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"d";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:18:""a b" NEAR/2 "c d"";}i:1;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:6:{i:13;a:2:{s:6:"weight";s:1:"4";s:5:"attrs";a:0:{}}i:1;a:2:{s:6:"weight";s:1:"3";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:1:"3";s:5:"attrs";a:0:{}}i:3;a:2:{s:6:"weight";s:1:"3";s:5:"attrs";a:0:{}}i:11;a:2:{s:6:"weight";s:1:"3";s:5:"attrs";a:0:{}}i:12;a:2:{s:6:"weight";s:1:"3";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"6";s:11:"total_found";s:1:"6";s:4:"time";s:5:"0.064";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"b";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"c";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"d";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:14:"a b NEAR/2 c d";}i:2;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:2:{i:13;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:12;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"2";s:11:"total_found";s:1:"2";s:4:"time";s:5:"0.025";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"b";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"c";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}s:1:"d";a:2:{s:4:"docs";s:2:"13";s:4:"hits";s:2:"13";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:28:"a NEAR/2 b NEAR/2 c NEAR/2 d";}i:3;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:20:{i:524;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:15;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:16;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:17;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:18;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:19;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:20;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:21;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:22;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:23;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:24;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:25;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:26;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:27;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:28;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:29;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:30;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:31;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:32;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}}s:5:"total";s:3:"511";s:11:"total_found";s:3:"511";s:4:"time";s:5:"0.048";s:5:"words";a:4:{s:1:"e";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:3:"512";}s:1:"f";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:3:"512";}s:1:"g";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:3:"512";}s:1:"h";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:3:"512";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:18:""e f" NEAR/2 "g h"";}i:4;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:20:{i:525;a:2:{s:6:"weight";s:3:"512";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:15;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:16;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:17;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:18;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:19;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:20;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:21;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:22;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:23;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:24;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:25;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:26;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:27;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:28;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:29;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:30;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:31;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:32;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}}s:5:"total";s:3:"511";s:11:"total_found";s:3:"511";s:4:"time";s:5:"0.146";s:5:"words";a:4:{s:1:"i";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:4:"1022";}s:1:"j";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:4:"1022";}s:1:"k";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:4:"1022";}s:1:"l";a:2:{s:4:"docs";s:3:"511";s:4:"hits";s:4:"1022";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:18:""i j" NEAR/2 "k l"";}i:5;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:6:{i:528;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:531;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:526;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:527;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:529;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}i:530;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"6";s:11:"total_found";s:1:"6";s:4:"time";s:5:"0.034";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:6;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:6:{i:528;a:2:{s:6:"weight";s:1:"4";s:5:"attrs";a:0:{}}i:531;a:2:{s:6:"weight";s:1:"4";s:5:"attrs";a:0:{}}i:526;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:527;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:529;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:530;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"6";s:11:"total_found";s:1:"6";s:4:"time";s:5:"0.149";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:7;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:2:{i:528;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}i:531;a:2:{s:6:"weight";s:1:"2";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"2";s:11:"total_found";s:1:"2";s:4:"time";s:5:"0.122";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:8;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:2:{i:528;a:2:{s:6:"weight";s:4:"2661";s:5:"attrs";a:0:{}}i:531;a:2:{s:6:"weight";s:4:"2661";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"2";s:11:"total_found";s:1:"2";s:4:"time";s:5:"0.047";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:9;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:2:{i:528;a:2:{s:6:"weight";s:4:"2661";s:5:"attrs";a:0:{}}i:531;a:2:{s:6:"weight";s:4:"2661";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"2";s:11:"total_found";s:1:"2";s:4:"time";s:5:"0.024";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"6";s:4:"hits";s:1:"6";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}}}
+a:1:{i:0;a:18:{i:0;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:4:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"4";s:11:"total_found";s:1:"4";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:18:""a b" NEAR/2 "c d"";}i:1;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:4:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"4";s:11:"total_found";s:1:"4";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:18:""c d" NEAR/2 "a b"";}i:2;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:4:{i:1;a:2:{s:6:"weight";s:4:"3324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"3324";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:4:"2324";s:5:"attrs";a:0:{}}i:3;a:2:{s:6:"weight";s:4:"2324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"4";s:11:"total_found";s:1:"4";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:14:"a b NEAR/2 c d";}i:3;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:11:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:5;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:6;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:7;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:8;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:11;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:12;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:2:"11";s:11:"total_found";s:2:"11";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:28:"a NEAR/2 b NEAR/5 c NEAR/2 d";}i:4;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:7:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:3;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:5;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"7";s:11:"total_found";s:1:"7";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:28:"a NEAR/3 b NEAR/3 c NEAR/3 d";}i:5;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:4:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:12;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"4";s:11:"total_found";s:1:"4";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:28:"a NEAR/3 d NEAR/3 b NEAR/3 c";}i:6;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:7:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:3;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:5;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"7";s:11:"total_found";s:1:"7";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:16:"(a b c) NEAR/3 d";}i:7;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:1:{i:15;a:2:{s:6:"weight";s:4:"3834";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"1";s:11:"total_found";s:1:"1";s:4:"time";s:5:"0.001";s:5:"words";a:3:{s:6:"burden";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"2";}s:9:"financial";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}s:5:"share";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:31:"burden NEAR/2 (financial share)";}i:8;a:12:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:5:"total";s:1:"0";s:11:"total_found";s:1:"0";s:4:"time";s:5:"0.000";s:5:"words";a:3:{s:6:"burden";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"2";}s:5:"share";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}s:9:"financial";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:32:"burden NEAR/2 (share financial) ";}i:9;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:1:{i:15;a:2:{s:6:"weight";s:4:"3834";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"1";s:11:"total_found";s:1:"1";s:4:"time";s:5:"0.000";s:5:"words";a:3:{s:5:"share";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}s:9:"financial";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}s:6:"burden";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"2";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:31:"(share financial) NEAR/2 burden";}i:10;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:1:{i:15;a:2:{s:6:"weight";s:4:"3834";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"1";s:11:"total_found";s:1:"1";s:4:"time";s:5:"0.001";s:5:"words";a:3:{s:9:"financial";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}s:5:"share";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"3";}s:6:"burden";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"2";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:31:"(financial share) NEAR/2 burden";}i:11;a:12:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:5:"total";s:1:"0";s:11:"total_found";s:1:"0";s:4:"time";s:5:"0.001";s:5:"words";a:6:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"f";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}s:1:"g";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:31:""a b" NEAR/2 "c d" NEAR/2 "f g"";}i:12;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:7:{i:1;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:2;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:3;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:4;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:5;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:13;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}i:14;a:2:{s:6:"weight";s:4:"4324";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"7";s:11:"total_found";s:1:"7";s:4:"time";s:5:"0.001";s:5:"words";a:4:{s:1:"a";a:2:{s:4:"docs";s:2:"15";s:4:"hits";s:2:"15";}s:1:"b";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"c";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}s:1:"d";a:2:{s:4:"docs";s:2:"14";s:4:"hits";s:2:"14";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:28:"a NEAR/3 b NEAR/3 c NEAR/3 d";}i:13;a:12:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:5:"total";s:1:"0";s:11:"total_found";s:1:"0";s:4:"time";s:5:"0.001";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:14;a:13:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:7:"matches";a:1:{i:15;a:2:{s:6:"weight";s:1:"1";s:5:"attrs";a:0:{}}}s:5:"total";s:1:"1";s:11:"total_found";s:1:"1";s:4:"time";s:5:"0.001";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:15;a:12:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:5:"total";s:1:"0";s:11:"total_found";s:1:"0";s:4:"time";s:5:"0.000";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:16;a:12:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:5:"total";s:1:"0";s:11:"total_found";s:1:"0";s:4:"time";s:5:"0.000";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}i:17;a:12:{s:5:"error";s:0:"";s:7:"warning";s:0:"";s:6:"status";i:0;s:6:"fields";a:1:{i:0;s:5:"title";}s:5:"attrs";a:0:{}s:5:"total";s:1:"0";s:11:"total_found";s:1:"0";s:4:"time";s:5:"0.000";s:5:"words";a:2:{s:3:"are";a:2:{s:4:"docs";s:1:"1";s:4:"hits";s:1:"6";}s:4:"near";a:2:{s:4:"docs";s:1:"0";s:4:"hits";s:1:"0";}}s:8:"resarray";i:0;s:8:"roundoff";i:0;s:5:"query";s:10:""ARE NEAR"";}}}
\ No newline at end of file
Index: trunk/test/test_115/test.xml
===================================================================
--- trunk/test/test_115/test.xml	(revision 2426)
+++ trunk/test/test_115/test.xml	(revision 2427)
@@ -31,15 +31,19 @@
 </config>
 
 <queries>
-	<!-- expect 3 matches -->
-	<query index="idx" mode="extended2" ranker="wordcount" >"a b" NEAR/2 "c d"</query>
-	<query index="idx" mode="extended2" ranker="wordcount" >a b NEAR/2 c d</query>
-	<query index="idx" mode="extended2" ranker="wordcount" >a NEAR/2 b NEAR/2 c NEAR/2 d</query>
-	<!-- expect 511 matches, the first with the weithg=2 -->
-	<query index="idx" mode="extended2" ranker="wordcount" >"e f" NEAR/2 "g h"</query>
-	<!-- expect 511 matches, the first with the weithg=512 -->
-	<query index="idx" mode="extended2" ranker="wordcount" >"i j" NEAR/2 "k l"</query>
-	
+	<query index="idx" mode="extended2">"a b" NEAR/2 "c d"</query>
+	<query index="idx" mode="extended2">"c d" NEAR/2 "a b"</query>
+	<query index="idx" mode="extended2">a b NEAR/2 c d</query>
+	<query index="idx" mode="extended2">a NEAR/2 b NEAR/5 c NEAR/2 d</query>
+	<query index="idx" mode="extended2">a NEAR/3 b NEAR/3 c NEAR/3 d</query>
+	<query index="idx" mode="extended2">a NEAR/3 d NEAR/3 b NEAR/3 c</query>
+	<query index="idx" mode="extended2">(a b c) NEAR/3 d</query>
+	<query index="idx" mode="extended2">burden NEAR/2 (financial share)</query>
+	<query index="idx" mode="extended2">burden NEAR/2 (share financial) </query>
+	<query index="idx" mode="extended2">(share financial) NEAR/2 burden</query>
+	<query index="idx" mode="extended2">(financial share) NEAR/2 burden</query>
+	<query index="idx" mode="extended2">"a b" NEAR/2 "c d" NEAR/2 "f g"</query>
+	<query index="idx" mode="extended2">a NEAR/3 b NEAR/3 c NEAR/3 d</query>
 	<query index="idx" mode="all" >"ARE NEAR"</query>
 	<query index="idx" mode="any" >"ARE NEAR"</query>
 	<query index="idx" mode="phrase" >"ARE NEAR"</query>
@@ -54,37 +58,12 @@
 	title text NOT NULL
 );
 </db_create>
-
-<custom_insert><![CDATA[
-
-$line = "";
-for ( $i=0; $i<10; ++$i )
-{
-	mysql_query ( "INSERT INTO test_table VALUES ( 0, 'a b $line c d')" );
-	$line .="x ";
-}
-
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'a b c d')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'x a x b x c x d x')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'x x a x x b x x c x x d x x')" );
-
-for ( $i=0; $i<510; ++$i )
-	mysql_query ( "INSERT INTO test_table VALUES ( 0, 'e f x x g h y i j x x k l')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'e f x x g h y e f x x g h')" );
-
-$line = "";
-for ( $i=0; $i<512; ++$i )
-	$line .= " y i j x x k l";
-mysql_query ( "INSERT INTO test_table VALUES ( 0, '$line')" );
-
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'NEAR ARE STUFF')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'ARE STUFF NEAR')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'ARE NEAR STUFF')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, '\NEAR ARE STUFF')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'ARE STUFF \NEAR')" );
-mysql_query ( "INSERT INTO test_table VALUES ( 0, 'ARE \NEAR STUFF')" );
-
-]]></custom_insert>
+<db_insert>
+INSERT INTO `test_table` VALUES
+( 0, 'a b c d'), (0, 'a x b c d'), (0,'a x x b c d'), ( 0, 'a b x c d'), ( 0, 'a b x x c d'), ( 0, 'a b x x x c d'), ( 0, 'a b x x x x c d'), (0, 'a x b x x x x c x d'), (0, 'a x x b x x x c x x d'),
+( 0, 'c d x x x x a b'), ( 0, 'c d x x x a b'), ( 0, 'c d x x a b'), ( 0, 'c d x a b'), ( 0, 'c d a b'),
+( 0, '... is the clearinghouse associated with such exchange. In general, clearinghouses are backed by the corporate members of the clearinghouse who are required to share any financial burden resulting from the non-performance by one of their members and, as such, should significantly reduce this credit risk. In cases where the clearinghouse... is the clearinghouse associated with such exchange. In general, clearinghouses are backed by the corporate members of the clearinghouse who are required to share any financial burden resulting from the non-performance by one of their members and, as such, should significantly reduce this credit risk. In cases where the clearinghouse... be able to meet its obligations to a Trading Company. The counterparty for futures contracts traded in the United States and on most foreign exchanges is the clearinghouse associated with such exchange. In general, clearinghouses are backed by the corporate members of the clearinghouse who are required to share any financial...')
+</db_insert>
 <db_drop>DROP TABLE IF EXISTS test_table</db_drop>
 
 </test>
Index: trunk/src/sphinxsearch.cpp
===================================================================
--- trunk/src/sphinxsearch.cpp	(revision 2426)
+++ trunk/src/sphinxsearch.cpp	(revision 2427)
@@ -55,7 +55,8 @@
 	SphDocID_t	m_uDocid;
 	DWORD		m_uHitpos;
 	DWORD		m_uQuerypos;
-	DWORD		m_uSpanlen;
+	WORD		m_uSpanlen;
+	WORD		m_uMatchlen;
 	DWORD		m_uWeight;
 };
 
@@ -412,8 +413,9 @@
 		return pLeft && pRight															///< both members exist
 			&& pLeft->m_uDocid!=DOCID_MAX && pRight->m_uDocid!=DOCID_MAX				///< both members are valid
 			&& pLeft->m_uDocid==pRight->m_uDocid										///< both are about the same doc
-			&& pLeft->m_uHitpos<pRight->m_uHitpos										///< left is before the right
-			&& ( pLeft->m_uHitpos + pLeft->m_uSpanlen + m_iMaxDistance )>=pRight->m_uHitpos;	///< the right is NEAR the left
+			/// and the main NEAR condition-filter
+			&& ( ( ( HIT2LCS ( pLeft->m_uHitpos )<HIT2LCS ( pRight->m_uHitpos ) ) && ( HIT2LCS ( pLeft->m_uHitpos ) + pLeft->m_uMatchlen + m_iMaxDistance>HIT2LCS ( pRight->m_uHitpos ) ) )
+				| ( ( HIT2LCS ( pLeft->m_uHitpos )>=HIT2LCS ( pRight->m_uHitpos ) ) && ( HIT2LCS ( pRight->m_uHitpos ) + pRight->m_uMatchlen + m_iMaxDistance>HIT2LCS ( pLeft->m_uHitpos ) ) ) );
 	}
 
 private:
@@ -1102,7 +1104,7 @@
 		tHit.m_uDocid = pDoc->m_uDocid;
 		tHit.m_uHitpos = uHit;
 		tHit.m_uQuerypos = m_iAtomPos;
-		tHit.m_uSpanlen = tHit.m_uWeight = 1;
+		tHit.m_uMatchlen = tHit.m_uSpanlen = tHit.m_uWeight = 1;
 	}
 
 	m_pHitDoc = pDoc;
@@ -1198,7 +1200,7 @@
 				tHit.m_uDocid = pDoc->m_uDocid;
 				tHit.m_uHitpos = HIT_PACK ( m_uFieldPos, -1 );
 				tHit.m_uQuerypos = m_iAtomPos;
-				tHit.m_uSpanlen = tHit.m_uWeight = 1;
+				tHit.m_uMatchlen = tHit.m_uSpanlen = tHit.m_uWeight = 1;
 
 				if ( iHit==MAX_HITS-1 )
 					break;
@@ -1776,11 +1778,14 @@
 					eState = ST_DOCFINISHED;
 					break;
 				}
-				DWORD uSpanlen = pHitRight->m_uSpanlen + pHitRight->m_uHitpos - pHitLeft->m_uHitpos;
+				int iDistance = HIT2LCS ( pHitRight->m_uHitpos ) - HIT2LCS ( pHitLeft->m_uHitpos );
+				const ExtHit_t *&pL = (iDistance>0)?pHitLeft:pHitRight;
+				const ExtHit_t *&pR = (iDistance>0)?pHitRight:pHitLeft;
+				iDistance = (iDistance>0)?iDistance:-iDistance;
 				m_dMyHits[iHit].m_uDocid = uCurDocID;
-				m_dMyHits[iHit].m_uHitpos = pHitLeft->m_uHitpos;
-				m_dMyHits[iHit].m_uQuerypos = pHitLeft->m_uQuerypos;
-				m_dMyHits[iHit].m_uSpanlen = uSpanlen;
+				m_dMyHits[iHit].m_uHitpos = pL->m_uHitpos;
+				m_dMyHits[iHit].m_uQuerypos = pL->m_uQuerypos;
+				m_dMyHits[iHit].m_uMatchlen = iDistance + pR->m_uMatchlen;
 				m_dMyHits[iHit++].m_uWeight = pHitLeft->m_uWeight + pHitRight->m_uWeight;
 				if ( iHit==MAX_HITS-1 )
 				{
@@ -1964,11 +1969,14 @@
 			}
 			if ( IsAppropriateHit ( pHitLeft, pHitRight ) )
 			{
-				DWORD uSpanlen = pHitRight->m_uSpanlen + pHitRight->m_uHitpos - pHitLeft->m_uHitpos;
+				int iDistance = HIT2LCS ( pHitRight->m_uHitpos ) - HIT2LCS ( pHitLeft->m_uHitpos );
+				const ExtHit_t *&pL = (iDistance>0)?pHitLeft:pHitRight;
+				const ExtHit_t *&pR = (iDistance>0)?pHitRight:pHitLeft;
+				iDistance = (iDistance>0)?iDistance:-iDistance;
 				m_dHits[iHit].m_uDocid = uMatchedDocid;
-				m_dHits[iHit].m_uHitpos = pHitLeft->m_uHitpos;
-				m_dHits[iHit].m_uQuerypos = pHitLeft->m_uQuerypos;
-				m_dHits[iHit].m_uSpanlen = uSpanlen;
+				m_dHits[iHit].m_uHitpos = pL->m_uHitpos;
+				m_dHits[iHit].m_uQuerypos = pL->m_uQuerypos;
+				m_dHits[iHit].m_uMatchlen = iDistance + pR->m_uMatchlen;
 				m_dHits[iHit++].m_uWeight = pHitLeft->m_uWeight + pHitRight->m_uWeight;
 				if ( iHit==MAX_HITS-1 )
 				{
@@ -2465,7 +2473,7 @@
 				m_dMyHits[iMyHit].m_uDocid = pHit->m_uDocid;
 				m_dMyHits[iMyHit].m_uHitpos = HIT2LCS ( pHit->m_uHitpos ) - uSpanlen;
 				m_dMyHits[iMyHit].m_uQuerypos = m_uMinQpos;
-				m_dMyHits[iMyHit].m_uSpanlen = uSpanlen + 1;
+				m_dMyHits[iMyHit].m_uSpanlen = m_dMyHits[iMyHit].m_uMatchlen = uSpanlen + 1; ///< since it is exact phrase, the hitlen will be same as queried spanlen.
 				m_dMyHits[iMyHit].m_uWeight = m_uWords;
 				iMyHit++;
 
@@ -2687,7 +2695,7 @@
 				m_dHits[iHit].m_uDocid = pHit->m_uDocid;
 				m_dHits[iHit].m_uHitpos = HIT2LCS ( pHit->m_uHitpos ) - uSpanlen;
 				m_dHits[iHit].m_uQuerypos = m_uMinQpos;
-				m_dHits[iHit].m_uSpanlen = uSpanlen + 1;
+				m_dHits[iHit].m_uSpanlen = m_dHits[iHit].m_uMatchlen = uSpanlen + 1;
 				m_dHits[iHit++].m_uWeight = m_uWords;
 				m_uExpPos = m_uExpQpos = 0;
 
@@ -2895,7 +2903,7 @@
 			m_dMyHits[iHit].m_uDocid = pHit->m_uDocid;
 			m_dMyHits[iHit].m_uHitpos = dProx[iProxMinEntry];
 			m_dMyHits[iHit].m_uQuerypos = m_uMinQpos;
-			m_dMyHits[iHit].m_uSpanlen = uMax-dProx[iProxMinEntry]+1;
+			m_dMyHits[iHit].m_uSpanlen = m_dMyHits[iHit].m_uMatchlen = uMax-dProx[iProxMinEntry]+1;
 			m_dMyHits[iHit].m_uWeight = uWeight;
 			iHit++;
 
@@ -3055,7 +3063,7 @@
 			m_dHits[iHit].m_uDocid = pHit->m_uDocid;
 			m_dHits[iHit].m_uHitpos = dProx[iProxMinEntry];
 			m_dHits[iHit].m_uQuerypos = m_uMinQpos;
-			m_dHits[iHit].m_uSpanlen = uMax-dProx[iProxMinEntry]+1;
+			m_dHits[iHit].m_uSpanlen = m_dHits[iHit].m_uMatchlen = uMax-dProx[iProxMinEntry]+1;
 			m_dHits[iHit].m_uWeight = uWeight;
 			iHit++;
 
Index: trunk/src/sphinxquery.cpp
===================================================================
--- trunk/src/sphinxquery.cpp	(revision 2426)
+++ trunk/src/sphinxquery.cpp	(revision 2427)
@@ -47,7 +47,7 @@
 	void			AddQuery ( XQNode_t * pNode );
 	XQNode_t *		AddKeyword ( const char * sKeyword, DWORD uStar = STAR_NONE );
 	XQNode_t *		AddKeyword ( XQNode_t * pLeft, XQNode_t * pRight );
-	XQNode_t *		AddOp ( XQOperator_e eOp, XQNode_t * pLeft, XQNode_t * pRight );
+	XQNode_t *		AddOp ( XQOperator_e eOp, XQNode_t * pLeft, XQNode_t * pRight, int iOpArg=0 );
 
 	void			Cleanup ();
 	XQNode_t *		SweepNulls ( XQNode_t * pNode );
@@ -632,7 +632,7 @@
 }
 
 
-XQNode_t * XQParser_t::AddOp ( XQOperator_e eOp, XQNode_t * pLeft, XQNode_t * pRight )
+XQNode_t * XQParser_t::AddOp ( XQOperator_e eOp, XQNode_t * pLeft, XQNode_t * pRight, int iOpArg )
 {
 	/////////
 	// unary
@@ -660,7 +660,7 @@
 
 	// build a new node
 	XQNode_t * pResult = NULL;
-	if ( pLeft->m_dChildren.GetLength() && pLeft->GetOp()==eOp )
+	if ( pLeft->m_dChildren.GetLength() && pLeft->GetOp()==eOp && pLeft->m_iOpArg==iOpArg )
 	{
 		pLeft->m_dChildren.Add ( pRight );
 		pResult = pLeft;
@@ -668,6 +668,7 @@
 	{
 		XQNode_t * pNode = new XQNode_t();
 		pNode->SetOp ( eOp, pLeft, pRight );
+		pNode->m_iOpArg = iOpArg;
 		m_dSpawned.Add ( pNode );
 		pResult = pNode;
 	}
Index: trunk/src/sphinxquery.h
===================================================================
--- trunk/src/sphinxquery.h	(revision 2426)
+++ trunk/src/sphinxquery.h	(revision 2427)
@@ -107,6 +107,7 @@
 		, m_bFieldSpec ( false )
 		, m_uFieldMask ( 0xFFFFFFFFUL )
 		, m_iFieldMaxPos ( 0 )
+		, m_iOpArg ( 0 )
 		, m_iAtomPos ( -1 )
 		, m_bVirtuallyPlain ( false )
 	{}
Index: trunk/src/sphinx.cpp
===================================================================
--- trunk/src/sphinx.cpp	(revision 2426)
+++ trunk/src/sphinx.cpp	(revision 2427)
@@ -13158,6 +13158,59 @@
 	pNode->SetOp ( SPH_QUERY_OR, dArgs );
 }
 
+// transform the (A B) NEAR C into A NEAR B NEAR C
+static void TransformNear ( XQNode_t ** ppNode )
+{
+	XQNode_t *& pNode = *ppNode;
+	if ( pNode->GetOp()==SPH_QUERY_NEAR )
+	{
+		assert ( pNode->m_dWords.GetLength()==0 );
+		CSphVector<XQNode_t*> dArgs;
+		int iStartFrom = 0;
+
+		// transform all (A B C) NEAR D into A NEAR B NEAR C NEAR D
+		do
+		{
+			dArgs.Reset();
+			iStartFrom = 0;
+			ARRAY_FOREACH ( i, pNode->m_dChildren )
+			{
+				XQNode_t * pChild = pNode->m_dChildren[i]; ///< shortcut
+				if ( pChild->GetOp()==SPH_QUERY_AND && pChild->m_dChildren.GetLength()>0 )
+				{
+					ARRAY_FOREACH ( j, pChild->m_dChildren )
+						if ( j==0 && iStartFrom==0 )
+						{
+							// we will remove the node anyway, so just replace it with 1-st child instead
+							pNode->m_dChildren[i] = pChild->m_dChildren[j];
+							iStartFrom = i+1;
+						} else
+							dArgs.Add ( pChild->m_dChildren[j] );
+					pChild->m_dChildren.Reset();
+					SafeDelete ( pChild );
+				} else if ( iStartFrom!=0 )
+					dArgs.Add ( pChild );
+			}
+
+			if ( iStartFrom!=0 )
+			{
+				pNode->m_dChildren.Resize ( iStartFrom + dArgs.GetLength() );
+				ARRAY_FOREACH ( i, dArgs )
+					pNode->m_dChildren [ i + iStartFrom ] = dArgs[i];
+			}
+		} while ( iStartFrom!=0 );
+	}
+
+	ARRAY_FOREACH ( i, pNode->m_dChildren )
+		TransformNear ( &pNode->m_dChildren[i] );
+}
+
+inline static void Transform ( XQNode_t ** ppNode )
+{
+	TransformQuorum ( ppNode );
+	TransformNear ( ppNode );
+}
+
 struct CmpPSortersByRandom_fn
 {
 	inline bool IsLess ( const ISphMatchSorter * a, const ISphMatchSorter * b ) const
@@ -13217,7 +13270,7 @@
 	sphDoStatsOrder ( tParsed.m_pRoot, *pResult );
 
 	// transform query if needed (quorum transform, keyword expansion, etc.)
-	TransformQuorum ( &tParsed.m_pRoot );
+	Transform ( &tParsed.m_pRoot );
 	if ( m_bExpandKeywords )
 		tParsed.m_pRoot = ExpandKeywords ( tParsed.m_pRoot, m_tSettings );
 
@@ -13292,7 +13345,7 @@
 			sphDoStatsOrder ( tParsed.m_pRoot, *ppResults[i] );
 
 			// transform query if needed (quorum transform, keyword expansion, etc.)
-			TransformQuorum ( &tParsed.m_pRoot );
+			Transform ( &tParsed.m_pRoot );
 			if ( m_bExpandKeywords )
 				tParsed.m_pRoot = ExpandKeywords ( tParsed.m_pRoot, m_tSettings );
 
Index: trunk/src/yysphinxquery.c
===================================================================
--- trunk/src/yysphinxquery.c	(revision 2426)
+++ trunk/src/yysphinxquery.c	(revision 2427)
@@ -1191,7 +1191,7 @@
 
   case 35:
 
-    { yyval.pNode = pParser->AddOp ( SPH_QUERY_NEAR, yyvsp[-2].pNode, yyvsp[0].pNode ); yyval.pNode->m_iOpArg = yyvsp[-1].tInt.iValue; ;}
+    { yyval.pNode = pParser->AddOp ( SPH_QUERY_NEAR, yyvsp[-2].pNode, yyvsp[0].pNode, yyvsp[-1].tInt.iValue ); ;}
     break;
 
   case 36:
Index: trunk/src/sphinxquery.y
===================================================================
--- trunk/src/sphinxquery.y	(revision 2426)
+++ trunk/src/sphinxquery.y	(revision 2427)
@@ -105,7 +105,7 @@
 beforelist:
 	orlistf
 	| beforelist TOK_BEFORE orlistf		{ $$ = pParser->AddOp ( SPH_QUERY_BEFORE, $1, $3 ); }
-	| beforelist TOK_NEAR orlistf		{ $$ = pParser->AddOp ( SPH_QUERY_NEAR, $1, $3 ); $$->m_iOpArg = $2.iValue; }
+	| beforelist TOK_NEAR orlistf		{ $$ = pParser->AddOp ( SPH_QUERY_NEAR, $1, $3, $2.iValue ); }
 	;
 
 expr:
