Coder Social home page Coder Social logo

micmania1 / booleansearchparser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from duncanwilder/booleansearchparser

0.0 1.0 0.0 49 KB

A way to translate Boolean Search logic into MySQL Fulltext Parameters

License: The Unlicense

PHP 100.00%

booleansearchparser's Introduction

BooleanSearchParser

Build Status

The aim of this class is to take a Boolean Search and to convert it into something that can be used in a MySQL Fulltext Search.

The idea came about after recently working a lot with Boolean Search systems, and after reading this StackOverflow question, nothing really exists out there for MySQL.

Big thanks goes to PHP SQL Parser for having such a lovely Tokeniser and related methods, which made this easier.

Goals

  • To provide a good-enough conversion
  • To not try and correct mistakes with brackets and quotes etc.

Notes

Use

$parser = new \DuncanOgle\BooleanSearchParser\Parser();

echo $parser->parse("ict OR (technology AND bob)");
// ict (+technology +bob)

Regarding order

Order and brackets are important, more often than not OR logic takes priority

sales OR finance AND manager will become sales finance +manager and not sales +finance +manager

Todo

  • Handle the * character
  • Turn into a package that can be pulled in via composer
  • Move tests over to PHP Unit
  • Add custom priority settings (currently its OR>AND>NOT)
  • Add optional word stemmer like the one used here

Simple Examples

Input Output
ict +ict
ict it +ict +it
ict OR it ict it
NOT ict -ict
it NOT ict +it -ict
web AND (ict OR it) +web +(ict it)
ict OR (it AND web) ict (+it +web)
ict NOT (ict AND it AND web) +ict -(+ict +it +web)
php OR (NOT web NOT embedded ict OR it) php (-web -embedded ict it)
(web OR embedded) (ict OR it) +(web embedded) +(ict it)
develop AND (web OR (ict AND php)) +develop +(web (+ict +php))
"ict null
"ict OR it" +"ict OR it"

Complex Examples

Input Output
"business development" or "it sales" and (danish or dutch or italian or denmark or holland or netherlands or italy) "business development" "it sales" +(danish dutch italian denmark holland netherlands italy)
(procurement or buying or purchasing) and (marine or sea) and (engineering or engineer) +(procurement buying purchasing) +(marine sea) +(engineering engineer)

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.