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 9061403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:28:33+00:00 2026-06-16T15:28:33+00:00

Hello I have a 32mb file. It is a simple dictionary file encoded 1250

  • 0

Hello I have a 32mb file. It is a simple dictionary file encoded 1250 with 2.8 million lines in it. Every line has only one unique word:

cat
dog
god
...

I want to use Lucene to search for every anagram in dictionary of specific word. For example:

I want to search every anagram of the word dog and lucene should search my dictionary and return dog and god. In my webapp I have a Word Entity:

public class Word {
    private Long id;
    private String word;
    private String baseLetters;
    private String definition;
}

and baseLetters is the variable which are sorted letters alphabetically for searching such anagrams [god and dog words will have the same baseLetters: dgo]. I succeeded in searching such anagrams from my database using this baseLetters variable in different service but I have problem to create index of my dictionary file. I know I have to add to fields:

word and baseLetters but I have no idea how to do it 🙁 Could someone show me some directions to achieve this goal?

For now I have only something like that:

public class DictionaryIndexer {

private static final Logger logger = LoggerFactory.getLogger(DictionaryIndexer.class);

@Value("${dictionary.path}")
private String dictionaryPath;

@Value("${lucene.search.indexDir}")
private String indexPath;

public void createIndex() throws CorruptIndexException, LockObtainFailedException {
    try {
        IndexWriter indexWriter = getLuceneIndexer();
        createDocument();           
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }       
 }

private IndexWriter getLuceneIndexer() throws CorruptIndexException, LockObtainFailedException, IOException {
    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
    IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_36, analyzer);
    indexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
    Directory directory = new SimpleFSDirectory(new File(indexPath));
    return new IndexWriter(directory, indexWriterConfig);
}

private void createDocument() throws FileNotFoundException {
    File sjp = new File(dictionaryPath);
    Reader reader = new FileReader(sjp);

    Document dictionary = new Document();
    dictionary.add(new Field("word", reader));
}

}

PS: One more question. If i register DocumentIndexer as a bean in Spring will the index be creating/appending every time I redeploy my webapp? and the same will be with the future DictionarySearcher?

  • 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-16T15:28:34+00:00Added an answer on June 16, 2026 at 3:28 pm

    The function createDocument() should be

    private void createDocument() throws FileNotFoundException {
        File sjp = new File(dictionaryPath);
        BufferedReader reader = new BufferedReader(new FileReader(sjp));
    
        String readLine = null;
        while((readLine = reader.readLine() != null)) {
            readLine = readLine.trim();
            Document dictionary = new Document();
            dictionary.add(new Field("word", readLine));
            // toAnagram methods sorts the letters in the word. Also makes it
            // case insensitive.
            dictionary.add(new Field("anagram", toAnagram(readLine)));
            indexWriter.addDocument(dictionary);
        }
    }
    

    If you are using Lucene for a lot of functionality, considering using Apache Solr, a search platform built on top of Lucene.

    You could also model your index with just one entry per anagram group.

    {"anagram" : "scare", "words":["cares", "acres"]}
    {"anagram" : "shoes", "words":["hoses"]}
    {"anagram" : "spore", "words":["pores", "prose", "ropes"]}
    

    This would require updates to existing documents in the index while processing your dictionary file. Solr would help with higher level API in such cases. For e.g., IndexWriter does not support updating documents. Solr supports updates.

    Such an index would give one result document per anagram search.

    Hope it helps.

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

Sidebar

Related Questions

Hello only have a few hours with Java. (from Python) I am trying to
Hello I have a bunch of text on my file which i display. I
Hello i have this foreach loop that gives weird result , it displays only
Hello I have an android application which has a service running. After 20 mins
Hello I have a page in an ASP.NET (website) project that writes a file
Hello I have this in my code File file = new File(words.txt); Scanner scanFile
Hello I have a ScrollBar Template as per below - only relevant portion shown:
Hello have following strange issue, can vertical center the menu text if it's one
Hello I have a jQuery to open picture only in browser visible area: $(document).ready(function()
Hello i have the follow problem. I have e XML file and i know

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.