I've found boolean mode of MySQL full text search useful, however there are a couple of things I can't seem to figure out how to achieve.
For instance imagine I have a full text column containing the words "Steve's Javascript Tutorial - Part One".
I would like to match this for each of the following searches: "tutorials", "javascript tutorials", "java", "java script", "script"
Imagine that each of those searches is simply assigned to a variable in whatever language may be being used (I always use PHP).
How could I modify this to make sure that Steve's article is returned on each of those searches?
MATCH (article_title) AGAINST ('"+$variable+"*' IN BOOLEAN MODE)
This is impossible ;)
When you search for "tutorials" the entry will not be found, because the entry in the database is singular and the search term is plural. You should do some form of "word stemming" before inserting the values to the database (and on search).
When you have done this, your expression will work. For searrch terms with more words (spaces) you should add the asterix to every word.
Related
Sorry, but uhrm, I'd like to use regexp (actually I'd use something else but I want to do the task within a Matlab function) to pick a single row containing desired keywords within an html table.
I am using Matlab calling function regexpi (case-insensitive version of regexp), which is akin to PHP regex from what I can tell.
Ok, here's a snippet from such an html table to parse:
<tr><td>blu</td><td>value</td></tr><tr><td>findme</td><td>value</td></tr><tr><td>ble</td><td>value</td></tr>
The desired row to pick contains the word "findme".
(added:) Content of other cells and tags in the table could be anything (here "bla" is a dummy value)- the important part is the presence of "findme" and that a single line (not more) is caught (or all lines containing "findme" but such behaviour is not expected). Any paired name/value table in a wikipedia page is a good example.
I tinkered with https://regex101.com/ using whatever I could dig up at the Matlab documentation (forward/backward looking, combinations of :,> and ?), but have failed to identify a pattern that will pick just the right row (or all those that contain the keyword "findme"). The following pattern for instance will pick the text but not the entire row: <tr[^>]*>[^>]*.*?(findme).*?<\/td .
Pattern <tr[^>]*>(.*?findme.*?)<\/tr[^>]*> picks the row but is too greedy and picks preceding rows.
Note that the original task I had set out was to capture entire tables and then parse these, but the Matlab regexp-powered function I found for the task had trouble with nested tables (or I had trouble implementing it for the task).
The question is how to return a row containing desired keywords from an html table, programmatically, within a matlab function (without calling an external program)? Bonus question is how to solve the nested table issue, but maybe that's another question.
I suggest you split up the string with strsplit and use contains for the filtering, which is a lot more readable and maintainable than a regex pattern:
htmlString = ['<tr><td>blu</td><td>value</td></tr><tr><td><a',...
'href="bla">findme</a></td><td>value</td></tr><tr><td><a',...
'href="ble">ble</a></td><td>value</td></tr>'];
keyword = 'findme';
splitStrings = strsplit(htmlString,'<tr>');
desiredRow = ['<tr>' splitStrings{contains(splitStrings,keyword)}]
The output is:
<tr><td>findme</td><td>value</td></tr>
Alternatively you may also combine extractBetween and contains:
allRows = extractBetween(htmlString,'<tr>','</tr>');
desiredRow = ['<tr>' allRows{contains(allRows,keyword)} '</tr>']
If you must use regex:
regexp(htmlString,['<tr><td>[^>]+>' keyword '.*?<\/tr>'],'match')
Try this
%<td>(.*?)%sg
https://regex101.com/r/0Xq0mO/1
Anyone know how to search by keyword through loggly JSON logs?
I have JSON logs with a key messageText and if I search for cat i want a log with messageText: "someone took a photo of their cat" which should return about a bajillion results, but instead it returns 0.
I have tried:
search json.messageText:cat
search json.messageText:%cat%
but I'm just gessing at this point. Loggly's help is unhelpful. It's entirely possible that this is not possible.
Try this:
search json.messageText:"*cat*"
I just spent an hour stuck on this one, too. Their "filter system" shows that they do a search on "json.key1.key2 : value8".
BUT, if you want to do the exact same search, you have to type in "key1.key2 : value8", which is essentially the same thing without the "json." at the beginning. The interface is very misleading and confusing about this.
So basically, don't put the "json." and the beginning of searches.
There is no need to type "search" at the beginning.
First, you can do a text-based search, on all fields, by just typing:
cat
Now, if you want to restrict your search to the field json.MessageText:
json.messageText:cat
First time implementing Full Text Search...
I've run the necessary ALTER TABLE SQL to enable FULLTEXT on the applicable tables/fields.
On the following beta site: http://wtc.betaforming.com/
If I do a search for "leadership", I get normal results except for the Events section at the bottom. I have Events with that word in the event title and throughout the description copy (http://wtc.betaforming.com/events/event/?event_id=10039).
If I do a search for "communications", I get results in the Events section, which makes me think I have everything configured correctly.
I'm using the following basic code for testing purposes:
SELECT *
FROM tblevents
WHERE MATCH(event_title, event_desc_long, event_desc_short, event_tab_one_title, event_tab_one_text, event_tab_two_title, event_tab_two_text, event_tab_three_title, event_tab_three_text, event_tab_four_title, event_tab_four_text) AGAINST ('$site_search_term')
This is the same code I'm using to search Products and Articles (changing the necessary FROM and WHERE information).
Not sure what is happening (since it works for some phrases) or where to start looking in my db to see what is wrong.
Thanks
Brett
The answer to my question can be found here:
http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
My search term was over the 50% threshold - you have to read all the way to the bottom to find this.
I've implemented the "IN BOOLEAN MODE" for my events search and everything appears to be working correctly. I also used this article for help:
http://devzone.zend.com/26/using-mysql-full-text-searching/
I need a search function for on an intranet , can I do this purely in HTML ? and if so could you possibly point me in the right direction , I tried googeling it but it came up with searching via search engines.
Cheers
EDIT: I only need it to search for text on 1 page , its not a whole website , just one page.
You will need some server-side scripting in order to provide the directory listings.
I recommend using PHP's glob function recursively, but there might be a better option.
Edit:
For one page, using JavaScript, you could get the contents of all of the elements, and use regex or indexOf to determine if the string exists within the text, and if so, where.
If you are to use the indexOf function, as the function only returns the index of the first occurrence of the string, you will need to repeat the search until you've gathered all occurrences.
You may specify the start parameter to snip the front of the searching area, to begin the new search after your last found occurrence.
In my MySQL DB I have a list of terms like this (With First letters Capital and most of the time plurals)
Hairdressers
Restaurants
Beauty Salons
Furnitures For Restaurants
On my website I have a search bar where the user can search for those word (my website is a kind of POI finder). The search bar has a auto-suggest function, but I'm having problems with my query.
SELECT * FROM TABLE WHERE word = 'userword%'
So if the user enter "Res" it will return all the word starting the "Res". Fair enough, that works, But in my DB i have also words with space between them (Furnitures For Restaurants) and I would like that if the user enter "Res" the mysql query ALSO return Furnitures For Restaurants. I have tried this
SELECT * FROM TABLE WHERE word = '%userword%'
Yes great this works, but... it is a bit to much relax.. it return all and everything, so if the user enters "a" it will return all the word having a in it... And I don't want this.
So how can make the query works only on the FIRST letters of each word ? Exactly like my first query but taking in consideration words with spaces?
Look into mysql FULL Text Search feature. Look at this article too, explains mysql full text searching in a very detailed way.