Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene indexing - lots of docs/phrases
    primarykey
    data
    text
    <p>What approach should I use in indexing following set of files.</p> <p>Each file contains around 500k lines of characters (400MB) - characters are not words, they are, lets say for sake of question random characters, without spaces.</p> <p>I need to be able to find each line which contains given 12-character string, for example:</p> <p>line: AXXXXXXXXXXXXJJJJKJIDJUD....ect up to 200 chars</p> <p>interesting part: <strong>XXXXXXXXXXXX</strong></p> <p>While searching, I'm only interested in characters 1-13 (so <strong>XXXXXXXXXXXX</strong>). After the search I would like to be able to read line containing <strong>XXXXXXXXXXXX</strong> without looping through the file. </p> <p>I wrote following poc (simplified for question:</p> <p>Indexing:</p> <pre><code> while ( (line = br.readLine()) != null ) { doc = new Document(); Field fileNameField = new StringField(FILE_NAME, file.getName(), Field.Store.YES); doc.add(fileNameField); Field characterOffset = new IntField(CHARACTER_OFFSET, charsRead, Field.Store.YES); doc.add(characterOffset); String id = ""; try { id = line.substring(1, 13); doc.add(new TextField(CONTENTS, id, Field.Store.YES)); writer.addDocument(doc); } catch ( IndexOutOfBoundsException ior ) { //cut off for sake of question } finally { //simplified snipped for sake of question. characterOffset is amount of chars to skip which reading a file (ultimately bytes read) charsRead += line.length() + 2; } } </code></pre> <p>Searching:</p> <pre><code>RegexpQuery q = new RegexpQuery(new Term(CONTENTS, id), RegExp.NONE); //cause id can be a regexp concernign 12char string TopDocs results = searcher.search(q, Integer.MAX_VALUE); ScoreDoc[] hits = results.scoreDocs; int numTotalHits = results.totalHits; Map&lt;String, Set&lt;Integer&gt;&gt; fileToOffsets = new HashMap&lt;String, Set&lt;Integer&gt;&gt;(); for ( int i = 0; i &lt; numTotalHits; i++ ) { Document doc = searcher.doc(hits[i].doc); String fileName = doc.get(FILE_NAME); if ( fileName != null ) { String foundIds = doc.get(CONTENTS); Set&lt;Integer&gt; offsets = fileToOffsets.get(fileName); if ( offsets == null ) { offsets = new HashSet&lt;Integer&gt;(); fileToOffsets.put(fileName, offsets); } String offset = doc.get(CHARACTER_OFFSET); offsets.add(Integer.parseInt(offset)); } } </code></pre> <p>The problem with this approach is that, it will create one doc per line. </p> <p>Can you please give me hints how to approach this problem with lucene and if lucene is a way to go here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload