Skip to main content

For nudb

Project description

NUDB

A Python module for NUDB.
NUDB is a fast database and search engine.

Menu:

Install

$ pip install nudb

Usage

資料格式

  • GAIS record

    • @ 開頭, : 結尾作為欄位名稱

    • : 之後為欄位內容

    • For example:

      // "@title:" 為欄位名稱
      @title:Mayday五月天 [ 頑固Tough ] Official Music Video
      
  • JSON

Connect to NUDB

from nudb import Nudb

nudb = Nudb()
nudb.connect('host', 'port', 'db')

參數說明

  • host: DB host
  • port: DB port
  • db: 指定 DB 名稱

Get DB info

result = nudb.get_DB_info(timeout=10)

參數說明

  • timeout: 設定 timeout,單位為 s,預設是 10s.

Search

options = {
    'db': 'test',
    'matchmode': 'BestMatch',
    'groupby': '@title:',
    'getrec': 'y',
    'orderby': 'score',
    'order': 'decreasing',
    'minrid': 100,
    'maxrid': 10000,
    'ridrange': 10000,
    'minscore': 100,
    'maxscore': 5000,
    'q': '旅遊',
    'filter': '@viewcount:>1000',
    'Sensitivity': 'sensitive',
    'p': 1,
    'ps': 10,
    'select': '@title:,@body:,@viewcount:',
    'out': 'json'
}
result = nudb.search(options, timeout=10);

參數說明

  • timeout: 設定 timeout,單位為 s,預設是 10 s.
  • options: query options
    • db: 指定DB

    • matchmode

      • AndMatch (預設)
      • OrMatch
      • BestMatch
    • groupby: 指定欄位群組, 預設只有輸出key, count, 欄位格式為GAIS record

    • getrec=y: 搭配groupby使用, 輸出全部資料

    • orderby

      • rid: 依照rid排序

      • score: 必須有參數q 才有score

      • groupsize: 搭配groupby

      • {FieldName}: 依照欄位(FieldName)排序

        • 在建立DB時, 數值欄位須設定 -numfieldindex
        • 在建立DB時, 時間欄位須設定 -timeindex
        {
          'orderby': '@viewcount:'
        }
        
      • [min|max|ave|sum]{FieldName}: 找出欄位(FieldName)的最小/最大/平均/總和值

        {
          'orderby': 'sum@viewcount:' 
        }
        
      • order: 搭配orderby使用, 預設為decreasing

        • decreasing: 遞減
        • increasing: 遞增
      • minrid: 設定rid最小值

      • maxrid: 設定rid最大值

      • ridrange: 設定搜尋的rid範圍, rid由大至小, 僅搜尋此範圍內的資料

      • minscore: score最小值

      • maxscore: score最大值

      • q: 搜尋關鍵字

        • 可指定欄位搜尋, 欄位格式為GAIS record:
        {
          'q': '@title:日本旅遊'
        }
        
      • 可指定欄位值須完全符合:

        {
          'q': '@id:=abcd1234'
        }
        
      • 可設定所有條件須符合(AndMatch):

        {
          'q': '+@id:1234,+@name:test'
        }
        
        • 可搜尋多個欄位, 以","區隔:
        {
          'q': "@title:日本旅遊,@body:東京"
        }
        
    • time: 可設定搜尋時間範圍

      • 在建立DB時, 時間欄位須設定 -timeindex

      • 限定時間區間

        {
          'time': '=20180101-20180301'
        }
        
      • 特定時間以後

        {
          'time': '=>20180220122000'  # YYYYMMDDHHmmss
        }
        
      • 特定時間以前

        {
          'time': '=<20180220122000'  # YYYYMMDDHHmmss
        }
        
      • 限定某天

        {
          'time': '=20180220'
        }
        
    • filter: 數值條件檢索, 沒有做數值欄位索引(-numfieldindex)也可查詢

      {
        'filter': '@price:<200'
      }
      
      {
        'filter': '@price:200-400'  # 數值區間
      }
      
    • maxcandidnum

    • Sensitivity

      • sensitive: 預設, 區分大小寫
      • insensitive: 不分大小寫
    • keytermfield

    • keytermstat

    • p: page, 指定輸出page, 預設為1

    • ps: page size, 每個page大小, 預設為10

    • select: 指定輸出欄位, 欄位格式為GAIS record, 多個欄位之間以","區隔

    • L: 指定回傳起始比數及總筆數

      {
        'L': 30       # 回傳30筆
      }
      
      {
        'L': '11,60'  # 從第11筆開始, 輸出60筆
      }
      
    • out: 輸出格式 (json or text)

Get record by rid or key

result = nudb.rget(data_id, search_field='rid', timeout=10)

參數說明

  • data_id: Record ID or primary key.
  • search_field: 搜尋的欄位,rid 或 key, 預設是 rid.
  • timeout: 設定 timeout,單位為 s,預設是 10s.

Put record

# format: json or text
result = nudb.rput(data, data_type, rec_beg=None, timeout=10)

參數說明

  • data: 資料
  • data_type: 資料格式(json or text)
  • rec_beg: record begin pattern, 若資料格式為text則必須有此參數
  • timeout: 設定 timeout,單位為 s,預設是 10s.

Put record from file

result = nudb.fput(file_path, data_type, rec_beg=None, timeout=60)

參數說明

  • file_path: 要上傳的檔案
  • data_type: 資料格式(json or text)
  • rec_beg: record begin pattern, 若資料格式為text則必須有此參數
  • timeout: 設定 timeout,單位為 s,預設是 60s.

Delete record by rid or key

result = nudb.rdel(data_id, search_field='rid', timeout=10)

參數說明

  • data_id: Record ID 或 primary key, 一次刪除多筆可使用,區隔多個 id
  • search_field: 搜尋的欄位,rid 或 key, 預設是 rid.
  • timeout: 設定 timeout,單位為 s,預設是 10s.

Update record

result = nudb.rupdate(data_id, data, data_type, search_field='rid', update_method='replaceRecord', timeout=10)

參數說明

  • data_id: 要更新的資料rid or primary key
  • data: 更新的資料內容
  • data_type: 資料格式(json or text)
  • search_field: 搜尋的欄位,rid 或 key, 預設是 rid.
  • update_method: 更新方式
    • replaceRecord: 取代整筆資料 (Default)
    • replaceField: 取代指定欄位的資料
  • timeout: 設定 timeout,單位為 s,預設是 10s.

Change log

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nudb-1.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nudb-1.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file nudb-1.1.1.tar.gz.

File metadata

  • Download URL: nudb-1.1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for nudb-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ebbab35dc736520a105e248863e9def7d562da15cfb26343444d0b040744f683
MD5 675d3f3169ce64cb379c1585cc940fca
BLAKE2b-256 8d659a4255ac0b7fa91ffb63ef278a213f4d4015f30b2f8b0cf8bf21389d3b99

See more details on using hashes here.

File details

Details for the file nudb-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: nudb-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for nudb-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4cd8a7dd14d3c4b4dbd1b7f6fe6c4849cd3e104e55aef19b1b06be3a6f2fd9e
MD5 e2163689fdce58e7f0610c6f26e3d22e
BLAKE2b-256 24909bc87b851da5022d23bd3c181118dd53851097ff5d2f262c590b30684702

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page