Serverside: OR Search not working

Serverside: OR Search not working

hugh_grunthugh_grunt Posts: 4Questions: 2Answers: 0
edited June 6 in Free community support

Hello,

i have a datatable setup serverside, all working great except i can not get OR search working, for instance:
"Word Anotherword"
It will not look for "Word" OR "Anotherword" but for "Word Anotherword".

I have looked at multiple posts but they did not helpe me as it seems to be already be implemented what these posts suggest.

My DataTableInitiation is like this:

new DataTable('#example', { 
    "search":
        {
            "regex" : true,
            smart : false
        },
    ajax: 'php/xxxx.php',
    columns: [      
        { data: 'xxx', "regex":true }
    ],  
    processing: true,
    serverSide: true,
;

I do have a search for every column which calls this:

column.search(input.value, true, false).draw();

The Payload also looks fine to me:
(EDIT: gave column payloard first)

start: 0
length: 10
search[value]: ges kla
search[regex]: true

The php script seems to already have the functionality but i still get 0 results:

if ( count( $globalSearch ) ) {
            $where = '('.implode(' OR ', $globalSearch).')';
        }

        if ( count( $columnSearch ) ) {
            $where = $where === '' ?
                implode(' AND ', $columnSearch) :
                $where .' AND '. implode(' AND ', $columnSearch);
        }

        if ( $where !== '' ) {
            $where = 'WHERE '.$where;
        }

        return $where;

There is only one custom change i made to the sspclass, which is hardcoded the max amount of data output with the max_items variable im passing, but if i understood correctly this should not be the issue as it gets applied after the sql search:

return array(
            "draw"            => isset ( $request['draw'] ) ?
                intval( $request['draw'] ) :
                0,
                "limit" => $limit,
            "recordsTotal"    => intval( $recordsTotal ),
            "recordsFiltered" => intval( $recordsFiltered ),
            "data"            => self::data_output( $columns, $data, $max_items)
        );

I hope youre not annoyed, but all the posts did not help me yet.
Thanks in advance.

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    The WHERE condition that method builds up will OR over multiple columns for the string given, but it doesn't split the incoming string input different words - see here.

    At the moment it will search for "Word Anotherword" being present in any of the columns. It doesn't do a any word, any order, any column search like client-side processing does in DataTables.

    That link shows where the code would need to be modified to change that if you want to do so.

    Allan

  • hugh_grunthugh_grunt Posts: 4Questions: 2Answers: 0

    Ah, ok i see what i understood wrong with OR.

    I will try modify the code to do as i wish, thanks for answer.

Sign In or Register to comment.