lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.9k stars 137 forks source link

Start Issue #84

Closed javadevelopment4 closed 3 years ago

javadevelopment4 commented 3 years ago

I have downloaded the project the following command doesn't work

npm install --save minisearch

However npm install works.

Not sure about the next step. How to run the project? How to start the server?

Not sure where to place the document or text folder to index the content and search.

lucaong commented 3 years ago

Hi @javadevelopment4 , MiniSearch is not a server or an application, it is a library that is used to implement full-text search inside applications. As such, there is no server to start. Usually, one would create a new JavaScript project (like a web application or a NodeJS app), require MiniSearch inside it, and use it to implement full-text search features. Your application using MiniSearch might implement a server, but it's up to the developer: MiniSearch provides some building blocks for builders. To make a parallel with the Java world, MiniSearch is more similar to Lucene than to ElasticSearch or Solr.

You can try running the demo application by cloning the repository and starting the example app:

# Clone then repository:
git clone git@github.com:lucaong/minisearch.git

# Go to the examples folder, install dependencies, and run the demo:
cd minisearch/examples
npm install
npm run start

As of where to put the documents if you use MiniSearch in your project, that is entirely up to you: MiniSearch needs you to call one of the add, addAll, or addAllAsync functions passing the documents as plain JavaScript object, but how to retrieve them is your decision. A common strategy for browser applications is to request the documents as JSON from an endpoint, and then index them with MiniSearch (that's what the demo application does).

The simplest possible demo you could try if you just want to experiment and learn, without even creating an application, is to install minisearch as you did, start a NodeJS console with node, and type line by line the basic example from the README inside the console:

// A collection of documents for our examples
const documents = [
  {
    id: 1,
    title: 'Moby Dick',
    text: 'Call me Ishmael. Some years ago...',
    category: 'fiction'
  },
  {
    id: 2,
    title: 'Zen and the Art of Motorcycle Maintenance',
    text: 'I can see by my watch...',
    category: 'fiction'
  },
  {
    id: 3,
    title: 'Neuromancer',
    text: 'The sky above the port was...',
    category: 'fiction'
  },
  {
    id: 4,
    title: 'Zen and the Art of Archery',
    text: 'At first sight it must seem...',
    category: 'non-fiction'
  },
  // ...and more
]

let miniSearch = new MiniSearch({
  fields: ['title', 'text'], // fields to index for full-text search
  storeFields: ['title', 'category'] // fields to return with search results
})

// Index all documents
miniSearch.addAll(documents)

Now in the console you can perform searches with the search function:

// Search with default options
let results = miniSearch.search('zen art motorcycle')
// => [
//   { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258, match: { ... } },
//   { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629, match: { ... } }
// ]
javadevelopment4 commented 3 years ago

Thank you so much for the details. Thinking of a portable search app which does indexing of txt or doc and publish the results with miniserver.

lucaong commented 3 years ago

I will close this issue for now, as I think that the question is answered, but feel free to comment further on it if needed.