1.0.2 • Published 11 months ago

afta v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

AFTA

AFTA is a powerful, open-source JavaScript library for analyzing, indexing, and searching documents. It provides support for different kinds of document parsers (currently PDF and HTML), various query types, and leverages an SQL database for storing and retrieving indexed documents.

This project is ideal for applications that require efficient and advanced search functionality over a collection of documents.

Key Features

  • Supports multiple types of document parsers
  • Built-in document analyzer and indexer
  • Cache system for optimizing search operations
  • Multiple query types supported (Term, Boolean, Phrase)
  • Uses SQLite database for persisting index and document data

In this section, we will guide you through the process of setting up and using the Indexer. This will include the following steps:

Setup Environment

Make sure you have Node.js installed. If you don't, you can download it from the official website. Also, ensure that you have a running instance of an Analyzer server. You will need to specify its address when creating an instance of the Analyzer class.

Install Dependencies

As this library is meant to be used with a node environment, ensure all dependencies are installed. Run the command npm install in your terminal at the root of your project directory.

Install Pacakge afta

npm install afta

Create an Instance of Analyzer

import { Analyzer } from "afta";

const analyzer = new Analyzer("link_to_analyzer");

Create an Instance of Database

import { SQLiteDatabase } from "afta";

const database = new SQLiteDatabase("indexer.db");
await database.connect();

Create an Instance of Indexer

import { Indexer } from "afta";

const indexer = new Indexer(analyzer, database);

Add Documents to Indexer

import { Document, Field } from "../../src";

const document = new Document(1);
const field1 = new Field(
  "title",
  "My Title",
  "My Analyzed Title",
  true,
  true,
  true
);
const field2 = new Field(
  "body",
  "My Body",
  "My Analyzed Body",
  true,
  true,
  true
);

document.add(field1);
document.add(field2);

await indexer.addDocument(document);

Create and Execute Queries

import { TermQuery, Term, BuilderQuery } from "afta";

const termQuery = new TermQuery(new Term("title", "My Title"));
const builderQuery = new BuilderQuery();
builderQuery.build(termQuery);

const result = await builderQuery.execute(indexer, analyzer);
console.log(`Total Hits: ${result.totalHits}`);
console.log(`Matching Documents: ${JSON.stringify(result.documents)}`);

Closing the Database Connection

await database.close();

This is a basic guide on how to use the Indexer. Depending on your specific use case, you may need to use additional features or techniques.

The complete code for these steps is:

import {
  Analyzer,
  SQLiteDatabase,
  Indexer,
  Document,
  Field,
  TermQuery,
  Term,
  BuilderQuery,
} from "afta";

// Instantiate Analyzer
const analyzer = new Analyzer("link_to_analyzer");

// Instantiate SQLiteDatabase
const database = new SQLiteDatabase("indexer.db");
await database.connect();

// Instantiate Indexer
const indexer = new Indexer(analyzer, database);

// Create and Add Document to Indexer
const document = new Document(1);
const field1 = new Field(
  "title",
  "My Title",
  "My Analyzed Title",
  true,
  true,
  true
);
const field2 = new Field(
  "body",
  "My Body",
  "My Analyzed Body",
  true,
  true,
  true
);

document.add(field1);
document.add(field2);

await indexer.addDocument(document);

// Create and Execute Queries
const termQuery = new TermQuery(new Term("title", "My Title"));
const builderQuery = new BuilderQuery();
builderQuery.build(termQuery);

const result = await builderQuery.execute(indexer, analyzer);
console.log(`Total Hits: ${result.totalHits}`);
console.log(`Matching Documents: ${JSON.stringify(result.documents)}`);

// Close the database connection
await db.close();
1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

12 months ago