HOWTO:C#字符串到SQL全文目录搜索?

编程入门 行业动态 更新时间:2024-10-25 04:23:43
本文介绍了HOWTO:C#字符串到SQL全文目录搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有像这样的一些搜索查询:

乔治和NOT华盛顿和亚伯拉罕

狗或猫,不是狼

针对这些搜索我要回去了的乔治或亚伯拉罕结果但华盛顿的等。

基本上我想借此字符串,并可以提交一个上下文搜索到我的全文目录存储过程的搜索。

我假设我应该使用正则表达式,但我很熟悉正则表达式在C#。

我发现这文章: support.microsoft/kb/246800 我认为这是我。需要做的,但我希望我能有一些帮助,实施

假设你把一个字符串作为参数,并想返回一个字符串:

字符串输入='乔治·华盛顿AND NOT玛莎或狗'; 私人字符串interpretSearchQuery(输入) { // HALP! / *替换和| 而不是与 *和 *而不是 * *代替'或'| OR NOT与 *或 *OR NOT * *添加到字符串的开头和结束串 *的/ 返回'乔治·华盛顿,而不是玛莎或狗'; }

解决方案

我会使用解析您的字符串后缀表示法(或波兰式)。

** Postfix的算法** 中的算法评估任何后缀表达式是相当简单: 虽然有输入记号留下 读取输入的下一个标记。 。如果标记是一个价值其推入堆栈。 否则,该标记是一个运营商(运营商这里既包括运算符和函数)。 已知的先验,操作者需要n个参数。 。如果有对堆栈(错误)用户大于n的值少具有在表达式未输入足够的值。 ,否则,从栈中弹出的前n值。 评估运营商,拥有该值作为参数。 按下返回的结果,如果有的话,背面压入堆栈。 。如果只有一个在堆栈该值的值是计算的结果。 。如果有在堆栈(错误)的用户输入有值过多多个值。

所以,把你的输入字符串:

乔治·华盛顿和不玛莎或狗

和它simplifing为:

A =乔治 b =华盛顿 C =玛莎 D =狗 &安培; = AND ! = NOT | = OR

我们将获得的

后缀符号!

AB和C开发|

这意味着:

  • 推值A(乔治)
  • 推值b(华盛顿)
  • 和弹出前两个值和推动的结果(George和华盛顿)
  • 推值C(玛莎)
  • 不要通过弹出前两个值和推动的结果(乔治和华盛顿)NOT(玛莎)
  • 推值D(狗)
  • 或弹出前两个值和推动的结果((George和华盛顿)NOT(玛莎))OR(狗)
  • I have some search queries like so:

    George AND NOT Washington OR Abraham

    Dog OR cat AND NOT Wolf

    for these searches I would want to get back results for George or Abraham but not Washington, etc.

    basically I want to take the string and be able to submit a contextual search to my full-text catalog stored procedure search.

    I am assuming I should use Regex but I am very unfamiliar with Regex in C#.

    I found this article: support.microsoft/kb/246800 which I think is what I need to do, but I was hoping that I could have some help with the implementation.

    Assuming you take a string as parameter and would like to return a string:

    string input = 'George Washington AND NOT Martha OR Dog'; private string interpretSearchQuery(input) { // HALP! /* replace ' AND ' | ' AND NOT ' with * " AND " * " AND NOT " * * replace ' OR ' | ' OR NOT ' with * " OR " * " OR NOT " * * add " to beginning of string and " to end of string */ return '"George Washington" AND NOT "Martha" OR "Dog"'; }

    解决方案

    I would parse your string using Postfix notation (or Polish notation).

    **Postfix algorithm** The algorithm for evaluating any postfix expression is fairly straightforward: While there are input tokens left Read the next token from input. If the token is a value Push it onto the stack. Otherwise, the token is an operator (operator here includes both operators, and functions). It is known a priori that the operator takes n arguments. If there are fewer than n values on the stack (Error) The user has not input sufficient values in the expression. Else, Pop the top n values from the stack. Evaluate the operator, with the values as arguments. Push the returned results, if any, back onto the stack. If there is only one value in the stack That value is the result of the calculation. If there are more values in the stack (Error) The user input has too many values.

    So taking your input string:

    'George Washington AND NOT Martha OR Dog'

    And simplifing it to:

    A = George B = Washington C = Martha D = Dog & = AND ! = NOT | = OR

    We would get the postfix notation of

    AB&C!D|

    Which means:

  • Push value A (George)
  • Push value B (Washington)
  • AND by popping previous two values and pushing the result (George AND Washington)
  • Push value C (Martha)
  • NOT by popping previous two values and pushing the result (George AND Washington) NOT (Martha)
  • Push value D (Dog)
  • OR by popping previous two values and pushing the result ((George AND Washington) NOT (Martha)) OR (Dog)
  • 更多推荐

    HOWTO:C#字符串到SQL全文目录搜索?

    本文发布于:2023-10-25 18:26:35,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1527736.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字符串   目录   全文   HOWTO   SQL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!