Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Parse a free-text phrase to a query

free_text_search

Search a inverted positional index and return ranked references to documents relevant to the search phrase.

THIS PACKAGE IS IN BETA DEVELOPMENT AND SUBJECT TO DAILY BREAKING CHANGES.

Overview

The components of this library:

Query phrases can include modifiers broadly consistent with Google search modifiers.

Refer to the references to learn more about information retrieval systems and the theory behind this library.

Usage

In the pubspec.yaml of your flutter project, add the free_text_search dependency.

dependencies:
  free_text_search: <latest version>

In your code file add the free_text_search import.

import 'package:free_text_search/free_text_search.dart';

To parse a phrase simply pass it to the QueryParser.parse method, including any modifiers as shown in the snippet below.

// A phrase with all the modifiers
  const phrase =
      '"athletics track" +surfaced arena OR stadium "Launceston" -hobart NOT help-me';

  // Pass the phrase to a QueryParser instance parse method
  final queryTerms = await QueryParser().parse(phrase);

  // The following terms and their `[MODIFIER]` properties are returned
        // "athletics track" [EXACT] 
        // "athletics" [OR] 
        // "track" [OR] 
        // "surfaced" [IMPORTANT] 
        // "arena" [AND] 
        // "stadium" [OR] 
        // "Launceston" [EXACT] 
        // "launceston" [OR] 
        // "hobart" [NOT] 
        // "help-me" [NOT] 
        // "help" [NOT]     

The examples demonstrate the use of the QueryParser and PersistedIndexer.

API

FreeTextSearch class

The FreeTextSearch class exposes the search method that returns a list of SearchResult instances in descending order of relevance.

The length of the returned collection of SearchResult can be limited by passing a limit parameter to search. The default limit is 20.

After parsing the phrase to terms, the Postings and Dictionary for the query terms are asynchronously retrieved from the index:

Ensure that the FreeTextSearch.configuration and FreeTextSearch.tokenFilter match the TextAnalyzer used to construct the index on the target collection that will be searched.

SearchResult class

The SearchResult model represents a ranked search result of a query against a text index:

QueryParser class

The QueryParser parses free text queries, returning a collection of QueryTerm objects that enumerate each term and its QueryTermModifier.

The QueryParser.configuration and QueryParser.tokenFilter should match the TextAnalyzerused to construct the index on the target collection that will be searched.

The QueryParser.parse method parses a phrase to a collection of QueryTerms that includes:

QueryTerm for a derived version of a term always has its QueryTerm.modifier property set to QueryTermModifier.OR, unless the term was marked QueryTermModifier.NOT in the query phrase.

FreeTextQuery class

The FreeTextQuery enumerates the properties of a text search query:

QueryTerm class

The QueryTerm object extends Token, and enumerates the properties of a term in a free text query phrase:

QueryTermModifier Enumeration

The phrase can include the following modifiers to guide the the search results scoring/ranking algorithm:

Definitions

The following definitions are used throughout the documentation:

References

Issues

If you find a bug please fill an issue.

This project is a supporting package for a revenue project that has priority call on resources, so please be patient if we don’t respond immediately to issues or pull requests.

Contribute and/or Download the source code on GitHub

https://github.com/GM-Consult-Pty-Ltd/free_text_search
Exit mobile version