Free 3 Months
|
| |
| tianjie | Asp.Net User |
| How can I search the Ads description as well by clicking the normal search button? | 8/14/2007 4:22:45 AM |
0/0 | |
|
Hi there,
I'm using the Classifieds Starter Kit to develop a test website. I found that the normal search can only search the interested term within Ads title. Is there anyway that I can search the Ads description and even other attributes (ie. username)? I'm programming in VB. Any help is highly appreciated.
Thanks in advance.
Jay |
| darkknight187 | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/14/2007 2:07:41 PM |
0/0 | |
|
Hello Jay,
It's pretty easy for the most part. The file that does the physical work is in your stored procedure "GetAllAdsByQuery"
I guess if you wanted it to search for description it would look something like this, Description LIKE '%' + @SearchTerm + '%' AND
@SearchTerm represents the textbox id that is performing the search. So modify as needed.
If you add that to the search term it should allow you to still search for the title in the same box, otherwise replace title with description.
Good Luck, and have fun with it.
Daniel Meis
Be sure to visit www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you. This can be beneficial to other community members reading the thread. |
| tianjie | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/14/2007 7:04:11 PM |
0/0 | |
|
Hi Daniel,
Thanks for the quick reply. I tried your idea. The following is the code that i modified (see the bold). But it didn't work for me. Any one knows where else i should change? Thanks.
Jay
CREATE PROCEDURE GetAllAdsByQuery @LimitResultCount int = 100, @CategoryId int = 0, @MemberId int = 0, @MaxPrice money = -1, @SearchTerm nvarchar(50) = N'', @Location nvarchar(50) = N'', @AdType int = 0, @AdStatus int = 0, @AdLevel int = 0, @MinDateCreated smalldatetime = NULL, @MustHaveImage bit = false AS SET ROWCOUNT @LimitResultCount
SELECT * FROM ClassifiedsView_Ads WHERE (@CategoryId = 0 OR CategoryId IN ( SELECT Id FROM classifieds_Categories WHERE Path LIKE (SELECT Path FROM classifieds_Categories WHERE Id = @CategoryId ) + '%' )) AND (@MaxPrice = -1 OR Price <= @MaxPrice) AND (@MustHaveImage = 0 OR PreviewImageId IS NOT NULL) AND (@AdStatus = 0 OR AdStatus = @AdStatus) AND (@AdLevel = 0 OR AdLevel = @AdLevel) AND (@AdType = 0 OR AdType = @AdType) AND (@MemberId = 0 OR MemberId = @MemberId) AND (@MinDateCreated IS NULL OR DateCreated > @MinDateCreated) AND (Title LIKE '%' + @SearchTerm + '%' OR Description LIKE '%' + @SearchTerm + '%') AND (Location LIKE '%' + @Location + '%') ORDER BY PreviewImageId DESC, DateCreated DESC SET ROWCOUNT 0 GO
|
| darkknight187 | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/14/2007 11:11:03 PM |
0/0 | |
|
Instead of using the OR try copying the same searchterm twice such as.
Description LIKE '%' + @SearchTerm + '%' AND
Title LIKE '%' + @SearchTerm + '%' AND
so you just added the line, I didn't try it but it should work.
Be sure to visit www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you. This can be beneficial to other community members reading the thread. |
| darkknight187 | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/15/2007 3:05:07 AM |
0/0 | |
|
It was such a long time ago I guess I did more than I thought.
But when I added completly new search features I modified that file, and I think you're going to need to add Description to the top part.
The other files I modified was at the bottom of your search page you will find your adsearchdatabase.
And in the BLL folder in the GetAds section I modified the Ads.vb file.
Let me know if you have any trouble.
Good Luck
Be sure to visit www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you. This can be beneficial to other community members reading the thread. |
| darkknight187 | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/15/2007 2:47:47 PM |
0/0 | |
|
All of your .sql files are for uploading your database only, it put's your database together as it was originally, unmodified.
When you are ready to upload your database you can use a tool to generate your .sql with your current database state.
So that file you modified did nothing to help you. And the DAL/Ads.xsd file won't help you search either.
That file just points to the Stored procedure.
So for a Demo of my code there are three files, and you will notice that I have added several to my search,
For your use I would pretty much copy my loading of ZipCode, although in the stored procedure you may want to increase from nvarchar (50) to at least nvarchar (100) I'm not positive but I think it put's limits on the code.
First off you need to modify your stored procedure "GetAllAdsByQuery"
ALTER PROCEDURE GetAllAdsByQuery@LimitResultCount int = 50,
@CategoryId int = 0,@MemberId int = 0,
@MaxPrice money = -1,@PriceTo money = -1,
@PriceFrom money = -1,@BedsQuery money = -1,
@BathsQuery money = -1,@SqFeetQuery money = -1,
@SearchTerm nvarchar(50) = N'',@Location nvarchar(50) = N'',
@AdType int = 0,@ZipCode nvarchar(50) = N'',
@AdStatus int = 0,@AdLevel int = 0,
@MinDateCreated smalldatetime = NULL,@MustHaveImage bit = false
AS SET ROWCOUNT @LimitResultCount
SELECT *FROM ClassifiedsView_Ads
WHERE
(@CategoryId = 0 OR CategoryId IN (
SELECT Id FROM classifieds_Categories
WHERE Path LIKE(SELECT Path
FROM classifieds_Categories
WHERE Id = @CategoryId ) + '%'
)) AND
(@MaxPrice = -1 OR Price <= @MaxPrice) AND
(@PriceTo = -1 OR Price <= @PriceTo) AND
(@PriceFrom = -1 OR Price >= @PriceFrom) AND
(@BedsQuery = -1 OR Beds >= @BedsQuery) AND
(@BathsQuery = -1 OR Baths >= @BathsQuery) AND
(@SqFeetQuery = -1 OR SqFeet >= @SqFeetQuery) AND
(@MustHaveImage = 0 OR PreviewImageId IS NOT NULL) AND
(@AdStatus = 0 OR AdStatus = @AdStatus) AND
(@AdLevel = 0 OR AdLevel = @AdLevel) AND
(@AdType = 0 OR AdType = @AdType) AND
(@MemberId = 0 OR MemberId = @MemberId) AND
(@MinDateCreated IS NULL OR DateCreated > @MinDateCreated) AND
Location LIKE '%' + @SearchTerm + '%' AND
ZipCode LIKE '%' + @ZipCode + '%' AND
Location LIKE '%' + @Location + '%'
ORDER BY DateCreated DESC
SET ROWCOUNT 0
Next at the bottom of your search.aspx page you need to modify the object database, datasource.
< asp:ObjectDataSource ID="AdSearchDataSource" runat="server" TypeName="AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdsDB"
SelectMethod="GetActiveAdsByQuery" OldValuesParameterFormatString="original_{0}"><SelectParameters>
<asp:Parameter Type="Int32" DefaultValue="50" Name="recordLimit"></asp:Parameter>
<asp:ControlParameter Name="categoryId" DefaultValue="0" Type="Int32" ControlID="CategoryDropDown"
PropertyName="CurrentCategoryId"></asp:ControlParameter>
<asp:ControlParameter Name="memberId" ControlID="AdvancedSearch" PropertyName="MemberId"
Type="Int32" DefaultValue="0" />
<asp:ControlParameter Name="maxPrice" ControlID="AdvancedSearch" PropertyName="MaximumPrice"
Type="Decimal" DefaultValue="-1" />
<asp:ControlParameter Name="searchTerm" DefaultValue="" Type="String" ControlID="SearchTermTextBox"
PropertyName="Text"></asp:ControlParameter>
<asp:ControlParameter Name="location" ControlID="AdvancedSearch" PropertyName="Location"
Type="String" DefaultValue="" />
<asp:ControlParameter Name="adType" ControlID="AdTypeList" Type="Int32" DefaultValue="0" />
<asp:ControlParameter Name="ZipCode" DefaultValue="" Type="String" ControlID="ZipCodeQueryTB"
PropertyName="Text"></asp:ControlParameter>
<asp:Parameter Type="Int32" DefaultValue="0" Name="adLevel"></asp:Parameter>
<asp:ControlParameter Name="dayRange" ControlID="AdvancedSearch" PropertyName="DayRange"
Type="Int32" DefaultValue="-1" />
<asp:ControlParameter ControlID="PhotoCheckBox" DefaultValue="False" Name="MustHaveImage" Type="Boolean" />
<asp:ControlParameter ControlID="PriceToDropDown" DefaultValue="-1" Name="PriceTo" Type="Decimal" />
<asp:ControlParameter ControlID="PriceFromDropDown" DefaultValue="-1" Name="PriceFrom" Type="Decimal" />
<asp:ControlParameter ControlID="BedsQueryDropDown" DefaultValue="-1" Name="BedsQuery" Type="Decimal" />
<asp:ControlParameter ControlID="BathsQueryDropDown" DefaultValue="-1" Name="BathsQuery" Type="Decimal" />
<asp:ControlParameter ControlID="SqFeetQueryDropDown" DefaultValue="-1" Name="SqFeetQuery" Type="Decimal" />
</SelectParameters>
</asp:ObjectDataSource>
And finally there are two sections in the BLL/Ads.vb file in the get Ads section Public Shared Function GetActiveAdsByQuery(ByVal recordLimit As Integer, ByVal categoryId As Integer, ByVal memberId As Integer, ByVal maxPrice As Decimal, ByVal searchTerm As String, ByVal location As String, ByVal adType As Integer, ByVal ZipCode As String, ByVal adLevel As Integer, ByVal dayRange As Integer, ByVal mustHaveImage As Boolean, ByVal PriceTo As Decimal, ByVal PriceFrom As Decimal, ByVal BedsQuery As Decimal, ByVal BathsQuery As Decimal, ByVal SqFeetQuery As Decimal) As AdsDataComponent.AdsDataTable
Dim escapedSearchTerm As String = AdsDB.EscapeWildcardCharacters(searchTerm)Dim escapedLocation As String = AdsDB.EscapeWildcardCharacters(location)Return GetAdsByQuery(recordLimit, _
categoryId, memberId, maxPrice, _
HttpUtility.HtmlEncode(escapedSearchTerm), _
HttpUtility.HtmlEncode(escapedLocation), _ adType, ZipCode, CInt(AdStatus.Activated), _
adLevel, dayRange, mustHaveImage, _
PriceTo, PriceFrom, BedsQuery, BathsQuery, SqFeetQuery) End Function
Public Shared Function GetAdsByQuery(ByVal recordLimit As Integer, ByVal categoryId As Integer, ByVal memberId As Integer, ByVal maxPrice As Decimal, ByVal searchTerm As String, ByVal location As String, ByVal adType As Integer, ByVal ZipCode As String, ByVal adStatus As Integer, ByVal adLevel As Integer, ByVal dayRange As Integer, ByVal mustHaveImage As Boolean, ByVal PriceTo As Decimal, ByVal PriceFrom As Decimal, ByVal BedsQuery As Decimal, ByVal BathsQuery As Decimal, ByVal SqFeetQuery As Decimal) As AdsDataComponent.AdsDataTableDim minCreatedDate As System.Nullable(Of DateTime)
If location Is Nothing Then
location = ""
End If
If dayRange > 0 Then
minCreatedDate = DateTime.Now.Subtract(TimeSpan.FromDays(dayRange))
End If
' To return no results if the searchTerm is empty remove the following
' check on the searchTerm.
If searchTerm Is Nothing Then
searchTerm = ""
End If
If ZipCode Is Nothing Then
ZipCode = ""
End IfUsing db As New AdsDataAdapter()
Dim aa As AdsDataComponent.AdsDataTable = Nothing
aa = db.GetAllAdsByQuery(recordLimit, categoryId, memberId, maxPrice, searchTerm, location, adType, ZipCode, adStatus, adLevel, minCreatedDate, mustHaveImage, PriceTo, PriceFrom, BedsQuery, BathsQuery, SqFeetQuery) Return aa
End Using
End Function
That's it, but take note in my second step the ControlID="ZipCodeQueryTB" is pointing at my textbox Id name.
Good Luck
Daniel Meis
Be sure to visit www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you. This can be beneficial to other community members reading the thread. |
| tianjie | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/15/2007 8:10:56 PM |
0/0 | |
|
Your explaination did make a lot sense to me. I was following your instruction to achieve my goal but didn't quite get there yet. I'm grateful for your guidance and help.
Here is what I did and the error message i got:
In classifieds-add.sql
ALTER PROCEDURE GetAllAdsByQuery <ALTER was originall CREATE> @LimitResultCount int = 50, @CategoryId int = 0, @MemberId int = 0, @MaxPrice money = -1, @SearchTerm nvarchar(50) = N'', @Location nvarchar(50) = N'', @AdType int = 0, @Description ntext(500) = N'', <I added this line.> @AdStatus int = 0, @AdLevel int = 0, @MinDateCreated smalldatetime = NULL, @MustHaveImage bit = false AS SET ROWCOUNT @LimitResultCount
SELECT * FROM ClassifiedsView_Ads WHERE (@CategoryId = 0 OR CategoryId IN ( SELECT Id FROM classifieds_Categories WHERE Path LIKE (SELECT Path FROM classifieds_Categories WHERE Id = @CategoryId ) + '%' )) AND (@MaxPrice = -1 OR Price <= @MaxPrice) AND (@MustHaveImage = 0 OR PreviewImageId IS NOT NULL) AND (@AdStatus = 0 OR AdStatus = @AdStatus) AND (@AdLevel = 0 OR AdLevel = @AdLevel) AND (@AdType = 0 OR AdType = @AdType) AND (@MemberId = 0 OR MemberId = @MemberId) AND (@MinDateCreated IS NULL OR DateCreated > @MinDateCreated) AND Title LIKE '%' + @SearchTerm + '%' AND Description LIKE '%'+ @Description +'%' AND <I added this line> Location LIKE '%' + @Location + '%' ORDER BY DateCreated DESC SET ROWCOUNT 0 GO
In search.aspx
<asp:ControlParameter Name="location" ControlID="AdvancedSearch" PropertyName="Location" Type="String" DefaultValue="" /> <asp:ControlParameter Name="adType" ControlID="AdvancedSearch" PropertyName="AdType" Type="Int32" DefaultValue="0" /> <asp:ControlParameter Name="description" DefaultValue="" Type="String" ControlID="DescriptionTextBox" <PropertyName="Text"></asp:ControlParameter> <I added this line> <asp:Parameter Type="Int32" DefaultValue="0" Name="adLevel"></asp:Parameter> <asp:ControlParameter Name="dayRange" ControlID="AdvancedSearch" PropertyName="DayRange" Type="Int32" DefaultValue="-1" />
In BLL\Ads.vb
Public Shared Function GetActiveAdsByQuery(ByVal recordLimit As Integer, ByVal categoryId As Integer, ByVal memberId As Integer, ByVal maxPrice As Decimal, ByVal searchTerm As String, ByVal location As String, ByVal adType As Integer, ByVal description As String, ByVal adLevel As Integer, ByVal dayRange As Integer, ByVal mustHaveImage As Boolean) As AdsDataComponent.AdsDataTable
Dim escapedSearchTerm As String = AdsDB.EscapeWildcardCharacters(searchTerm) Dim escapedLocation As String = AdsDB.EscapeWildcardCharacters(location) Return GetAdsByQuery(recordLimit, _ categoryId, memberId, maxPrice, _ HttpUtility.HtmlEncode(escapedSearchTerm), _ HttpUtility.HtmlEncode(escapedLocation), _ adType, Description, CInt(AdStatus.Activated), _ adLevel, dayRange, mustHaveImage)
End Function
Public Shared Function GetAdsByQuery(ByVal recordLimit As Integer, ByVal categoryId As Integer, ByVal memberId As Integer, ByVal maxPrice As Decimal, ByVal searchTerm As String, ByVal location As String, ByVal adType As Integer, ByVal description As String, ByVal adStatus As Integer, ByVal adLevel As Integer, ByVal dayRange As Integer, ByVal mustHaveImage As Boolean) As AdsDataComponent.AdsDataTable Dim minCreatedDate As System.Nullable(Of DateTime) If location Is Nothing Then location = "" End If If dayRange > 0 Then minCreatedDate = DateTime.Now.Subtract(TimeSpan.FromDays(dayRange)) End If ' To return no results if the searchTerm is empty remove the following ' check on the searchTerm. If searchTerm Is Nothing Then searchTerm = "" End If If Description Is Nothing Then Description = "" End If
Using db As New AdsDataAdapter() Dim aa As AdsDataComponent.AdsDataTable = Nothing aa = db.GetAllAdsByQuery(recordLimit, categoryId, memberId, maxPrice, searchTerm, location, adType, description, adStatus, adLevel, minCreatedDate, mustHaveImage) Return aa End Using End Function
Error given me:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted to 'System.Nullable(Of Date)'.
Source Error:
|
Line 180: Using db As New AdsDataAdapter()
Line 181: Dim aa As AdsDataComponent.AdsDataTable = Nothing
Line 182: aa = db.GetAllAdsByQuery(recordLimit, categoryId, memberId, maxPrice, searchTerm, location, adType, description, adStatus, adLevel, minCreatedDate, mustHaveImage)
Line 183: Return aa
Line 184: End Using
| |
| darkknight187 | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/15/2007 8:30:06 PM |
0/0 | |
|
Alright, I think I got it.
Go into App_Data/DAL and right click on Ads.xsd select view code, one of the sections is GetAllAdsByQuerry, you need to add to that aswell.
Your error just hit me like a brick, sorry I forgot that one.
Don't forget to mark your question as answered when you get it.
Be sure to visit www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you. This can be beneficial to other community members reading the thread. |
| darkknight187 | Asp.Net User |
| Re: How can I search the Ads description as well by clicking the normal search button? | 8/19/2007 1:41:22 PM |
0/0 | |
|
There is only one line you need to modify to get it to seach for description.
In the stored procedure, "GetAllAdsByQuery" just the bottom part change Title to Description.
That's it. There is no other references, the only thing is it takes the place of searching for title.
So it's one or the other there.
If you would like both, untested but the active term is serchterm and you would need to copy that in all references, and then in your search page have searchterm and searchterm1 pointing to the same control. "SearchTermTextBox"
Be sure to visit www.detelli.comAnd please remember to click ?Mark as Answer? on the post that helps you. This can be beneficial to other community members reading the thread. |
|
| |
Free Download:
Books: How to Do Everything with Your IPod and IPod Mini Authors: Guy Hart-Davis, Pages: 416, Published: 2004 Audio Editing with Cool Edit Authors: Richard Riley, Pages: 160, Published: 2002 Web:Custom Search Engine Topic Refinement Notice that it looks very much like normal Google search results. Now click on the "Finish" button, and admire your (very short) list of custom search ... Creating Google Custom Search Engines | O'Reilly Media Sep 6, 2007 ... If I used the normal Google search page, I'd get over 2 million results and ... Log on to Google and click on the My Search Engines link. ... Google's "Edit Search results" experiment | justin hileman dot info If you want normal search results, you can use Google on its own without signing in. I suspect users can opt out as well when signed in though this ... Find broken links on your site with Xenu's Link Sleuth (TM) You can also click the "browse" button to check a local HTML file. .... To find where the site is, use web search engines (like Google or the Internet ... Search Engines and Frames - Search Engine Watch (SEW) Explains how to make a frames site accessible to search engines and humans without ... then return to this page (use your back button or click on the big, ... Implementing Search in ASP.NET with Google Custom Search Sep 15, 2008 ... You cannot make any AdSense income from the ads in the search results shown ... This displays the search box, but clicking the Search button ... BarelyBad Search - Map - Navigation You can search this site and see the site map, above, or you can keep reading. ... button icon, and you'll find one at the bottom as well as at the top of ... Less is more in Web search interfaces for older adults Etsin recognises Microsoft Word, Excel, and PowerPoint, as well as PDF files, ..... We will have a separate "Begin new search" button in the next version of ... PhilC’s Ramblings » Search engines, etc. When you type in a search term, and click the “ChaCha Search” button, ... take their chances with the ads and with the results from normal search engines. ... Inside AdSense: AdSense for search now powered by Custom Search Selecting ad location: Do you want ads to appear at the top and bottom of your search results? Or along the right sidebar as well, just like on Google.com? ... Videos: Web Applications and the Ubiquitous Web Google TechTalks
February 1, 2006
Dave Raggett
Dave Raggett is currently a W3C Fellow from Canon, and W3C Activity Lead for Multimodal Interaction.... |
|
Search This Site:
|
|