'How can i make this terrier example work?

Trying to figure out how to embody terrier Indexing and Retrieval in my app but cant even run properly the documentation demo (https://github.com/terrier-org/terrier-core/blob/5.x/doc/quickstart-integratedsearch.md)

I know there are some serious updates now but feels like mess to me. Can anyone help?

This is the most recent example you can find***

import java.io.File;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;
import org.terrier.indexing.Document;
import org.terrier.indexing.TaggedDocument;
import org.terrier.indexing.tokenisation.Tokeniser;
import org.terrier.querying.LocalManager;
import org.terrier.querying.Manager;
import org.terrier.querying.ManagerFactory;
import org.terrier.querying.ScoredDoc;
import org.terrier.querying.ScoredDocList;
import org.terrier.querying.SearchRequest;
import org.terrier.realtime.memory.MemoryIndex;
import org.terrier.utility.ApplicationSetup;
import org.terrier.utility.Files;


public class IndexingAndRetrievalExample {

    public static void main(String[] args) throws Exception {

        // Directory containing files to index
            String aDirectoryToIndex = "/my/directory/containing/files/";

        // Configure Terrier
                ApplicationSetup.setProperty("indexer.meta.forward.keys", "docno");
        ApplicationSetup.setProperty("indexer.meta.forward.keylens", "30");

        // Create a new Index
                MemoryIndex memIndex = new MemoryIndex();

        // For each file
                for (String filename : new File(aDirectoryToIndex).list() ) {

                        String fullPath = aDirectoryToIndex+filename;

            // Convert it to a Terrier Document
                        Document document = new TaggedDocument(Files.openFileReader(fullPath), new HashMap(), Tokeniser.getTokeniser());

            // Add a meaningful identifier
                        document.getAllProperties().put("docno", filename);

                        // index it
                        memIndex.indexDocument(document);
                }

                // Set up the querying process
                ApplicationSetup.setProperty("querying.processes", "terrierql:TerrierQLParser,"
                + "parsecontrols:TerrierQLToControls,"
                + "parseql:TerrierQLToMatchingQueryTerms,"
                + "matchopql:MatchingOpQLParser,"
                + "applypipeline:ApplyTermPipeline,"
                + "localmatching:LocalManager$ApplyLocalMatching,"
                + "filters:LocalManager$PostFilterProcess");

                // Enable the decorate enhancement
                ApplicationSetup.setProperty("querying.postfilters", "org.terrier.querying.SimpleDecorate");

                // Create a new manager run queries
                Manager queryingManager = ManagerFactory.from(memIndex.getIndexRef());

                // Create a search request
                SearchRequest srq = queryingManager.newSearchRequestFromQuery("search for document");

                // Specify the model to use when searching
                srq.setControl(SearchRequest.CONTROL_WMODEL, "BM25");

                // Enable querying processes
                srq.setControl("terrierql", "on");
                srq.setControl("parsecontrols", "on");
                srq.setControl("parseql", "on");
                srq.setControl("applypipeline", "on");
                srq.setControl("localmatching", "on");
                srq.setControl("filters", "on");

                // Enable post filters
                srq.setControl("decorate", "on");

                // Run the search
                queryingManager.runSearchRequest(srq);

                // Get the result set
                ScoredDocList results = srq.getResults();

                // Print the results
                System.out.println("The top "+results.size()+" of documents were returned");
                System.out.println("Document Ranking");
                for(ScoredDoc doc : results) {
                    int docid = doc.getDocid();
                    double score = doc.getScore();
                    String docno = doc.getMetadata("docno")
                    System.out.println("   Rank "+i+": "+docid+" "+docno+" "+score);
                }
    }
}

Indexing part seems to be okay. This lines of retrieval part seem problematic.

Manager queryingManager = ManagerFactory.from(memIndex.getIndexRef()); cursor message: Cannot resolve method 'getIndexRef' in 'MemoryIndex

srq.setControl(SearchRequest.CONTROL_WMODEL, "BM25"); cursor message: Cannot resolve symbol 'CONTROL_WMODEL'

ScoredDocList results = srq.getResults(); cursor message: Cannot resolve method 'getResults' in 'SearchRequest'

I think the problem is that there are new ways to do this and some methods are now deprecated.

Could anyone try this code and see if it works?

It is a Maven project. These are the dependencies :

        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-core</artifactId>
            <version>5.5</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-core</artifactId>
            <version>5.4</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-core</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-realtime</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-core</artifactId>
            <version>4.4</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-core</artifactId>
            <version>4.2</version>
        </dependency>

        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-batch-indexers</artifactId>
            <version>5.4</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-batch-retrieval</artifactId>
            <version>5.4</version>
        </dependency>
        <dependency>
            <groupId>org.terrier</groupId>
            <artifactId>terrier-index-api</artifactId>
            <version>5.5</version>
        </dependency>
    </dependencies>


Sources

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

Source: Stack Overflow

Solution Source