Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2006-08-21 01:13:39
- noods
- Member
- Registered: 2005-09-23
- Posts: 21
Search using OR instead of AND
Hi
I was wondering how to change textpatterns search engine so that it includes at least one word you type into the search feature – rather than all words.
For example, with a site i am developing, if you search “butter chicken” you will receive no results. Ideally, i would like the results to display articles with the word “butter” or “chicken” in it
Essentially, the search output query uses the AND operator (+) when you search using more than one word
http://www.recipesfor2.com.au/index.php?s=search&q=butter+chicken
But i want it to output using the OR operator (|) like below:
http://www.recipesfor2.com.au/index.php?s=search&q=butter|chicken|chicken
where in the textpattern code can i edit this?
Thanks in advance
-noods
Offline
Re: Search using OR instead of AND
The ‘+’ you see there is just to encode the space between the keywords you entered, because you can’t have a bare space within an URL. It is not related to Boolean AND searching.
Looking at the TXP code, it seems that it doesn’t do AND queries… or OR queries, but instead uses REGEXP matching. For example, if the title of an article is “word1 word2 word3”, then searching for “word1 word3” won’t match (it would if TXP did pure AND searching), but searching for “word1.*word3” will match.
You can try editing the publish.php file and change these two lines:
<pre><code>$match = “, match (Title,Body) against (‘$q’) as score”;
$search = “ and (Title rlike ‘$q’ or Body rlike ‘$q’) $s_filter”;
</code></pre>
into:
<pre><code>$match = “, match (Title,Body) against (‘$q’) as score”;
$search = “ and (match (Title,Body) against (‘$q’)) $s_filter”;
</code></pre>
or if you want <a href=“http://mysql.com/doc/refman/5.0/en/fulltext-boolean.html”>boolean search</a>:
<pre><code>$match = “, match (Title,Body) against (‘$q’ IN BOOLEAN MODE) as score”;
$search = “ and (match (Title,Body) against (‘$q’ IN BOOLEAN MODE)) $s_filter”;
</code></pre>
PS. This wasn’t tested, so I can’t guarantee that it’ll work.
Last edited by ruud (2006-08-21 14:42:04)
Offline
#3 2006-08-22 00:25:09
- noods
- Member
- Registered: 2005-09-23
- Posts: 21
Re: Search using OR instead of AND
thanks for that ruud – but it kinda outputted an error.
the ‘+’ does seem to work like an AND operator, even if it is there just to encode a space…but if you do replace it with the ‘|’ symbol, the search actually does search for either word you type in – if you have a look at the link below.
http://www.recipesfor2.com.au/index.php?s=search&q=butter|chicken|chicken
as opposed to searching directly for “butter chicken” in the search field.
is there any way to replace the ‘+’ with a ‘|’ in the encoding?
Offline
Re: Search using OR instead of AND
Hmm.. strange, works fine here.
The | in between words, it does indeed work as an OR operator, but without changing TXP code, writing a plugin or perhaps some javascript the + cannot be easily replaced.
Perhaps easier than my earlier suggestion would be to replace the line <code>$q = doSlash($q);</code> with <code>$q = doSlash(strtr($q, ‘ ‘, ‘|’));</code> in publish.php.
Offline
#5 2006-08-22 05:26:41
- noods
- Member
- Registered: 2005-09-23
- Posts: 21
Re: Search using OR instead of AND
thanks ruud!
that fix worked perfectly!
Offline
Pages: 1