lincanbin / Carbon-Forum

A high performance open-source forum software written in PHP. Discussions Tags based with Quora/StackOverflow style.
https://www.94cb.com/
Apache License 2.0
1.84k stars 433 forks source link

How to make search like google style? #248

Open hoogw opened 6 years ago

hoogw commented 6 years ago

1) if I search aaa bbb ccc it search for any title OR tag like aaa OR like bbb OR like ccc. SQL = like aaa or like bbb or like ccc

Google search does, AND, means, any title OR tag like aaa AND bbb AND ccc. SQL = like aaa AND like bbb AND like ccc

I feel google style is better, more useful, why, if I google BASS, the result could have fish, gitar, and people.

I only want to see result related to fish, and filter out others. so I search BASS FISH, google will use AND by default, means, BASS AND FISH. it will only show results have both BASS and fish.

If I google BASS -fish, I will filter out all fish related page, means, I don't want to see fish related page, SQL = Like BASS AND not like FISH.

google search style is more useful, it should only need to make change at SQL, or => and

hoogw commented 6 years ago

google style, - minus means not include, + plus sign means include

aaa -bbb -ccc

means, pages include aaa, but not include bbb, not include ccc

+aaa bbb -ccc

means, pages include aaa AND bbb, but NOT include ccc

hoogw commented 6 years ago

also google style, 'bbb aaa' , "bbb aaa"

means, exact string 'bbb aaa' must be match.

hoogw commented 6 years ago

Including and Excluding Google Search Terms https://www.lifewire.com/addition-subtraction-in-google-1616814

Ten Tips for Smarter Google Searches http://www.informit.com/articles/article.aspx?p=675274&seqNum=3

hoogw commented 6 years ago

自己动手,满足自己需要。

改这个文件。要加个括号。 (topic or tag) AND (topic or tag) AND (topic or tag) controller/search.php

`///$NormalQuery[] = 't.Topic LIKE :Topic' . $ParamName . ' or t.Tags LIKE :Tag' . $ParamName;

$NormalQuery[] = '('.'t.Topic LIKE :Topic' . $ParamName . ' or t.Tags LIKE :Tag' . $ParamName . ')';

...................

.............

.......

...`

另外一个地方 OR 改成 AND

///$Temp = implode(' OR ', $NormalQuery);

$Temp = implode(' AND ', $NormalQuery);

...................

.............

.......

...

改过以后, search “aaa bbb” 无论是tag 还是topic 必须同时有 aaa 和 bbb 的帖子才出现在搜索结果里,和google search一样。

没改之前,search “aaa bbb” 无论是tag 还是topic, 只有aaa,没有bbb的帖子也出现在搜索结果里。这是不符合google search的原则的。

hoogw commented 6 years ago

$AdvancedQuery $AdvancedQuery = array();//高级查询条件,用AND连接

请解释一下,这个东西怎么用,和 $NormalQuery = array();//普通查询条件,用OR连接 有什么区别?

我把 $AdvancedSearch = true 怎么不管用,