Package it.unimi.dsi.mg4j.query

Examples of it.unimi.dsi.mg4j.query.QueryEngine


   
    /* To run a query in a simple way we need a query engine. The engine requires a parser
     * (which in turn requires the set of index names and a default index), a document iterator
     * builder, which needs the index map, a default index, and a limit on prefix query
     * expansion, and finally the index map. */
    QueryEngine engine = new QueryEngine(
      new SimpleParser( indexMap.keySet(), "text", termProcessors ),
      new DocumentIteratorBuilderVisitor( indexMap, text, 1000 ),
      indexMap
     
    );

    /* Optionally, we can score the results. Here we use a state-of-art ranking
     * function, BM25, which requires document sizes. */
    engine.score( new BM25Scorer() );
   
    /* Optionally, we can weight the importance of each index. To do so, we have to pass a map,
     * and again we use the handy fastutil constructor. Note that setting up a BM25F scorer
     * would give much better results, but we want to keep it simple. */
    engine.setWeights( new Reference2DoubleOpenHashMap<Index>( new Index[] { text, title }, new double[] { 1, 2 } ) );
   
    /* Optionally, we can use an interval selector to get intervals representing matches. */
    engine.intervalSelector = new IntervalSelector();
   
    /* We are ready to run our query. We just need a list to store its results. The list is made
     * of DocumentScoreInfo objects, which comprise a document id, a score, and possibly an
     * info field that is generic. Here the info field is a map from indices to arrays
     * of selected intervals. This part will be empty if we do not set an interval selector. */
    ObjectArrayList<DocumentScoreInfo<Reference2ObjectMap<Index, SelectedInterval[]>>> result =
      new ObjectArrayList<DocumentScoreInfo<Reference2ObjectMap<Index,SelectedInterval[]>>>();

    /* The query engine can return any subsegment of the results of a query. Here we grab the first 20 results. */
    engine.process( arg[ 1 ], 0, 20, result );
   
    for( DocumentScoreInfo<Reference2ObjectMap<Index, SelectedInterval[]>> dsi : result ) {
      System.out.println( dsi.document + " " + dsi.score );
    }
  }
View Full Code Here

TOP

Related Classes of it.unimi.dsi.mg4j.query.QueryEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.