Example usage for org.apache.lucene.queryparser.classic MultiFieldQueryParser MultiFieldQueryParser

List of usage examples for org.apache.lucene.queryparser.classic MultiFieldQueryParser MultiFieldQueryParser

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.classic MultiFieldQueryParser MultiFieldQueryParser.

Prototype

public MultiFieldQueryParser(String[] fields, Analyzer analyzer) 

Source Link

Document

Creates a MultiFieldQueryParser.

Usage

From source file:Tweet_search.TweetSearcher.java

public TweetSearcher() throws IOException, Exception {
    GetProjetBaseDirAndSetProjectPropFile setPropFile = new GetProjetBaseDirAndSetProjectPropFile();
    prop = setPropFile.prop;/*from w  w w  .j a  va2  s. co m*/
    propFileName = setPropFile.propFileName;

    tweet_starts_from_date = Integer.parseInt(prop.getProperty("tweet.starts.from.date", "20"));
    tweet_ends_from_date = Integer.parseInt(prop.getProperty("tweet.ends.from.date", "29"));

    /* max number of files to return for each query */
    num_ret = Integer.parseInt(setPropFile.prop.getProperty("retrieve.num_wanted"));
    /* Set Retrieval model set */
    setSimilarityFlag = setPropFile.prop.getProperty("retrieval.model");

    String indexDirectoryPath = prop.getProperty("indexPath");
    if (!indexDirectoryPath.endsWith("/"))
        indexDirectoryPath = indexDirectoryPath.concat("/");

    reader = new IndexReader[tweet_ends_from_date - tweet_starts_from_date + 1];
    searcher = new IndexSearcher[tweet_ends_from_date - tweet_starts_from_date + 1];
    for (int i = 0; i < tweet_ends_from_date - tweet_starts_from_date + 1; i++) {
        reader[i] = DirectoryReader.open(FSDirectory
                .open(new File(indexDirectoryPath.concat(Integer.toString(i + tweet_starts_from_date)))));
        searcher[i] = new IndexSearcher(reader[i]);

        /* setting the similarity function */
        /* 1-BM25, 2-LM-JM, 3-LM-D, 4-DefaultLuceneSimilarity */
        setSimilarityFn_ResFileName(i);
        /* */
    }

    /* setting the fields in which the searching will be perfomed */
    String[] fields = setQueryFieldsToSearch();

    //        String []fields = new String[]{"abstract", "title", "contexts"};
    /* === */

    /* using the same analyzer which is used for indexing */
    Analyzer engAnalyzer = getAnalyzer();
    mFQueryParser = new MultiFieldQueryParser(fields, engAnalyzer);

    //        num_wanted = Integer.parseInt(prop.getProperty("retrieve.num_wanted","100"));
    num_wanted = num_ret;

    /* setting query list*/
    queries = constructQuery();

    /* queries has all the RAW data read from the query file like: 
    query_num, paper_title, paper_abtract, context etc.
    */
    String qfield = "qfield-";
    for (int i = 0; i < fields.length; i++) {
        if (i == 0)
            qfield = qfield.concat(fields[i]);
        else
            qfield = qfield.concat("-").concat(fields[i]);
    }
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
    //get current date time with Date()
    Date date = new Date();

    resultsFile = dateFormat.format(date).concat("-" + resultsFile).concat("-").concat(qfield).concat("-topres")
            .concat(new Integer(num_wanted).toString()).concat(".res");

    String path = prop.getProperty("resPath");
    if (!path.endsWith("/"))
        path = path.concat("/");
    resultsFile = path.concat(resultsFile);
    System.out.println("Result will be saved in: " + resultsFile);

}