Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:50:26+00:00 2026-06-11T16:50:26+00:00

I need to implement a process, wherein a text file of roughly 50/150kb is

  • 0

I need to implement a process, wherein a text file of roughly 50/150kb is uploaded, and matched against a large number of phrases (~10k).

I need to know which phrases match specifically.

A phrase could be “blah blah blah” or just “blah” – meaning I need to take word-boundaries into account, as I don’t wish to include infix matches.

My first attempt was to just create a large pre-compiled list of regular expressions that look like @"\b{0}\b" (as 10k the phrases are constant – I can cache & re-use this same list against multiple documents);

On my brand-new & very fast PC – this matching is taking 10 seconds+, which I would like to be able to reduce a great deal.

Any advice on how I may be able to achieve this would be greatly appreciated!

Cheers,
Dave

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:50:27+00:00Added an answer on June 11, 2026 at 4:50 pm

    You could Lucene.NET and the Shingle Filter as long as you don’t mind having a cap on the number of possible words as phrase can have.

    public class MyAnalyzer : Analyzer
    {
        public override TokenStream TokenStream(string fieldName, TextReader reader)
        {       
            return new ShingleFilter(new LowerCaseFilter(new StandardTokenizer(Lucene.Net.Util.Version.LUCENE_29, reader)), 6);
        }
    }
    

    You can run the analyzer using this utility method.

    public static IEnumerable<string> GetTerms(Analyzer analyzer, string keywords)
    {
        var tokenStream = analyzer.TokenStream("content", new StringReader(keywords));
        var termAttribute = tokenStream.AddAttribute<ITermAttribute>();
    
        var terms = new HashSet<string>();
        
        while (tokenStream.IncrementToken())
        {
            var term = termAttribute.Term;
            if (!terms.Contains(term))
            {
                terms.Add(term);
            }
        }
    
        return terms;
    }
    

    Once you’ve retrieved all the terms do an intersect with you words list.

    var matchingShingles = GetTerms(new MyAnalyzer(), "Here's my stuff I want to match");
    
    var matchingPhrases = phrasesToMatch.Intersect(matchingShingles, StringComparer.OrdinalIgnoreCase);
    

    I think you will find this method is much faster than Regex matching and respects word boundries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to process a large number of records (several million) representing people. I
I need to implement a thread pool in Java (java.util.concurrent) whose number of threads
I need to implement a sort of task buffer. Basic requirements are: Process tasks
I need to implement inter-process communication system for processes (in machine-wide) in Win32 using
I need to implement a simple message bus: One process only thus no need
I need to implement a process where users punch in a few details into
I have no experience with sockets and I need to implement a process that
I need to implement a shell script that kills a process. The problem is
As a college project I need to implement a basic file system from within
I am a c# asp.net developer and need to implement a number of flash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.