'Lucene to use different files to search text

I am working on a task where I need to search a text using lucene. But here the requirement is to use the already created segment, .si, .cfe and .cfs files by other application.

enter image description here

I am able to get those files but while searching the text it won't show me the results.

The code is for search is:

    public void searchText(String indexPath, String searchString) {
        try {
            Analyzer analyzer = new StandardAnalyzer(); 
            File indexDirectory = new File(indexPath);
            Directory directory = FSDirectory.open(indexDirectory.toPath());
            IndexReader directoryReader = DirectoryReader.open(directory);
            IndexSearcher searcher = new IndexSearcher(directoryReader);
            QueryParser parser = new QueryParser("requiredtext", analyzer);
            Query query = parser.parse(searchString);
            System.out.println(query);
            // Parse a simple query that searches for "text":
            ScoreDoc[] hits = searcher.search(query, 10).scoreDocs;
            // Iterate through the results:
            for (int i = 0; i < hits.length; i++) {
                Document hitDoc = searcher.doc(hits[i].doc);
            }

            analyzer.close();
            directoryReader.close();
            directory.close();
        }
        catch (Exception ex){
            System.out.println("Exception - "+ex.getMessage());
        }
    }

I am using the Lucene version 8.11.1 with Java8.

The question is: Is it possible in Lucene to read/find/search the text for which the files are written by some other application and search by other application. If it is then please provide the pointers how?

Atul



Solution 1:[1]

I found the issue and fixed it.

I was looking for the data in the field "requiredtext" but the indexer wont store the data for the field like while indexing it wont set the property for this field "TextField.Store.YES" and that is the reason I wont get the data for the field which I am looking for.

I got the data for other field for which the property was set.

And my questions was is it possible to search data on other files which are created by other application? So the answer is yes. @andrewJames answer helps to prove it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Atul