EdiWang / Moonglade

The ASP.NET Core blog system of https://edi.wang, runs on Microsoft Azure
https://edi.wang
GNU General Public License v3.0
516 stars 137 forks source link

Search in blog content #300

Open Anduin2017 opened 4 years ago

Anduin2017 commented 4 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to edi.wang
  2. Click on search
  3. See error

Expected behavior A clear and concise description of what you expected to happen.

I can search the content in any blog.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context

I can't get the search result if the title do not contains my search content.

EdiWang commented 4 years ago

This could be done via Azure Cognitive Search, but it will make the blog system couple with Azure again.

Anduin2017 commented 4 years ago

You shall make this feature an abstract: ISearchEngine.

And first implement it with Azure Cognitive Search. If the user hates Azure, you can provider another option to search in database.

public interface ISearchEngine
{
    List<Blog> Search(string input)
}
EdiWang commented 4 years ago

@Anduin2017 good idea, hate Azure and search 996!

hez2010 commented 4 years ago

Since you're using SQL Server for database, why not use its integrated full-text search service?

EdiWang commented 4 years ago

Hi @hez2010 full-text search is perfect for searching blog content, but I can't use it because full-text search will require extra installation and configuration for SQL Server, not every user of Moonglade has the administrative permission to modify their SQL Server deployment. Especially for users on non-Azure clouds, or even using classic SQL Server services by many Chinese ISPs, they don't have full-text search enabled.

I don't want to roughly implement the content search by "LIKE %XXXX%", the closest I can think of is to "LIKE %XXXX%" the post content abstract (initial 400 words) instead of full post content. But it isn't perfect as well.

EdiWang commented 4 years ago

I am now thinking about enabling full-text search as a switch in system settings, turned off by default, so that users with full-text search support on their SQL Server can turn on this switch to allow Moonglade search content in blog posts.

EdiWang commented 4 years ago

For reference: https://docs.microsoft.com/en-us/sql/relational-databases/search/full-text-search?view=sql-server-ver15 https://docs.microsoft.com/en-us/sql/relational-databases/search/query-with-full-text-search?view=sql-server-ver15

EdiWang commented 4 years ago

To enable full-text search:

CREATE FULLTEXT CATALOG MoongladeFTCat AS default
GO

DROP FULLTEXT INDEX ON Post
GO

CREATE FULLTEXT INDEX ON Post(PostContent)  
KEY INDEX PK_Post
WITH CHANGE_TRACKING AUTO
GO

Test full-text search

SELECT Id, Title, ContentAbstract
FROM Post
WHERE CONTAINS(PostContent, '"ASP.NET Core"')
manaatmoon commented 4 years ago

I just successfully deploy your code onto my own azure web app service https://manaatmoonblog.azurewebsites.net/. Since i don't know if there is any legal requirement, so please let me know if i need to obey any rules.

misaya commented 3 years ago

You shall make this feature an abstract: ISearchEngine.

And first implement it with Azure Cognitive Search. If the user hates Azure, you can provider another option to search in database.

public interface ISearchEngine
{
    List<Blog> Search(string input)
}

If Users hate Azure,let he/she go away.

Anduin2017 commented 2 years ago

Any plan for this feature?

Anduin2017 commented 2 years ago

Any update on this? @EdiWang

EdiWang commented 2 years ago

Hi @Anduin2017 this feature may come when UWP is revived