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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

DataObject gets written twice in search


Go to End


2 Posts   1139 Views

Avatar
joelg

Community Member, 134 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, 1899 Posts

19 October 2010 at 9:21pm

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