Whenever we use hashtag for searching that always results from a single tag (except Tumblr).
Just wondering is there a search engine allows multiple tag search?
I suppose that using different combination of tags could be fun and accurate:
#A general results
#A, #B more specific
#A, #B, #C, #D close to the truth what attributes (tags) are given.
Is any website served in this way?
Or how can I build a database to make this happened?
Thank you a lot.
This is old and written in VB but the principle I think will work for you.
This code is not completely limiting to Images that have all of the tags it is instead pushing the images with the most tag hits to the top.
This code works from the idea of show the user what fits best first but then give them other options below. Where as your AND scenario would cut out something that worked for 4 out of 5 of the tags. In this scenario they would just show below tags that had 5 out of 5.
So if you had some images with tags like:
Given:
Image1 woman,dog,panda
Image2 woman,telephone,smiling
Image3 man,dog,panda,banana
Image4 man,telephone,smiling
Yield:
A tag search of "telephone smiling" would score [Image2] and [Image4] to the top of the listing.
A tag search of "panda" would only yield Image1 and Image3.
A tag search of "man dog panda banana" Would yield Image3 as the top followed by Image1 followed by Image4.
This implementation is for finding the best image based on tags.
You create 3 tables in your SQL database as such (if you are doing webpages or stories or whatever change image to that for your own clarity):
SQL Tables:
imageTag [INT ID, String Tag]
imageImages [INT ID, NVARCHAR(2000) Path]
imageConnections [INT TagID, INT ImageID]
VB.NET Code:
'The beef of the SQL statement to get the scored results is here.
Dim SearchString As String =
"SELECT it.path, count(it.path) AS cnt, it.Id, it.name, it.description, it.updated FROM imageimages AS it, imageconnections AS itt, imagetags AS t WHERE " + _
"{REPLACE-TAG} AND t.id = itt.tagid AND it.id = itt.imageid " + _
"GROUP BY Path, it.ID, it.name, it.description, it.updated ORDER BY cnt DESC"
Dim keywords As String() = tstSearch.Text.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)
If keywords.Length > 0 Then
Dim strReplacement As String
strReplacement = "( tag = '" + keywords(0) + "'"
If keywords.Length > 1 Then
For i As Integer = 1 To keywords.Length - 1
strReplacement += " OR tag = '" + keywords(i) + "'"
Next
End If
strReplacement += " )"
SearchString = SearchString.Replace("{REPLACE-TAG}", strReplacement)
dt = tran.GetDataTable(SearchString)
End If
Related
Using SSIS I am bringing in raw text files that contain this in the output:
I use this data later to report on. The Key columns get pivoted. However, I don't want to show all those columns individually, I only want to show the total.
To accomplish this my idea was calculate the Sum on insert using a trigger, and then insert the sum as a new row into the data.
The output would look something like:
Is what I'm trying to do possible? Is there a better way to do this dynamically on pivot? To be clear I'm not just pivoting these rows for a report, there are other ones that don't need the sum calculated.
Using derived column and Script Component
You can achieve this by following these steps:
Add a derived column (name: intValue) with the following expression:
(DT_I4)(RIGHT([Value],2) == "GB" ? SUBSTRING([Value],1,FINDSTRING( [Value], " ", 1)) : "0")
So if the value ends with GB then the number is taken else the result is 0.
After that add a script component, in the Input and Output Properties, click on the Output and set the SynchronousInput property to None
Add 2 Output Columns outKey , outValue
In the Script Editor write the following script (VB.NET)
Private SumValues As Integer = 0
Public Overrides Sub PostExecute()
MyBase.PostExecute()
Output0Buffer.AddRow()
Output0Buffer.outKey = ""
Output0Buffer.outValue = SumValues.ToString & " GB"
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Output0Buffer.AddRow()
Output0Buffer.outKey = Row.Key
Output0Buffer.outValue = Row.Value
SumValues += Row.intValue
End Sub
I am going to show you a way but I don't recommend adding total to the end of the detail data. If you are going to report on it show it as a total.
After source add a data transformation:
C#
Add two columns to your data flow: Size int and type string
Select Value as readonly
Here is the code:
string[] splits = Row.value.ToString().Split(' '); //Make sure single quote for char
int goodValue;
if(Int32.TryParse(splits[0], out goodValue))
{
Row.Size = goodValue;
Row.Type = "GB";
}
else
{
Row.Size = 0;
Row.Type="None";
}
Now you have the data with the proper data types to do arithmatic in your table.
If you really want the data in your format. Add a multicast and an aggregate and SUM(Size) and then merge back into your original flow.
I was able to solve my problem in another way using a trigger.
I used this code:
INSERT INTO [Table] (
[Filename]
, [Type]
, [DeviceSN]
, [Property]
, [Value]
)
SELECT ms.[Filename],
ms.[Type],
ms.[DeviceSN],
'Memory Device.Total' AS [Key],
CAST(SUM(CAST(left(ms.[Value], 2) as INT)) AS VARCHAR) + ' GB' as 'Value'
FROM [Table] ms
JOIN inserted i ON i.Row# = ms.Row#
WHERE ms.[Value] like '%GB'
GROUP BY ms.[filename],
ms.[type],
ms.[devicesn]
I am working on a AddIn which is based on VBA. I import data from XML file. I want to apply filter on that data. I don't know how can I store and organize data.
XML File:
<?xml version="1.0"?>
<TestClass>
<TestObject>
<Site>Facebook</Site>
<Name>ABC</Name>
<URL>https://www.facebook.com/ABC/</URL>
</TestObject>
<TestObject>
<Site>Facebook</Site>
<Name>XYZ</Name>
<URL>https://www.facebook.com/XYZ/</URL>
</TestObject>
<TestObject>
<Site>Twitter</Site>
<Name>ABC</Name>
<URL>https://www.twitter.com/ABC/</URL>
</TestObject>
<TestObject>
<Site>Facebook</Site>
<Name>XYZ</Name>
<URL>https://www.twitter.com/XYZ/</URL>
</TestObject>
</TestClass>
Here is my code.
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
XMLFileName = "C:\Users\abc\Desktop\TestFiles\TestData.xml"
oXMLFile.Load (XMLFileName)
Set Sites = oXMLFile.SelectNodes("TestClass/TestObject/Site/text()")
Set Names = oXMLFile.SelectNodes("TestClass/TestObject/Name/text()")
Set URLs = oXMLFile.SelectNodes("TestClass/TestObject/URL/text()")
Public SiteArray(100) As String
Public NameArray(100) As String
Public URLArray(100) As String
For i = 0 To (Sites.Length - 1)
SiteArray(i) = Sites(i).NodeValue
NameArray(i) = Names(i).NodeValue
URLArray(i) = URLs(i).NodeValue
Next
Now I don't know how to get list of Name where Site is Facebook. I also want to get list of URL of Twitter.
Can anybody please suggest me mechanism for filtering in above case?
Based on what you've said you want, I've amended your code and added comments to explain what I'm doing:
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
XMLFileName = "C:\Users\abc\Desktop\TestFiles\TestData.xml"
oXMLFile.Load (XMLFileName)
Set Sites = oXMLFile.SelectNodes("TestClass/TestObject/Site/text()")
Set Names = oXMLFile.SelectNodes("TestClass/TestObject/Name/text()")
Set URLs = oXMLFile.SelectNodes("TestClass/TestObject/URL/text()")
Public myArray() As String ' declare array as dynamic so we can amend its size
ReDim myArray(6,0) ' reset it to be 2 dimensional
For i = 0 To (Sites.Length - 1)
myArray(0,i) = Sites(i).NodeValue ' Column 1 of the array contains Sites
myArray(1,i) = Names(i).NodeValue ' Column 2 of the array contains Names
myArray(2,i) = URLs(i).NodeValue ' Column 3 of the array contains URLs
myArray(3,i) = URLs(i).NodeValue ' Column 4 of the array contains URLs
myArray(4,i) = URLs(i).NodeValue ' Column 5 of the array contains URLs
myArray(5,i) = URLs(i).NodeValue ' Column 6 of the array contains URLs
myArray(6,i) = URLs(i).NodeValue ' Column 7 of the array contains URLs
ReDim Preserve myArray(6, UBound(myArray,2)+1) ' increase the size of the array dynamically to include an extra "row" of data
Next
' Now you can loop through and search for anything you want, like so:
For i = 0 to UBound(myArray, 2) ' loop through all the "rows" of the array
If Instr(LCase(myArray(0,i)), "facebook") > 0 Then ' If the site contains facebook
myName = myArray(1, i) ' returns the associated name for the Site
myURL = myArray(2, i) ' returns the associated URL for the Site
' Do whatever you need with this info then let the loop continue through the rest of the rows or use an Exit For statement to break the loop
End If
Next
I have a Database that I need to use, but it has some errors which I have to fix.
Since I am not an expert in MS-Access, I can not figure out where the mistakes are.
The first error
Run-time. Could not find field '| 1' to which reference is made in the expression.
is thrown when pressing the print button.
Opening the debug, I found this piece of code:
Private Sub Pulsante40_Click()
If Me!Campo51 = False Then
Select Case [schede]![S_Stampa_Ordini].[ordinamento]
Case 1
DoCmd.OpenReport "Stampa Ordini BY DATA", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
Case 2
DoCmd.OpenReport "Stampa Ordini BY CLIENTE", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
Case 3
DoCmd.OpenReport "Stampa Ordini BY LAVORAZION", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
Case 4
DoCmd.OpenReport "Stampa Ordini BY DATA_CONS", , , " (DATA_AGG Between #" & Format$(Me.[Dal], "mm/dd/yyyy") & "# And #" & Format$(Me.[Al], "mm/dd/yyyy") & " 23:59#) AND Tipo = """ & Me.TipoL & """"
End Select
FDipendente = 0
Else
DoCmd.OpenForm "FiltroStampa", , , , , A_DIALOG
End If
End Sub
It gives me error on line:
Select Case [schede]![S_Stampa_Ordini].[ordinamento]
The second error
Compile Error, could not find the method or data member
is thrown when I open the mask minutes and select
Legno, or Lavorazione Ext
code:
Private Sub Tipo_AfterUpdate()
Select Case Me.Tipo
Case "C"
Me.[SSMin-In].scheda.testo0.Caption = "Lavorazione:"
Case "L"
Me.[SSMin-In].scheda.testo0.Caption = "Cod.Prev.:"
Case "E"
Me.[SSMin-In].scheda.testo0.Caption = "Cod.Prev.:"
End Select
End Sub
It gives me the error on line:
Private Sub Tipo_AfterUpdate()
It has been days that I'm trying to solve the Database, or at least to start studying the visual basic to understand something. Unfortunately I only know java and my colleagues can not help me. Thank you in advance for an answer and I apologize if I was unclear or did not provide enough information.
It looks to me like your code is trying to refer to controls on your form, but in an invalid way (I can't quite understand what the code is trying to do because I don't read the language, and I don't know what controls you have on the form).
For example, to get the value of a combo box on a form, you would normally type something like Me.cboMyCombo.Value. To get the value of a field bound to this form, you would type something like Me!MyField or Me![My Field].Value.
Your calls to [schede]![S_Stampa_Ordini].[ordinamento] and Me.[SSMin-In].scheda.testo0.Caption look like they have a few too many methods on the end.
One way to find out what methods are acceptable is to start typing and let the pop-up menus guide you. For example, type Me. and see what pops up. In my example, cboMyCombo would be one of the items in the menu. Choose it, and you will see a new menu with Value as a choice.
You can also use the 'Expression Builder'.
You might want to try to copy your SQL into a query (or two). Make sure they actually produce the results you want. Then, you can call DoCmd.OpenQuery "qappYourNewQueryName". It is easier to read.
INSERT INTO [MIN-OUT]
( LAVORAZION, TIPO, MINUTI )
SELECT DISTINCTROW
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO,
0 FROM [MIN-IN]
GROUP BY
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO;
' What is this?
, ID_Dipendente )
SELECT DISTINCTROW
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO,
[Forms]![Minuti].[dipendente] AS Espr1
FROM [MIN-IN]
GROUP BY
[MIN-IN].LAVORAZION,
[MIN-IN].TIPO,
[Forms]![Minuti].[dipendente];")
I run a insert statement on ruby on rails. But failed. This is the code:
class BookmarkController < ApplicationController
def index
if request.post?
#user_new = Bookmark.new(params[:user_new])
tags = #user_new.tags.split(",")
#user_new = Bookmark.new(params[:user_new])
query = "INSERT INTO bookmark (title , url, tags) VALUES (#{#user_new.title}, #{#user_new.url}, #{tags[0]}) "
Bookmark.connection.execute(query);
end
end
But the output is :
ActiveRecord::StatementInvalid in BookmarkController#index
SQLite3::SQLException: near ".": syntax error: INSERT INTO bookmark (title , url, tags) VALUES (abhir, www.mrabhiram.tumblr.com, tumblr)
Can anyone suggest me the proper way to insert records using SQL insert statement?
Assuming Bookmark is subclassed from ActiveRecord, AR will save this for you - no need to write custom SQL - the save method will take care of this. You can read more about relevant ActiveRecord functionality here
class BookmarkController < ApplicationController
def index
if request.post?
#user_new = Bookmark.new(params[:user_new])
tags = #user_new.tags.split(",")
#user_new = Bookmark.new(params[:user_new])
#query = "INSERT INTO bookmark (title , url, tags) VALUES (#{#user_new.title}, #{#user_new.url}, #{tags[0]}) "
#Bookmark.connection.execute(query);
# The save method will insert the record into the database.
#user_new.save()
end
end
You can write
MOdel.connection.insert("INSERT INTO table_name(fields) VALUES('value')")
it's working...
You need quotes on your 'values' data. Something like:
query = "INSERT INTO bookmark (title , url, tags) VALUES ('#{#user_new.title}', '#{#user_new.url}', '#{tags[0]}') "
We have a web application that uses SQL Server 2008 as the database. Our users are able to do full-text searches on particular columns in the database. SQL Server's full-text functionality does not seem to provide support for hit highlighting. Do we need to build this ourselves or is there perhaps some library or knowledge around on how to do this?
BTW the application is written in C# so a .Net solution would be ideal but not necessary as we could translate.
Expanding on Ishmael's idea, it's not the final solution, but I think it's a good way to start.
Firstly we need to get the list of words that have been retrieved with the full-text engine:
declare #SearchPattern nvarchar(1000) = 'FORMSOF (INFLECTIONAL, " ' + #SearchString + ' ")'
declare #SearchWords table (Word varchar(100), Expansion_type int)
insert into #SearchWords
select distinct display_term, expansion_type
from sys.dm_fts_parser(#SearchPattern, 1033, 0, 0)
where special_term = 'Exact Match'
There is already quite a lot one can expand on, for example the search pattern is quite basic; also there are probably better ways to filter out the words you don't need, but it least it gives you a list of stem words etc. that would be matched by full-text search.
After you get the results you need, you can use RegEx to parse through the result set (or preferably only a subset to speed it up, although I haven't yet figured out a good way to do so). For this I simply use two while loops and a bunch of temporary table and variables:
declare #FinalResults table
while (select COUNT(*) from #PrelimResults) > 0
begin
select top 1 #CurrID = [UID], #Text = Text from #PrelimResults
declare #TextLength int = LEN(#Text )
declare #IndexOfDot int = CHARINDEX('.', REVERSE(#Text ), #TextLength - dbo.RegExIndexOf(#Text, '\b' + #FirstSearchWord + '\b') + 1)
set #Text = SUBSTRING(#Text, case #IndexOfDot when 0 then 0 else #TextLength - #IndexOfDot + 3 end, 300)
while (select COUNT(*) from #TempSearchWords) > 0
begin
select top 1 #CurrWord = Word from #TempSearchWords
set #Text = dbo.RegExReplace(#Text, '\b' + #CurrWord + '\b', '<b>' + SUBSTRING(#Text, dbo.RegExIndexOf(#Text, '\b' + #CurrWord + '\b'), LEN(#CurrWord) + 1) + '</b>')
delete from #TempSearchWords where Word = #CurrWord
end
insert into #FinalResults
select * from #PrelimResults where [UID] = #CurrID
delete from #PrelimResults where [UID] = #CurrID
end
Several notes:
1. Nested while loops probably aren't the most efficient way of doing it, however nothing else comes to mind. If I were to use cursors, it would essentially be the same thing?
2. #FirstSearchWord here to refers to the first instance in the text of one of the original search words, so essentially the text you are replacing is only going to be in the summary. Again, it's quite a basic method, some sort of text cluster finding algorithm would probably be handy.
3. To get RegEx in the first place, you need CLR user-defined functions.
It looks like you could parse the output of the new SQL Server 2008 stored procedure sys.dm_fts_parser and use regex, but I haven't looked at it too closely.
You might be missing the point of the database in this instance. Its job is to return the data to you that satisfies the conditions you gave it. I think you will want to implement the highlighting probably using regex in your web control.
Here is something a quick search would reveal.
http://www.dotnetjunkies.com/PrintContent.aspx?type=article&id=195E323C-78F3-4884-A5AA-3A1081AC3B35
Some details:
search_kiemeles=replace(lcase(search),"""","")
do while not rs.eof 'The search result loop
hirdetes=rs("hirdetes")
data=RegExpValueA("([A-Za-zöüóőúéáűíÖÜÓŐÚÉÁŰÍ0-9]+)",search_kiemeles) 'Give back all the search words in an array, I need non-english characters also
For i=0 to Ubound(data,1)
hirdetes = RegExpReplace(hirdetes,"("&NoAccentRE(data(i))&")","<em>$1</em>")
Next
response.write hirdetes
rs.movenext
Loop
...
Functions
'All Match to Array
Function RegExpValueA(patrn, strng)
Dim regEx
Set regEx = New RegExp ' Create a regular expression.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True
Dim Match, Matches, RetStr
Dim data()
Dim count
count = 0
Redim data(-1) 'VBSCript Ubound array bug workaround
if isnull(strng) or strng="" then
RegExpValueA = data
exit function
end if
regEx.Pattern = patrn ' Set pattern.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
count = count + 1
Redim Preserve data(count-1)
data(count-1) = Match.Value
Next
set regEx = nothing
RegExpValueA = data
End Function
'Replace non-english chars
Function NoAccentRE(accent_string)
NoAccentRE=accent_string
NoAccentRE=Replace(NoAccentRE,"a","§")
NoAccentRE=Replace(NoAccentRE,"á","§")
NoAccentRE=Replace(NoAccentRE,"§","[aá]")
NoAccentRE=Replace(NoAccentRE,"e","§")
NoAccentRE=Replace(NoAccentRE,"é","§")
NoAccentRE=Replace(NoAccentRE,"§","[eé]")
NoAccentRE=Replace(NoAccentRE,"i","§")
NoAccentRE=Replace(NoAccentRE,"í","§")
NoAccentRE=Replace(NoAccentRE,"§","[ií]")
NoAccentRE=Replace(NoAccentRE,"o","§")
NoAccentRE=Replace(NoAccentRE,"ó","§")
NoAccentRE=Replace(NoAccentRE,"ö","§")
NoAccentRE=Replace(NoAccentRE,"ő","§")
NoAccentRE=Replace(NoAccentRE,"§","[oóöő]")
NoAccentRE=Replace(NoAccentRE,"u","§")
NoAccentRE=Replace(NoAccentRE,"ú","§")
NoAccentRE=Replace(NoAccentRE,"ü","§")
NoAccentRE=Replace(NoAccentRE,"ű","§")
NoAccentRE=Replace(NoAccentRE,"§","[uúüű]")
end function