Coder Social home page Coder Social logo

docquery's Introduction

DocQuery

Document query interface for plaintext documents stored in directories on a filesystem.

Installation

~ $ npm install docquery
...

Usage

Library

> var dq = new DocQuery("~/Projects/docquery/test/fixtures", {recursive: true})
DocQuery {}

> dq.search("star")
[{"filePath": "/Users/jonmagic/Projects/docquery/test/fixtures/top-5/movies.md",  "fileName": "movies.md",  "title": "movies",  "modifiedAt": "2015-05-15T17:28:25.250Z",  "body": "..."}]

> dq.documents
// [...returns list of all documents sorted newest to oldest]

> dq.on("ready", function() { console.log("fires when documents are finished loading") })
> dq.on("added", function(fileDetails) { console.log("fires when a document is added") })
> dq.on("updated", function(fileDetails) { console.log("fires when a document is updated") })
> dq.on("removed", function(fileDetails) { console.log("fires when a document is removed") })

Command Line

Here's an example directory structure with some markdown documents in it.

~/Projects/docquery $ tree test/fixtures
test/fixtures
├── 2015-05-15.md
├── hello-world.md
└── top-5
    ├── burgers.md
    └── movies.md

1 directory, 4 files

Use the docquery command line tool dq to query those documents and get back json results.

~/Projects/docquery $ dq -r -p test/fixtures star
[
  {
    "filePath": "/Users/jonmagic/Projects/docquery/test/fixtures/top-5/movies.md",
    "fileName": "movies.md",
    "title": "movies",
    "modifiedAt": "2015-05-15T17:28:25.250Z",
    "body": "..."
  }
]

dq takes a number of options.

~/Projects/docquery $ dq -h
Usage: dq [options] query

Options:
  -p, --path <path>    Path to search
  -r, --recursive      Search sub directories
  -b, --body           Include document body in search result
  -h, --help           Show dq help

Return file paths only from the search results with jq.

~/Projects/docquery $ dq -rp test/fixtures star | jq .[].filePath
"/Users/jonmagic/Projects/docquery/test/fixtures/top-5/movies.md"

Set default options by creating a ~/.dq file that looks like this:

{
  "recursive": false,
  "searchPath": "~/Notes",
  "includeBody": false
}

Development

~/Projects/docquery $ npm test

> [email protected] test /Users/jonmagic/Projects/docquery
> babel src --out-dir lib; mocha --compilers js:mocha-traceur test/*_test.js

src/cli.js -> lib/cli.js
src/docquery.js -> lib/docquery.js


  DocQuery
    #search
      ✓ returns search result for query (214ms)
      ✓ returns new documents in search results (418ms)
      ✓ does not return document in search results after it has been deleted (626ms)
    #documents
      ✓ returns all documents (209ms)
      ✓ returns documents sorted newest first (210ms)
      ✓ returns new documents as they are added (414ms)
      ✓ does not return document after it has been deleted (625ms)
      ✓ ignores files in subfolders when recursive is false (419ms)


  8 passing (3s)

Contributors

License

The MIT License (MIT)

Copyright (c) 2015 Jonathan Hoyt

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

docquery's People

Contributors

jonmagic avatar lexicalunit avatar seongjaelee avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docquery's Issues

Intermittent test failures

~/Projects/docquery (master)🐑 💨 ✨  npm test

> [email protected] test /Users/jonmagic/Projects/docquery
> babel src --out-dir lib; mocha --compilers js:mocha-traceur test/*_test.js

src/cli.js -> lib/cli.js
src/docquery.js -> lib/docquery.js


  DocQuery
    #search
      ✓ returns search result for query
      ✓ returns new documents in search results (160ms)
      ✓ does not return document in search results after it has been deleted (267ms)
    #documents
      ✓ returns all documents
      ✓ returns documents sorted newest first
      ✓ returns new documents as they are added (189ms)

/Users/jonmagic/Projects/docquery/test/docquery_test.js:106
          assert.equal("tempfile", dq.documents[0].title)
               ^
AssertionError: 'tempfile' == 'movies'
    at DocQuery.<anonymous> (/Users/jonmagic/Projects/docquery/test/docquery_test.js:106:16)
    at DocQuery.emit (events.js:107:17)
    at DocQuery.addDocument (/Users/jonmagic/Projects/docquery/lib/DocQuery.js:90:10)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/lib/DocQuery.js:63:11)
    at EventEmitter.emit (events.js:107:17)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/node_modules/chokidar/index.js:135:15)
    at EventEmitter.FSWatcher._emit (/Users/jonmagic/Projects/docquery/node_modules/chokidar/index.js:148:5)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:172:14)
    at addOrChange (/Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:177:7)
    at /Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:194:19
    at FSReqWrap.oncomplete (fs.js:95:15)
npm ERR! Test failed.  See above for more details.
~/Projects/docquery (master)🐑 💨 ✨  npm test

> [email protected] test /Users/jonmagic/Projects/docquery
> babel src --out-dir lib; mocha --compilers js:mocha-traceur test/*_test.js

src/cli.js -> lib/cli.js
src/docquery.js -> lib/docquery.js


  DocQuery
    #search
      ✓ returns search result for query
      ✓ returns new documents in search results (131ms)
      ✓ does not return document in search results after it has been deleted (345ms)
    #documents
      ✓ returns all documents
      ✓ returns documents sorted newest first
      ✓ returns new documents as they are added (186ms)
      ✓ does not return document after it has been deleted (357ms)
      ✓ ignores files in subfolders when recursive is false (213ms)


  8 passing (1s)

~/Projects/docquery (master)🐑 💨 ✨  npm test

> [email protected] test /Users/jonmagic/Projects/docquery
> babel src --out-dir lib; mocha --compilers js:mocha-traceur test/*_test.js

src/cli.js -> lib/cli.js
src/docquery.js -> lib/docquery.js


  DocQuery
    #search
      ✓ returns search result for query
      ✓ returns new documents in search results (169ms)
      ✓ does not return document in search results after it has been deleted (327ms)
    #documents
      ✓ returns all documents
      ✓ returns documents sorted newest first
      ✓ returns new documents as they are added (190ms)

/Users/jonmagic/Projects/docquery/test/docquery_test.js:106
          assert.equal("tempfile", dq.documents[0].title)
               ^
AssertionError: 'tempfile' == 'movies'
    at DocQuery.<anonymous> (/Users/jonmagic/Projects/docquery/test/docquery_test.js:106:16)
    at DocQuery.emit (events.js:107:17)
    at DocQuery.addDocument (/Users/jonmagic/Projects/docquery/lib/DocQuery.js:90:10)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/lib/DocQuery.js:63:11)
    at EventEmitter.emit (events.js:107:17)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/node_modules/chokidar/index.js:135:15)
    at EventEmitter.FSWatcher._emit (/Users/jonmagic/Projects/docquery/node_modules/chokidar/index.js:148:5)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:172:14)
    at addOrChange (/Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:177:7)
    at /Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:194:19
    at FSReqWrap.oncomplete (fs.js:95:15)
npm ERR! Test failed.  See above for more details.
~/Projects/docquery (master)🐑 💨 ✨  npm test

> [email protected] test /Users/jonmagic/Projects/docquery
> babel src --out-dir lib; mocha --compilers js:mocha-traceur test/*_test.js

src/cli.js -> lib/cli.js
src/docquery.js -> lib/docquery.js


  DocQuery
    #search
      ✓ returns search result for query
      ✓ returns new documents in search results (179ms)
      ✓ does not return document in search results after it has been deleted (257ms)
    #documents
      ✓ returns all documents
      ✓ returns documents sorted newest first
      ✓ returns new documents as they are added (189ms)

/Users/jonmagic/Projects/docquery/test/docquery_test.js:106
          assert.equal("tempfile", dq.documents[0].title)
               ^
AssertionError: 'tempfile' == 'movies'
    at DocQuery.<anonymous> (/Users/jonmagic/Projects/docquery/test/docquery_test.js:106:16)
    at DocQuery.emit (events.js:107:17)
    at DocQuery.addDocument (/Users/jonmagic/Projects/docquery/lib/DocQuery.js:90:10)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/lib/DocQuery.js:63:11)
    at EventEmitter.emit (events.js:107:17)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/node_modules/chokidar/index.js:135:15)
    at EventEmitter.FSWatcher._emit (/Users/jonmagic/Projects/docquery/node_modules/chokidar/index.js:148:5)
    at EventEmitter.<anonymous> (/Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:172:14)
    at addOrChange (/Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:177:7)
    at /Users/jonmagic/Projects/docquery/node_modules/chokidar/lib/fsevents-handler.js:194:19
    at FSReqWrap.oncomplete (fs.js:95:15)
npm ERR! Test failed.  See above for more details.
~/Projects/docquery (master)🐑 💨 ✨  npm test

> [email protected] test /Users/jonmagic/Projects/docquery
> babel src --out-dir lib; mocha --compilers js:mocha-traceur test/*_test.js

src/cli.js -> lib/cli.js
src/docquery.js -> lib/docquery.js


  DocQuery
    #search
      ✓ returns search result for query
      ✓ returns new documents in search results (175ms)
      ✓ does not return document in search results after it has been deleted (259ms)
    #documents
      ✓ returns all documents
      ✓ returns documents sorted newest first
      ✓ returns new documents as they are added (157ms)
      ✓ does not return document after it has been deleted (308ms)
      ✓ ignores files in subfolders when recursive is false (215ms)


  8 passing (1s)

Support faster index querying

Live-filtering a folder with 3500 notes is pretty slow, see seongjaelee/nvatom#35

I have no clue about the intricacies here, yet; possibly opting out of filterBody(doc) can help if this.searchIndex.search(query) returns a list of matching files in a more reasonable amount of time already.

(I really wonder how the search index of Notational Velocity can be so blazing fast! I'd love to copy the solution here :))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.