English 中文(简体)
2. 寻找一个插图,以对应一个引语和其他关键词
原标题:Searching a string for a match on a quoted phrase and other keywords

作为我试图完成的工作的一个实例,这里有一些法典列出了一份有缩略财产的书籍清单,称为Sentence

public class Book {
    public string Sentence { get; set; }
}

Book book1 = new Book() { Sentence = "The quick brown fox jumps over the lazy dog" };
Book book2 = new Book() { Sentence = "The quick brown frog jumps over the lazy sloth" };

List<Book> books = new List<Book>();

books.Add(book1);
books.Add(book2);

我想根据一些用户的投入,通过书目清单查询(查询要求比这一例子更加复杂)。

如果用户提供<代码>quick fox“lazy dog”的搜索短语,那么我就回去了一份清单,该清单有1本书作为收集工作的一部分。 如果用户提供<代码>quick fox sloth的检索短语,则不应再作复,因为这三字并非都出现在任何特性中。

<<>Summary

  1. quick fox “lazy dog” - 1 Result(引文中的词语一起出现,其余词语单独出现)

  2. <代码>> - 1 Result(两字在插图中同时出现)

  3. lazy sloth - 1 Result(两字都出现在插图中)

现行法典:

//Turn the search word into an array of words (includes support for quotes phrases).  E.g: quick fox "lazy dog" becomes a list of these values: `quick`, `fox`, `lazy dog`.
var searchWords = Regex.Matches(searchWord, @"(?<match>w+)|""(?<match>[ws]*)""")
                       .Cast<Match>()
                       .Select(m => m.Groups["match"].Value)
                       .ToList();

var query = from b in books
            where (!string.IsNullOrEmpty(b.Sentence) && searchWords.Any(b.Sentence.Contains))
            select b;

个案工作 2. 我现在看一看一看一看,如果一看一看一看,那么我就认为该项目。

最佳回答

我认为,你可能希望<代码>All( LINQ)方法做到:

var query = from b in books
            where (!string.IsNullOrEmpty(b.Sentence) && searchWords.All(word => b.Sentence.Contains(word)))
            select b;
问题回答

不用重新发明轮式I,将使用Lucene.Net。 甚至不需要软盘上的指数。 所有指数+研究可在记忆中进行(使用Lucene s RamDirectory)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签