Jump to:

23364 Posts in 18142 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » DataObject gets written twice in search

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 731 Views
  • joelg
    Community Member
    129 Posts

    DataObject gets written twice in search Link to this post

    Hi everyone

    I'm running a site with 2.4.0 and have enabled fulltext search. I'm doing a little statistics on the searches by writing the search query into a dataobject and save it to the database for each search a user makes. The code looks like this and is placed inside the results-function in my Page_Controller.php class:

        * Process and render search results.
        * @param array $data The raw request data submitted by user
        * @param SearchForm $form The form instance that was submitted
        * @param SS_HTTPRequest $request Request generated for this action
       function results($data, $form, $request) {
          $Search = new SearchEntry();
          $Search->SearchQuery = $form->getSearchQuery();
          $data = array(
             'Results' => $form->getResults(),
             'Query' => $form->getSearchQuery(),
             'Title' => 'Search Results'
          return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));

    What bugs me is that my SearchEntry dataobject gets written twice on my live site, but not on my localsite. Does anyone have any idea what could be causing this?

    Thanks for any help


  • swaiba
    Forum Moderator
    1784 Posts

    Re: DataObject gets written twice in search Link to this post

    No, but to help I'd suggest calling ->removeDuplicates() ont he DataObjectSet to ensure the correct result.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.