Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

DataObject gets written twice in search


Reply


2 Posts   791 Views

Avatar
joelg

Community Member, 129 Posts

19 October 2010 at 10:11am

Edited: 19/10/2010 10:11am

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();
      $Search->write();
      
      $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

Joel

Avatar
swaiba

Forum Moderator, 1799 Posts

19 October 2010 at 9:21pm

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