Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

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

Open
unloft opened this issue Mar 22, 2017 · 5 comments

Comments

@unloft
Copy link

unloft commented Mar 22, 2017

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
Copy link
Author

unloft commented Mar 22, 2017

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

@daviddarnes
Copy link
Member

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

@unloft
Copy link
Author

unloft commented Mar 22, 2017

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 .

@daviddarnes
Copy link
Member

@unloft not a problem, this is much better. Thank you 😄

@unloft
Copy link
Author

unloft commented Mar 26, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants