修复php版文档错误

This commit is contained in:
lei.tian 2022-06-30 19:47:51 +08:00
parent 05a2b1d65e
commit 8da391f54f
2 changed files with 8 additions and 6 deletions

View File

@ -31,7 +31,7 @@ printf("{region: %s, took: %.5f ms}\n", $region, XdbSearcher::now() - $sTime);
如果你的 php 母环境支持,可以预先加载 vectorIndex 缓存,然后做成全局变量,每次创建 Searcher 的时候使用全局的 vectorIndex可以减少一次固定的 IO 操作从而加速查询,减少 io 压力。 如果你的 php 母环境支持,可以预先加载 vectorIndex 缓存,然后做成全局变量,每次创建 Searcher 的时候使用全局的 vectorIndex可以减少一次固定的 IO 操作从而加速查询,减少 io 压力。
```php ```php
// 1、从 dbPath 加载 VectorIndex 缓存,把下述的 vIndex 变量缓存到内存里面。 // 1、从 dbPath 加载 VectorIndex 缓存,把下述的 vIndex 变量缓存到内存里面。
$vIndex = XdbSearcher::loadVectorFromFile($dbPath); $vIndex = XdbSearcher::loadVectorIndexFromFile($dbPath);
if ($vIndex === null) { if ($vIndex === null) {
printf("failed to load vector index from '%s'\n", $dbPath); printf("failed to load vector index from '%s'\n", $dbPath);
return; return;
@ -60,7 +60,7 @@ printf("{region: %s, took: %.5f ms}\n", $region, XdbSearcher::now() - $sTime);
### 缓存整个 `xdb` 数据 ### 缓存整个 `xdb` 数据
如果你的 PHP 环境支持,可以预先加载整个 `xdb` 的数据到内存,这样可以实现完全基于内存的查询,类似之前的 memory search 查询。 如果你的 PHP 环境支持,可以预先加载整个 `xdb` 的数据到内存,这样可以实现完全基于内存的查询,类似之前的 memory search 查询。
```php ```php
// 1、从 dbPath 加载整个 xdb 到内存。 // 1、从 dbPath 加载整个 xdb 到内存。
$cBuff = XdbSearcher::loadContentFromFile($dbPath); $cBuff = XdbSearcher::loadContentFromFile($dbPath);

View File

@ -8,8 +8,10 @@
require dirname(__FILE__) . '/XdbSearcher.class.php'; require dirname(__FILE__) . '/XdbSearcher.class.php';
const XDB_PATH = '../../data/ip2region.xdb';
function testLoadHeader() { function testLoadHeader() {
$header = XdbSearcher::loadHeaderFromFile('../../data/ip2region.xdb'); $header = XdbSearcher::loadHeaderFromFile(XDB_PATH);
if ($header == null) { if ($header == null) {
printf("failed to load header from file\n"); printf("failed to load header from file\n");
return; return;
@ -20,17 +22,17 @@ function testLoadHeader() {
} }
function testLoadVectorIndex() { function testLoadVectorIndex() {
$vIndex = XdbSearcher::loadVectorIndexFromFile('../../data/ip2region.xdb'); $vIndex = XdbSearcher::loadVectorIndexFromFile(XDB_PATH);
if ($vIndex == null) { if ($vIndex == null) {
printf("failed to load vector index from file\n"); printf("failed to load vector index from file\n");
return; return;
} }
printf("vector index loaded: length=%d\n", strlen($vIndex)); printf("vector index loaded, length=%d\n", strlen($vIndex));
} }
function testLoadContent() { function testLoadContent() {
$cBuff = XdbSearcher::loadContentFromFile('../../data/ip2region.xdb'); $cBuff = XdbSearcher::loadContentFromFile(XDB_PATH);
if ($cBuff == null) { if ($cBuff == null) {
printf("failed to load content from file\n"); printf("failed to load content from file\n");
return; return;