Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
380 changes: 297 additions & 83 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ compile_commands.json
libsimple.*
build/
build-ios/
build-ios-*/
build-ohos/
output-ios*/
*.gch
bin/
output/
Expand All @@ -20,4 +23,4 @@ examples/go/libsimple-osx-x64/
cmake-build-debug/


.vscode/
.vscode/
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ if(BUILD_SQLITE3)
set(SQLITE_INSTALL_DIR ${SQLITE_ROOT})
set(SQLITE_INCLUDE_DIR ${SQLITE_INSTALL_DIR}/include)
set(SQLITE_LIB_DIR ${SQLITE_INSTALL_DIR}/lib)
if (NOT IOS)
option(SQLITE_ENABLE_FTS5 "enables full text searches version 5" ON)
if (MSVC OR (UNIX AND NOT IOS))
option(SQLITE_ENABLE_FTS5 "enables full text searches version 5" ON)
option(BUILD_SHELL "build SQLite3 shell application" ON)
add_subdirectory(contrib/sqlite3)
endif()
Expand Down
138 changes: 132 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 8,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"minor": 28,
"patch": 0
},
"configurePresets": [
Expand Down Expand Up @@ -65,32 +65,106 @@
"CMAKE_INSTALL_PREFIX": {
"type": "PATH",
"value": "${sourceDir}/../../_temp/macos/install"
},
"BUILD_SHELL": {
"type": "BOOL",
"value": "OFF"
}
}
},
{
"name": "windows-msvc-vs17",
"displayName": "Visual Studio 17 2022",
"description": "Configure with VS17 and vcpkg toolchain",
"name": "macos-ninja-x64",
"displayName": "macOS Ninja (x64)",
"description": "Configure for macOS x64 build",
"inherits": "macos-ninja",
"binaryDir": "${sourceDir}/../../_temp/macos-x64",
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "x86_64",
"CMAKE_INSTALL_PREFIX": {
"type": "PATH",
"value": "${sourceDir}/../../_temp/macos-x64/install"
}
}
},
{
"name": "macos-ninja-arm64",
"displayName": "macOS Ninja (arm64)",
"description": "Configure for macOS arm64 build",
"inherits": "macos-ninja",
"binaryDir": "${sourceDir}/../../_temp/macos-arm64",
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "arm64",
"CMAKE_INSTALL_PREFIX": {
"type": "PATH",
"value": "${sourceDir}/../../_temp/macos-arm64/install"
}
}
},
{
"name": "windows-msvc-vs17-base",
"hidden": true,
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"toolset": "v143",
"binaryDir": "${sourceDir}/../../_temp/windows",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
},
"BUILD_SHELL": {
"type": "BOOL",
"value": "OFF"
},
"BUILD_TESTING": {
"type": "BOOL",
"value": "OFF"
},
"BUILD_SQLITE3": {
"type": "BOOL",
"value": "ON"
},
"SQLITE_ENABLE_FTS5": {
"type": "BOOL",
"value": "ON"
}
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "windows-msvc-vs17",
"displayName": "Visual Studio 17 2022 (x64)",
"description": "Configure with VS17 and vcpkg toolchain (x64)",
"inherits": "windows-msvc-vs17-base",
"architecture": "x64",
"binaryDir": "${sourceDir}/../../_temp/windows-x64",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
},
{
"name": "windows-msvc-vs17-x86",
"displayName": "Visual Studio 17 2022 (Win32)",
"description": "Configure with VS17 and vcpkg toolchain (Win32)",
"inherits": "windows-msvc-vs17-base",
"architecture": "Win32",
"binaryDir": "${sourceDir}/../../_temp/windows-x86",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x86-windows"
}
},
{
"name": "windows-msvc-vs17-arm64",
"displayName": "Visual Studio 17 2022 (ARM64)",
"description": "Configure with VS17 and vcpkg toolchain (ARM64)",
"inherits": "windows-msvc-vs17-base",
"architecture": "ARM64",
"binaryDir": "${sourceDir}/../../_temp/windows-arm64",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "arm64-windows"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -120,6 +194,32 @@
"description": "Build for macOS (Release)",
"configuration": "Release"
},
{
"name": "macos-ninja-x64",
"configurePreset": "macos-ninja-x64",
"displayName": "Build macOS x64",
"description": "Build for macOS x64"
},
{
"name": "macos-ninja-x64-release",
"configurePreset": "macos-ninja-x64",
"displayName": "Build macOS x64 (Release)",
"description": "Build for macOS x64 (Release)",
"configuration": "Release"
},
{
"name": "macos-ninja-arm64",
"configurePreset": "macos-ninja-arm64",
"displayName": "Build macOS arm64",
"description": "Build for macOS arm64"
},
{
"name": "macos-ninja-arm64-release",
"configurePreset": "macos-ninja-arm64",
"displayName": "Build macOS arm64 (Release)",
"description": "Build for macOS arm64 (Release)",
"configuration": "Release"
},
{
"name": "windows-msvc-vs17",
"configurePreset": "windows-msvc-vs17",
Expand All @@ -132,6 +232,32 @@
"displayName": "Build Windows VS17 (Release)",
"description": "Build with VS17 (Release)",
"configuration": "Release"
},
{
"name": "windows-msvc-vs17-x86",
"configurePreset": "windows-msvc-vs17-x86",
"displayName": "Build Windows VS17 (Win32)",
"description": "Build with VS17 (Win32)"
},
{
"name": "windows-msvc-vs17-x86-release",
"configurePreset": "windows-msvc-vs17-x86",
"displayName": "Build Windows VS17 (Win32, Release)",
"description": "Build with VS17 (Win32, Release)",
"configuration": "Release"
},
{
"name": "windows-msvc-vs17-arm64",
"configurePreset": "windows-msvc-vs17-arm64",
"displayName": "Build Windows VS17 (ARM64)",
"description": "Build with VS17 (ARM64)"
},
{
"name": "windows-msvc-vs17-arm64-release",
"configurePreset": "windows-msvc-vs17-arm64",
"displayName": "Build Windows VS17 (ARM64, Release)",
"description": "Build with VS17 (ARM64, Release)",
"configuration": "Release"
}
]
}
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Downloads](https://img.shields.io/github/downloads/wangfenjin/simple/total)](https://img.shields.io/github/downloads/wangfenjin/simple/total)
[![build](https://github.com/wangfenjin/simple/workflows/CI/badge.svg)](https://github.com/wangfenjin/simple/actions?query=workflow%3ACI)
[![build](https://github.com/wangfenjin/simple/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/wangfenjin/simple/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/wangfenjin/simple/branch/master/graph/badge.svg?token=8SHLFZ3RB4)](https://codecov.io/gh/wangfenjin/simple)
[![CodeFactor](https://www.codefactor.io/repository/github/wangfenjin/simple/badge)](https://www.codefactor.io/repository/github/wangfenjin/simple)
[![License: MIT](https://img.shields.io/badge/Dual_License-MIT_or_GPL_v3_later-blue.svg)](https://github.com/wangfenjin/simple/blob/master/LICENSE)
Expand All @@ -26,6 +26,7 @@ simple 是一个支持中文和拼音的 [sqlite3 fts5](https://www.sqlite.org/f
* C# 例子 https://github.com/dudylan/SqliteCheck/
* Rust 例子 https://github.com/xuxiaocheng0201/libsimple/
* Android Flutter 的例子 https://github.com/SageMik/sqlite3_simple
* React Native op-sqlite 例子 [examples/react-native-op-sqlite.md](./examples/react-native-op-sqlite.md)

### 命令行使用

Expand Down Expand Up @@ -63,6 +64,26 @@ sqlite> select simple_highlight(t1, 0, '[', ']') as text from t1 where text matc
5. simple_snippet() 实现截取 match 片段的功能,与 sqlite 自带的 snippet 功能类似,同样是增强连续 match 的词汇分到同一组的逻辑
6. jieba_query() 实现jieba分词的效果,在索引不变的情况下,可以实现更精准的匹配。可以通过 `-DSIMPLE_WITH_JIEBA=OFF ` 关掉结巴分词的功能 [#35](https://github.com/wangfenjin/simple/pull/35)
7. jieba_dict() 指定 dict 的目录,只需要调用一次,需要在调用 jieba_query() 之前指定。
8. pinyin_dict() 支持指定自定义的 `pinyin.txt` 文件路径。调用成功后会立即切换拼音映射;如果文件格式不正确,会返回错误并保持当前映射不变。

### 自定义 pinyin.txt

默认会使用内置在 so 中的 `contrib/pinyin.txt`。如果希望使用自己的拼音表,可以在查询前调用:

```sql
select pinyin_dict('/path/to/pinyin.txt');
```

`pinyin.txt` 每行格式与默认文件一致,例如:

```text
U+3007: líng,yuán,xīng
U+3007: líng,yuán,xīng # 行尾注释也支持(前面需要空格)
```

注意:
- 建议在建索引和查询前先调用一次 `pinyin_dict()`。
- 如果替换了拼音映射,已有索引中的拼音 token 不会自动重建,需要按你的业务策略重建索引。

## 开发

Expand All @@ -83,6 +104,19 @@ make install
./build-ios.sh
```

支持 ohos 编译:

从 [官方发布渠道](https://gitcode.com/openharmony/docs/blob/master/en/release-notes/OpenHarmony-v5.0.1-release.md#acquiring-source-code-from-mirrors)下载适用于目标平台的SDK.
```
tar -zxvf ohos-sdk.tar.gz
cd $OHOS_SDK/Linux
for i in *.zip;do unzip ${i};done
```
开始编译
```
./build-ohos.sh
```

### 代码
- `src/entry` 入口文件,注册 sqlite tokenizer 和函数
- `src/simple_tokenizer` 分词器实现
Expand All @@ -99,5 +133,4 @@ make install

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=wangfenjin/simple&type=Date)](https://star-history.com/#wangfenjin/simple&Date)

[![Star History Chart](https://api.star-history.com/svg?repos=wangfenjin/simple&type=Date)](https://www.star-history.com/#wangfenjin/simple&Date)
4 changes: 2 additions & 2 deletions build-and-run
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ simple.example() {
run "cd output/bin/"
run "cat ${ProjectRoot}/example.sql ${ProjectRoot}/example-jieba.sql | ./sqlite3"
run "./simple_cpp_example"
run "cd ${ProjectRoot}"
run "python3 examples/python3/db_connector.py './output/bin/libsimple'"
# run "cd ${ProjectRoot}"
# run "python3 examples/python3/db_connector.py './output/bin/libsimple'"
}

main() {
Expand Down
4 changes: 2 additions & 2 deletions build-and-run-no-jieba
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ simple.example() {
run "cd output-no-jieba/bin/"
run "./sqlite3 < ${ProjectRoot}/example.sql"
run "./simple_cpp_example"
run "cd ${ProjectRoot}"
run "python3 examples/python3/db_connector.py"
# run "cd ${ProjectRoot}"
# run "python3 examples/python3/db_connector.py"
}

main() {
Expand Down
50 changes: 50 additions & 0 deletions build-ios-dynamic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

set -eu

script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
toolchain_file="${script_dir}/contrib/ios.toolchain.cmake"
ios_output_root="${script_dir}/output-ios-dynamic"
final_output_root="${script_dir}/output"

build_variant() {
platform="$1"
build_dir="${script_dir}/build-ios-dynamic-${platform}"
install_dir="${ios_output_root}/${platform}"

cmake -S "${script_dir}" -B "${build_dir}" -G Xcode \
-DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \
-DPLATFORM="${platform}" \
-DENABLE_BITCODE=0 \
-DDEPLOYMENT_TARGET=12.0 \
-DBUILD_SQLITE3=OFF \
-DBUILD_IOS_DYNAMIC_FRAMEWORK=ON \
-DCMAKE_INSTALL_PREFIX=""

cmake --build "${build_dir}" --config Release
cmake --install "${build_dir}" --config Release --prefix "${install_dir}"
}

rm -rf "${ios_output_root}" "${final_output_root}/libsimple-dynamic.xcframework"
mkdir -p "${final_output_root}"

build_variant OS64
build_variant SIMULATOR64
build_variant SIMULATORARM64

sim64_framework="${ios_output_root}/SIMULATOR64/bin/simple.framework"
simarm64_framework="${ios_output_root}/SIMULATORARM64/bin/simple.framework"
sim_universal_dir="${ios_output_root}/SIMULATOR_UNIVERSAL/bin"
sim_universal_framework="${sim_universal_dir}/simple.framework"

mkdir -p "${sim_universal_dir}"
cp -R "${sim64_framework}" "${sim_universal_framework}"
lipo -create \
"${sim64_framework}/simple" \
"${simarm64_framework}/simple" \
-output "${sim_universal_framework}/simple"

xcodebuild -create-xcframework \
-framework "${ios_output_root}/OS64/bin/simple.framework" \
-framework "${sim_universal_framework}" \
-output "${final_output_root}/libsimple-dynamic.xcframework"
Loading