anchor-cms icon indicating copy to clipboard operation
anchor-cms copied to clipboard

Important 2 problems with search ( comma words and left_join for search in other column )

Open unloft opened this issue 9 years ago • 5 comments

Summary

I followed this commit : #248 but not work... error on left_join ( point of null) I want include in my search box the post_meta.data column for search also in my custom fields but this changes not work. ( commit #248 )

I would also add comma words..... for example in italian : " d'amore " or " I'm " in

English how can I do? You can help me?
You can test my search box URL: http://www.albatrosmagazine.net/

  • Anchor version 0.12.1

unloft avatar Mar 22 '17 08:03 unloft

THIS IS MY 2 FILES anchor/models/post.php anchor-models-post-php.pdf system/query.php system-query-php.pdf

unloft avatar Mar 22 '17 08:03 unloft

@unloft hi there, would you be able to describe the issue you're having a little more clearly? Thanks

daviddarnes avatar Mar 22 '17 09:03 daviddarnes

When researching a word or combination of words all works. The Articles in fact returning with my search terms found in the titles or in the markdown of my articles. But the search does not work when using apostrophe words.as for example in Italian -> "d'amore" "does not work transforms the word in -> "dand 39 amore" or the word in English, "I'm" turned it into -> "Iand 39 m" This is my first mistake. The second problem concerns the possibility to also include the custom_fields in research. I tried to follow the commit #248 but does not work in my case.

Sorry for my confused explanation .

unloft avatar Mar 22 '17 09:03 unloft

@unloft not a problem, this is much better. Thank you šŸ˜„

daviddarnes avatar Mar 22 '17 09:03 daviddarnes

Hi this is my way for fix one problem: Search in custom fields text In this case i make a where clause for search only when a custom field have a specific id : ->where(Base::table('post_meta.extend'), '=', '126');
(in my case this id is a custom author field named book_author)

the code for search in custom_filed (text): anchor/models/post.php

`public static function search($term, $page = 1, $per_page = 10) {

	$query = static::left_join(Base::table('users'), Base::table('users.id'), '=', Base::table('posts.author'))
		->where(Base::table('posts.status'), '=', 'published')
		->where(Base::table('posts.title'), 'like', '%' . $term . '%')
		->or_where(Base::table('posts.html'), 'like', '%' . $term . '%');
	if ($query->count() == 0) {
		$query = static::left_join(Base::table('users'), Base::table('users.id'), '=', Base::table('posts.author'))
		->left_join(Base::table('post_meta'), Base::table('post_meta.post'), '=', Base::table('posts.id'))
			->where(Base::table('post_meta.data'), 'like', '%' . $term . '%')
			->where(Base::table('post_meta.extend'), '=', '126');
	}
	$total = $query->count();  

	$posts = $query->take($per_page)
		->skip(--$page * $per_page)
		->get(array(Base::table('posts.*'),
			Base::table('users.id as author_id'),
			Base::table('users.bio as author_bio'),
			Base::table('users.real_name as author_name')));

	foreach ($posts as $key => $post) {
		if ($post->data['status'] !== 'published') {
			unset($posts[$key]);
		}
	}
	if (count($posts) < 1) {
		$total = 0;
	}
	
	
	return array($total, $posts);
	
	}`

**# what do you think ? @daviddarnes SOME CAN HELP FOR apostrophe search problem? ** UPDATE the apostrophe error is for 2 type of apostrophes screens for "I'm" and "I’m" searchs apostrophe1 ' apostrophe2 ’ apostrophe1 apostrophe2

unloft avatar Mar 26 '17 10:03 unloft