Search broken in Server-Side Processing

Search broken in Server-Side Processing

east1999east1999 Posts: 31Questions: 11Answers: 0

Hi guys,

I'm trying to transition my DT to SSP, and it's working great! However, I'm running into a few problems with parts of the code, because I used to rely on the data being fully loaded at the start.

My search function is posted below and collects data from a form (input and select). It executes after user action.

What happened with pure JS is that columns would be searched as loaded. With SSP it's a whole different thing.

  • General table.search() does not work at all.
  • Searching in two columns at the same time also doesn't work.
  • Strings that contain text separated by commas are limited to searches within portions between commas
  • I also believe that, as you search, the number of results gets smaller, as if you're searching within your own results.

My server-side code uses PHP and is copied from your example here.

What am I doing wrong?

var searchIt = function () {

    var searchUrl = ($('.form-control').val()).replace(/ /g,"+");
    var searchKey = $('.form-control').val();
    var selectedCategory = $('#gosearch').text();

    table.columns().search("").draw();)

    if (searchKey.length > 0) {

      if(selectedCategory == "General") { // Detect keyword search
        table.search(searchKey).draw();
        window.history.pushState({page:""}, document.title, "?=" + searchUrl);
      }
      else if (selectedCategory == "Author") { // Detect authors search
        table.columns(1).search(searchKey).draw();
        window.history.pushState({page: ""}, document.title, "?aut=" + searchUrl);
      }
      else if(selectedCategory == "Publication") { // Detect periodical search
        table.columns([6,7]).search(searchKey).draw();
        window.history.pushState({page: ""}, document.title, "?pub=" + searchUrl);
      }
      else if(selectedCategory == "Keyword") { // Detect keyword search
        table.columns(4).search(searchKey).draw();
        window.history.pushState({page: ""}, document.title, "?tag=" + searchUrl);
      }
      $('.alert').animate({top: "1em"});
      $('.alert').delay(500).animate({top: "-10em"});
    }
    else { // Detect empty search
      table.columns().search("").draw();
      window.history.pushState({page: ""}, document.title, "/");
    }

  }

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    edited January 2019

    Hi @east1999 ,

    There's a lot going on there. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    One point to make though, is that with serverSide, the search is the responsibility of the server-side script. If it's not working, to debug, see what the server is being sent, and what it's sending back. That will give some clues as to where the problem lies.

    Cheers,

    Colin

  • east1999east1999 Posts: 31Questions: 11Answers: 0
    edited January 2019

    Thank you for your answer. I was actually going to delete this question because I now see it is badly stated and I don't want it to be a source of confusion to others.

    • Table.search() is actually working
    • Searching in two columns has never worked (only as AND search)
    • Smaller results do happen, but this requires more testing. Since I have the mark.js plugin turned on, I sometimes see the new result with the previous one still highlighted.
    • Server-side search is not smart and I haven't been able to enforce that, thus it requires JOHN PHILIP SMITH and won't return the name if you enter JOHN SMITH.

    A test case would be ideal but I would need to take my table apart so I can show it to you.

  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    Answer ✓

    Hi @east1999 ,

    Searching in two columns has never worked (only as AND search)

    Yep, searches are ANDed together - not ORed - all columns have to match any search criteria given to them.

    not smart

    This thread here should help - short answer, you'll need to implement that.

    Cheers,

    Colin

  • east1999east1999 Posts: 31Questions: 11Answers: 0

    I think this is also about that question, but the code doesn't work with my case, so maybe it is best to think of a workaround, since I don't know that much about php. Thank you @colin for clarifying the problem here! From what I read, implementing OR search can be quite tough on the servers, but I hope there is a solution in the future, because SSP kind of takes away the magic of that search box.

    I'm marking this question as answered.

This discussion has been closed.