2017 © Pedro Peláez
 

library boolean-search-parser

A way to translate Boolean Search logic into MySQL Fulltext Parameters

image

duncanogle/boolean-search-parser

A way to translate Boolean Search logic into MySQL Fulltext Parameters

  • Tuesday, January 19, 2016
  • by DuncanOgle
  • Repository
  • 1 Watchers
  • 1 Stars
  • 702 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 5 Versions
  • 6 % Grown

The README.md

BooleanSearchParser

Build Status, (*1)

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., (*2)

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., (*3)

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

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, (*5)

sales OR finance AND manager will become sales finance +manager and not sales +finance +manager, (*6)

Todo

  • [x] Handle the * character
  • [x] Turn into a package that can be pulled in via composer
  • [x] 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), (*7)

The Versions

19/01 2016

dev-master

9999999-dev

A way to translate Boolean Search logic into MySQL Fulltext Parameters

  Sources   Download

Unlicense

The Requires

  • php >=5.4.0

 

The Development Requires

search mysql fulltext logic boolean

19/01 2016

1.0.5

1.0.5.0

A way to translate Boolean Search logic into MySQL Fulltext Parameters

  Sources   Download

Unlicense

The Requires

  • php >=5.4.0

 

The Development Requires

search mysql fulltext logic boolean

28/10 2015

v1.0.4

1.0.4.0

A way to translate Boolean Search logic into MySQL Fulltext Parameters

  Sources   Download

Unlicense

The Requires

  • php >=5.4.0

 

The Development Requires

search mysql fulltext logic boolean

27/10 2015

v1.0.3

1.0.3.0

A way to translate Boolean Search logic into MySQL Fulltext Parameters

  Sources   Download

Unlicense

The Requires

  • php >=5.4.0

 

The Development Requires

search mysql fulltext logic boolean

27/10 2015

1.0.0

1.0.0.0

A way to translate Boolean Search logic into MySQL Fulltext Parameters

  Sources   Download

Unlicense

The Development Requires

search mysql fulltext logic boolean