Hi there, hope all is well,
I'd like to be able to add multiple negative terms to a search query if possible, for example something similar to the following calling code:
$queryterm ="jumper -knitted -wooly";
Is this possible with external.php?
Many Thanks
Hi David,
Many thanks for that,
Its strange, I implemented the first part:
------------------------------------------
AGAINST ('".database_safe($parts[0])."')
REPLACE with:
AGAINST ('".database_safe($parts[0])."' IN BOOLEAN MODE)
------------------------------------------
and then when I added a negative term no results showed up at all.
Then when I also implemented the second part:
------------------------------------------
foreach($words as $word)
{
$where = "(";
...and REPLACE with:
foreach($words as $word)
{
if (substr($word,0,1)=="-")
{
$wheres[] = " name NOT LIKE '".database_safe(substr($word,1))."' ";
continue;
}
$where = "(";
------------------------------------------
The results showed up again as normall but with no negative term products removed,
Not sure what I've done here?!
Thanks,
Stew
Hi Stew,
Please could you email me your external.php and I'll check it out for you..
Cheers,
David.
--
PriceTapestry.com
Hi David,
I have the same issue here with a new site/installation of PT - is it OK to email you the external.php again?
Stew
Hi Stew,
I just checked back over our email dialog from the previous installation and I recall that I missed out the wildcard (%) characters from the NOT LIKE clauses, so I have corrected this in the modification described above (this comment). If still not working as expected sure forward the file and an example query and I'll take a look...
Cheers,
David.
--
PriceTapestry.com
Brilliant - thanks for looking at that David. Will give it a go now.
Hi Stew,
Sure - the BOOLEAN mode modification can be added to your external.php. In that file, perform a Search and Replace of
AGAINST ('".database_safe($parts[0])."')
REPLACE with:
AGAINST ('".database_safe($parts[0])."' IN BOOLEAN MODE)
You will then be able to set $_GET["q"] parameter in your calling code exactly as in your post by prefixing negative keywords with the - sign.
That covers the full text index, but bear in mind that any query containing a stopword (words like "this", "and" etc. that are considered too frequent to index) or any keyword less than 4 characters uses the basic search method. To support the same -keyword for basic searches, search for the following code beginning around line 480:
foreach($words as $word)
{
$where = "(";
...and REPLACE with:
foreach($words as $word)
{
if (substr($word,0,1)=="-")
{
$wheres[] = " name NOT LIKE '%".database_safe(substr($word,1))."%' ";
continue;
}
$where = "(";
Cheers,
David.
--
PriceTapestry.com