NAME

Search::Elasticsearch::Compat::Util - Provides the filter_keywords utility

VERSION

version 0.10

SYNOPSIS

use Search::Elasticsearch::Compat::Util qw(filter_keywords);

my $filtered = filter_keywords($unfiltered)

SUBROUTINES

filter_keywords()

This tidies up a string to be used as a query string in (eg) "search()" in Search::Elasticsearch::Compat so that user input won't cause a search query to return an error.

It is not flexible at all, and may or may not be useful to you.

Have a look at Search::Elasticsearch::Compat::QueryParser which gives you much more control over your query strings.

The current implementation does the following:

  • Removes any character which isn't a letter, a number, a space or -+'"*@._.

  • Removes and, or and not

  • Removes any - that doesn't have a space in front of it ( "foo -bar") is acceptable as it means 'foo' but not with 'bar'

  • Removes any space after a + or -

  • Removes any + or - which is not followed by a letter, number or a double quote

  • Removes any * that doesn't have at least 3 letters before it, ie we only allow wildcard searches on words with at least 3 characters

  • Closes any open double quotes

  • Removes leading and trailing whitespace

YMMV

LICENSE AND COPYRIGHT

Copyright 2009-2013 - 2011 Clinton Gormley.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

AUTHOR

Clinton Gormley <drtech@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by Elasticsearch BV.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004