/    Sign up×
Community /Pin to ProfileBookmark

I would like to make this more searchable, currently if you search for something in two different columns it returns nothing, if I searched for an artists name, and an album in the same search I get nothing.

Would I have to make $trimmed an array of words? If so, would this be a good way to search the DB?

[code=php]
$var = $_GET[‘q’];
$trimmed = trim($var);

$query = “SELECT artist,lyric,title,album,
MATCH(lyric, artist, album, title) AGAINST (‘$trimmed’ IN BOOLEAN MODE)
AS score
FROM lyrics
WHERE artist LIKE ‘%$trimmed%’ OR lyric LIKE ‘%$trimmed%’ OR title LIKE ‘%$trimmed%’ OR album LIKE ‘%$trimmed%’
AND MATCH(lyric, artist, album, title) AGAINST (‘$trimmed’ IN BOOLEAN MODE) ORDER BY score”;[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@chazzySep 25.2006 — you don't need the OR's in that sql...that's what your full text key does. other than that, i'm not sure what you mean by "more searchable". did you try BINARY instead of boolean?
Copy linkTweet thisAlerts:
@The_Little_GuyauthorSep 25.2006 — Would I just swithc out BOOLEAN with BINARY?

By "more searchable", I mean that I would like my search to return results that have text in the title and author, or author and album, or album and title, etc.

right now I can only either search title, author, or album, and not more than one.

Go here:http://d-top.org/ at the top in the search box type in this:

first type in [B]queen[/B] you get a bunch of results.

Now type in [B]Queen A Night At The Opera[/B]

You now get no results, and if you noticed, that was one of the results in the first search.



Also... I can't remove or, it just gives me errors.
Copy linkTweet thisAlerts:
@bokehSep 25.2006 — [CODE]artist LIKE '%$trimmed%' OR lyric LIKE '%$trimmed%' OR title LIKE '%$trimmed%' OR album LIKE '%$trimmed%' AND[/CODE]Remove the above from your query and it should work fine.
Copy linkTweet thisAlerts:
@The_Little_GuyauthorSep 25.2006 — OK

It displays results now, but if I search for

[B]Queen A Night At The Opera[/B]

It isn't displayed first.
Copy linkTweet thisAlerts:
@chazzySep 25.2006 — you need to better understand what you're passing in and querying against.

your query is literally searching for "Queen A Night..."

you need to break it up into individual items..
Copy linkTweet thisAlerts:
@The_Little_GuyauthorSep 25.2006 — And I was thinking of doing that with an array of words:

[code=php]$trimmed = trim($var); //$var is the search text
$trimmed = explode(" ", $trimmed);[/code]

Im not exactly sure how to do a query on any array of words.
Copy linkTweet thisAlerts:
@bokehSep 26.2006 — your query is literally searching for "Queen A Night..."[/QUOTE]That is only true for parts of the search string encapsulated in quotes.

Little Guy:

If your order is not as you would like you need to work on the part of the query that deals with the order. Near the top of the query you have: [CODE]MATCH [...] AGAINST [...] AS score[/CODE]Further down you have: [CODE]ORDER BY ´score´[/CODE]This is what is governing your output order, not the [I]where [/I] cluase which is what you seem to be concentrating on.
Copy linkTweet thisAlerts:
@chazzySep 26.2006 — sorry bokeh's right. i am assuming you entered "Queen ...." not Queen .... and the order should fix it in this case.
Copy linkTweet thisAlerts:
@bokehSep 26.2006 — the order should fix it in this case.[/QUOTE]Does a word have a higher specificity the nearer it is to the start of the string or am I misunderstanding what you are saying.
×

Success!

Help @The_Little_Guy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...