How do I build a search mechanism for my application?

后端 未结 7 1604
我在风中等你
我在风中等你 2020-12-30 13:34

It seems to be a common requirement nowadays to have a search feature that can search almost anything you want. Can anyone give me samples or tips as to how to go about buil

相关标签:
7条回答
  • 2020-12-30 14:02

    Lucene.NET is an extremely fast full text search engine.

    Sample usage:

    See Source code of DotNetKicks starting from codebehind of search page

    0 讨论(0)
  • 2020-12-30 14:03

    To follow up on fallen888's answer:

    You could create a class with a method taking an array or list of search keywords for input. Create LINQ queries related to each table, and for instance use the "LIKE" operator in some of the ways explained in this blogpost to search the right columns for matching content. Of course, this will not be very optimized, but will work for small systems :)

    0 讨论(0)
  • 2020-12-30 14:09

    One way would be to find the searched value in all tables in the database. Of course this code can be altered to focus on specific tables and columns.

    0 讨论(0)
  • 2020-12-30 14:10

    If you want something really scalable, I guess you'll have to build first a data dictionnary, listing each table and each column in your database. The building of such a table can be fully automated.

    You will indicate in this table which fields are available for straight or soft (with wild card) searching.

    You'll then be able to build some nice and smart user interface where the machine will be able to find that a code such as '*823*' refer both to 'INV-0823456' and 'INV-0880823' invoice numbers, as long as invoice number field is available for soft searching. The user might even be given the option to choose which column(s) to search, as scanning all telephone numbers in the database might not allways make sense.

    You should not try to index all searchable columns. A "full-index" strategy can become very costy in termes of disk volume\server overhead, and will not allways make sense for rarely searched columns. Don't worry a lot about that: users will not mind some delay in getting their answer.

    0 讨论(0)
  • 2020-12-30 14:26

    Xapian is an Open Source Search Engine Library with the features you are seeking.

    0 讨论(0)
  • 2020-12-30 14:29

    If you are using SQL Server for your database then you can try SQL's full text search. I have used it quite successfully.

    0 讨论(0)
提交回复
热议问题