Giter Site home page Giter Site logo

customsearch-1.0's Introduction

CustomSearch-1.0 馃攷

Patreon Paypal Discord

Framework for building search engines in lua. Handles most of the heavy work for you, such as concept separation, non ascii character support, logical operators and user criteria selection.

API Overview

Name Description
:Matches(article, search, filters) Returns wether the given article matches the search query using the filters structure as the criteria.
:Find(search, field1, field2, ...) Returns wether the search string is present on any of the string fields provided.
:Compare(operator, a, b) Returns an inequality operation between a and b, where operator is the string representation of the operation.

Filters Specification

The filters data structure allows you to easly build a search engine of your own. filters is a set of filter objects. Each filter is akin to an independent criteria of the engine: if any filter approves the article for a given search query, the article is approved.

For an object to be a filter, it must implement the following fields:

Name Description
:canSearch(operator, search, article) Returns wether the filter can process this query. If not .match will not be called and this filter will not be considered for the query. Can return any number of arguments.
:match(article, operator, data1, data2, ...) Returns wether this filter approves the article for a given query. 'data1', 'data2', etc are the return arguments of :canSearch.
.tags Optional. Array of identifiers that can be placed at the beggining of a search query to perform a :Match using only this filter.

Examples

local Lib = LibStub('CustomSearch-1.0')

Lib:Find('(Jo茫o)', 'Roses are red', 'Violets are (j贸a么)', 'Wait that was wrong') -- true
Lib:Find('banana', 'Roses are red', 'Violets are j贸a么', 'Wait that was wrong') -- false

Lib:Compare('<', 3, 4) -- true
Lib:Compare('>', 3, 4) -- false
Lib:Compare('>=', 5, 5) -- true

local Filters = {
  isBanana = {
    tags = {'b', 'ba'},
    
    canSearch = function(self, operator, search)
      return true
    end,
    
    match = function(self, article, operator, search)
      return Lib:Find(article, 'banana')
    end
  },
  
  searchingApple = {
    tags = {'a', 'app'},
    
    canSearch = function(self, operator, search)
      if not operator then
        return search
      end
    end,
    
    match = function(self, article, operator, search)
      return Lib:Find(search, 'apple')
    end
  }
}

Lib:Match('Banana', '', Filters) -- true
Lib:Match('', 'Apple', Filters) -- true
Lib:Match('', '> Apple', Filters) -- false
Lib:Match('Apple', 'Banana', Filters) -- false
Lib:Match('', 'b:Apple', Filters) -- false
Lib:Match('', 'a:Apple', Filters) -- true

鈿狅笍 Reminder!

If you use this library, please list it as one of your dependencies in the CurseForge admin system. It's a big help! 馃憤

customsearch-1.0's People

Contributors

jaliborc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

psykzz shaylynia

customsearch-1.0's Issues

Error when searching for "[": malformed pattern (missing ']')

When calling "Lib:Matches(link, search)" the following error will trigger if search contains the character "[":
malformed pattern (missing ']')

Proposed fix:
Disable pattern matching for the :find method used on lines 109 and 136:
if value:find(tag, nil, true) then
if text and self:Clean(text):find(search, nil, true) then

The same should be done in LibItemSearch-1.2 (sorry for including it here, but there is no issue tracker for LibItemSearch), on line 109:
if name:find(search, nil, true) then

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.