Example usage for org.apache.lucene.search IndexSearcher IndexSearcher

List of usage examples for org.apache.lucene.search IndexSearcher IndexSearcher

Introduction

In this page you can find the example usage for org.apache.lucene.search IndexSearcher IndexSearcher.

Prototype

public IndexSearcher(IndexReaderContext context) 

Source Link

Document

Creates a searcher searching the provided top-level IndexReaderContext .

Usage

From source file:com.javapr.plaintextindex.search.Suchen.java

License:Apache License

public void sucheString(String line) throws IOException, ParseException

{
    frame = new JFrame();
    frame.setTitle("Lucene Suche");
    frame.setSize(400, 180);/*from  w  w  w.  ja v a2  s  .  com*/
    frame.setLocation(400, 400);
    frame.setVisible(true);
    panel = new JPanel(new BorderLayout(5, 5));
    list = new JList();
    panel1 = new JPanel(new GridLayout(1, 1));
    panelLabel = new JPanel(new GridLayout(2, 1));
    pane = new JScrollPane(panel1);
    labelAnzData = new JLabel();
    alert = new JLabel();
    suche = new JLabel();
    dir = new JLabel();
    panel.add(panelLabel, BorderLayout.WEST);
    panel.add(pane, BorderLayout.CENTER);
    frame.add(panel);

    String field = "contents";
    int hitsPerPage = 10;

    try {
        IndexReader indexReader = DirectoryReader.open(FSDirectory.open(new File(Prop.Indexdirectory(null))));
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_42);
        QueryParser parser = new QueryParser(Version.LUCENE_42, field, analyzer);

        list1 = new ArrayList<Object>();

        try {
            Query query = parser.parse(line);

            suche = new JLabel("Suche nach: " + line);
            panelLabel.add(suche);

            TopDocs results = indexSearcher.search(query, 5 * hitsPerPage);
            ScoreDoc[] hits = results.scoreDocs;

            int end = hits.length;

            //Liste erzeugen und mit gefundenen Dateinamen fllen
            for (int i = 0; i < end; i++) {
                Document doc = indexSearcher.doc(hits[i].doc);
                String path = doc.get("filename");
                File file = new File(Prop.Filestoindex(null) + "\\" + doc.get("filename"));
                if (path != null) {
                    list1.add(path + ", " + file.length() / 1024 + "kb");
                }
            }

            labelAnzData = new JLabel(hits.length + " Gefundene Datei(en): ");
            panelLabel.add(labelAnzData);
            list = new JList(list1.toArray());
            panel1.add(list);

        } catch (ParseException p) {
            alert = new JLabel("String eingeben!");
            panel.add(alert);
            ;
        }
    } catch (IOException e) {
        dir.setText("<html><body>Index-Datei nicht gefunden!<br>Bitte Index erstellen!</body></html>");
        panel.add(dir);
    }
}

From source file:com.jivesoftware.forum.database.DbQuery.java

License:Open Source License

/**
 * Returns a Lucene Searcher that can be used to execute queries. Lucene
 * can handle index reading even while updates occur. However, in order
 * for index changes to be reflected in search results, the reader must
 * be re-opened whenever the modifiedDate changes.<p>
 *
 * The location of the index is the "search" subdirectory in [jiveHome]. If
 * jiveHome is not set correctly, this method will fail.
 *
 * @return a Searcher that can be used to execute queries.
 */// w w w. j  ava  2 s. co m
private static Searcher getSearcher() throws IOException {
    if (indexPath == null) {
        //Get path of where search index should be. It should be
        //the search subdirectory of [jiveHome].
        String jiveHome = JiveGlobals.getJiveHome();
        if (jiveHome == null) {
            System.err.println("ERROR: the jiveHome property is not set.");
            throw new IOException("Unable to open index for searching " + "because jiveHome was not set.");
        }
        indexPath = jiveHome + File.separator + "search";
    }

    if (searcher == null) {
        //Acquire a lock -- analyzer is a convenient object to do this on.
        synchronized (DbSearchManager.analyzer) {
            if (searcher == null) {
                if (indexExists(indexPath)) {
                    searchDirectory = FSDirectory.getDirectory(indexPath, false);
                    reader = IndexReader.open(searchDirectory);
                    indexLastModified = reader.lastModified(searchDirectory);
                    searcher = new IndexSearcher(reader);
                }
                //Otherwise, the index doesn't exist, so return null.
                else {
                    return null;
                }
            }
        }
    }
    if (reader.lastModified(searchDirectory) > indexLastModified) {
        synchronized (DbSearchManager.analyzer) {
            if (reader.lastModified(searchDirectory) > indexLastModified) {
                if (indexExists(indexPath)) {
                    indexLastModified = reader.lastModified(searchDirectory);
                    //We need to close the indexReader because it has changed.
                    //Re-opening it will make changes visible.
                    reader.close();

                    searchDirectory = FSDirectory.getDirectory(indexPath, false);
                    reader = IndexReader.open(searchDirectory);
                    searcher = new IndexSearcher(reader);
                }
                //Otherwise, the index doesn't exist, so return null.
                else {
                    return null;
                }
            }
        }
    }
    return searcher;
}

From source file:com.justinleegrant.myluceneplayground.SimpleFacetsExample.java

License:Apache License

/** User runs a query and counts facets. */
private List<FacetResult> facetsWithSearch() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    FacetsCollector fc = new FacetsCollector();

    // MatchAllDocsQuery is for "browsing" (counts facets
    // for all non-deleted docs in the index); normally
    // you'd use a "normal" query:
    FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);

    // Retrieve results
    List<FacetResult> results = new ArrayList<>();

    // Count both "Publish Date" and "Author" dimensions
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
    results.add(facets.getTopChildren(10, "Author"));
    results.add(facets.getTopChildren(10, "Publish Date"));

    indexReader.close();/*from  www . j a v a 2  s .  co m*/
    taxoReader.close();

    return results;
}

From source file:com.justinleegrant.myluceneplayground.SimpleFacetsExample.java

License:Apache License

/** User runs a query and counts facets only without collecting the matching documents.*/
private List<FacetResult> facetsOnly() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    FacetsCollector fc = new FacetsCollector();

    // MatchAllDocsQuery is for "browsing" (counts facets
    // for all non-deleted docs in the index); normally
    // you'd use a "normal" query:
    searcher.search(new MatchAllDocsQuery(), null /*Filter */, fc);

    // Retrieve results
    List<FacetResult> results = new ArrayList<>();

    // Count both "Publish Date" and "Author" dimensions
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);

    results.add(facets.getTopChildren(10, "Author"));
    results.add(facets.getTopChildren(10, "Publish Date"));

    indexReader.close();/*from ww w. j  av a 2  s. co  m*/
    taxoReader.close();

    return results;
}

From source file:com.justinleegrant.myluceneplayground.SimpleFacetsExample.java

License:Apache License

/** User drills down on 'Publish Date/2010', and we
 *  return facets for both 'Publish Date' and 'Author',
 *  using DrillSideways. *//* ww w  .j a v a2s. com*/
private List<FacetResult> drillSideways() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("Publish Date", "2010");

    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
    DrillSidewaysResult result = ds.search(q, 10);

    // Retrieve results
    List<FacetResult> facets = result.facets.getAllDims(10);

    indexReader.close();
    taxoReader.close();

    return facets;
}

From source file:com.khepry.frackhem.entities.Blendeds.java

License:Apache License

public QueryResult initialize(String indexFolderPath, String taxonomyFolderPath) {
    QueryResult queryResult = new QueryResult();

    String message = "";

    File indexFolder = new File(indexFolderPath);
    if (!indexFolder.exists()) {
        message = "Index path does not exist: " + indexFolderPath;
        queryResult.setNotValid(true);/*from w w w  .  j  a v a 2s . co  m*/
        queryResult.setMessage(message);
        if (outputToSystemErr) {
            System.err.println(message);
        }
        if (outputToMsgQueue) {
            progressMessageQueue.send(new MessageInput(message));
        }
    }

    File taxonomyFolder = new File(taxonomyFolderPath);
    if (!taxonomyFolder.exists()) {
        message = "Taxonomy path does not exist: " + taxonomyFolderPath;
        queryResult.setNotValid(true);
        queryResult.setMessage(message);
        if (outputToSystemErr) {
            System.err.println(message);
        }
        if (outputToMsgQueue) {
            progressMessageQueue.send(new MessageInput(message));
        }
    }

    if (indexFolder.exists() && taxonomyFolder.exists()) {
        try {
            indexReader = DirectoryReader.open(FSDirectory.open(indexFolder));
            indexSearcher = new IndexSearcher(indexReader);
            analyzer = new StandardAnalyzer(Version.LUCENE_44);
            taxonomyReader = new DirectoryTaxonomyReader(FSDirectory.open(taxonomyFolder));
            initialized = true;
        } catch (IOException e) {
            message = e.getMessage();
            if (outputToSystemErr) {
                System.err.println(message);
            }
            if (outputToMsgQueue) {
                progressMessageQueue.send(new MessageInput(message));
            }
        }
    }

    return queryResult;
}

From source file:com.knowgate.lucene.BugSearcher.java

License:Open Source License

/**
 * Compose a Lucene query based on given parameters
 * @param sLuceneIndexPath String Base path for Lucene indexes excluding WorkArea and table name
 * @param sWorkArea String GUID of WorkArea to be searched, cannot be null
 * @param sProject String GUID f project to which bug belongs
 * @param sReportedBy String//from  w w w  . j a  va2  s .  c  o  m
 * @param sWrittenBy String
 * @param sTitle String
 * @param sFromDate String
 * @param sToDate String
 * @param sType String
 * @param sPriority String
 * @param sSeverity String
 * @param sStatus String
 * @param sText String
 * @param sComments String
 * @param iLimit int
 * @param oSortBy Comparator
 * @return BugRecord[]
 * @throws ParseException
 * @throws IOException
 * @throws NullPointerException
 */
public static BugRecord[] search(String sLuceneIndexPath, String sWorkArea, String sProjectGUID,
        String sReportedBy, String sWrittenBy, String sTitle, Date dtFromDate, Date dtToDate, String sType,
        String sPriority, String sSeverity, String sStatus, String sText, String sComments, int iLimit,
        Comparator oSortBy) throws ParseException, IOException, NullPointerException {

    if (null == sLuceneIndexPath)
        throw new NullPointerException("BugSearcher.search() luceindex parameter cannot be null");

    if (null == sWorkArea)
        throw new NullPointerException("BugSearcher.search() workarea parameter cannot be null");

    if (DebugFile.trace) {
        DebugFile.writeln("Begin BugSearcher.search(" + sLuceneIndexPath + "," + sWorkArea + "," + sProjectGUID
                + "," + sReportedBy + "," + sWrittenBy + "," + sTitle + "," + dtFromDate + "," + dtToDate + ","
                + sType + "," + sPriority + "," + sSeverity + "," + "," + sStatus + "," + sText
                + String.valueOf(iLimit) + ")");
        DebugFile.incIdent();
    }

    BugRecord[] aRetArr;

    BooleanQuery oQry = new BooleanQuery();

    oQry.add(new TermQuery(new Term("workarea", sWorkArea)), BooleanClause.Occur.MUST);

    if (null != sProjectGUID)
        if (sProjectGUID.length() > 0)
            oQry.add(new TermQuery(new Term("container", sProjectGUID)), BooleanClause.Occur.MUST);

    if (null != sWrittenBy)
        if (sWrittenBy.length() > 0)
            oQry.add(new TermQuery(new Term("writer", sWrittenBy)), BooleanClause.Occur.MUST);

    if (null != sReportedBy)
        if (sReportedBy.length() > 0)
            oQry.add(new TermQuery(new Term("author", sReportedBy)), BooleanClause.Occur.MUST);

    if (null != sTitle)
        if (sTitle.length() > 0)
            oQry.add(new TermQuery(new Term("title", sTitle)), BooleanClause.Occur.MUST);

    if (null != sType)
        if (sType.length() > 0)
            oQry.add(new TermQuery(new Term("type", sType)), BooleanClause.Occur.MUST);

    if (null != sStatus)
        if (sStatus.length() > 0)
            oQry.add(new TermQuery(new Term("status", sStatus)), BooleanClause.Occur.MUST);

    if (null != sPriority)
        if (sPriority.length() > 0)
            oQry.add(new TermQuery(new Term("priority", sPriority)), BooleanClause.Occur.MUST);

    if (null != sSeverity)
        if (sSeverity.length() > 0)
            oQry.add(new TermQuery(new Term("severity", sSeverity)), BooleanClause.Occur.MUST);

    if (dtFromDate != null && dtToDate != null)
        oQry.add(
                new TermRangeQuery("created", DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY),
                        DateTools.dateToString(dtToDate, DateTools.Resolution.DAY), true, true),
                BooleanClause.Occur.MUST);
    else if (dtFromDate != null)
        oQry.add(new TermRangeQuery("created", DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY),
                null, true, false), BooleanClause.Occur.MUST);
    else if (dtToDate != null)
        oQry.add(new TermRangeQuery("created", null, DateTools.dateToString(dtToDate, DateTools.Resolution.DAY),
                false, true), BooleanClause.Occur.MUST);
    if (null != sText)
        if (sText.length() > 0)
            oQry.add(new TermQuery(new Term("text", sText)), BooleanClause.Occur.SHOULD);

    if (null != sComments)
        if (sComments.length() > 0)
            oQry.add(new TermQuery(new Term("comments", sComments)), BooleanClause.Occur.SHOULD);

    String sSegments = Gadgets.chomp(sLuceneIndexPath, File.separator) + "k_bugs" + File.separator + sWorkArea;
    if (DebugFile.trace)
        DebugFile.writeln("new IndexSearcher(" + sSegments + ")");
    Directory oFsDir = Indexer.openDirectory(sSegments);
    IndexSearcher oSearch = new IndexSearcher(oFsDir);

    Document oDoc;

    TopDocs oTopSet = oSearch.search(oQry, null, iLimit > 0 ? iLimit : 2147483647);
    if (oTopSet.scoreDocs != null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        int iDocCount = oTopDoc.length;
        aRetArr = new BugRecord[iDocCount];
        for (int d = 0; d < iDocCount; d++) {
            oDoc = oSearch.doc(oTopDoc[d].doc);
            aRetArr[d] = new BugRecord(oTopDoc[d].score, Integer.parseInt(oDoc.get("number")), oDoc.get("guid"),
                    oDoc.get("container"), oDoc.get("title"), oDoc.get("author"), oDoc.get("created"),
                    oDoc.get("type"), oDoc.get("status"), oDoc.get("priority"), oDoc.get("severity"),
                    oDoc.get("abstract"));
        } // next
    } else {
        aRetArr = null;
    }

    oSearch.close();
    oFsDir.close();

    if (oSortBy != null) {
        Arrays.sort(aRetArr, oSortBy);
    }

    if (DebugFile.trace) {
        DebugFile.decIdent();
        if (null == aRetArr)
            DebugFile.writeln("End BugSearcher.search() : no records found");
        else
            DebugFile.writeln("End BugSearcher.search() : " + String.valueOf(aRetArr.length));
    }
    return aRetArr;
}

From source file:com.knowgate.lucene.ContactSearcher.java

License:Open Source License

/**
 * Compose a Lucene query based on given parameters
 * @param sLuceneIndexPath String Base path for Lucene indexes excluding WorkArea and table name
 * @param sWorkArea String GUID of WorkArea to be searched, cannot be null
 * @param sProject String GUID f project to which bug belongs
 * @param sReportedBy String/*from  w w w .jav a  2  s. co m*/
 * @param sWrittenBy String
 * @param sTitle String
 * @param sFromDate String
 * @param sToDate String
 * @param sType String
 * @param sPriority String
 * @param sSeverity String
 * @param sStatus String
 * @param sText String
 * @param sComments String
 * @param iLimit int
 * @param oSortBy Comparator
 * @return BugRecord[]
 * @throws ParseException
 * @throws IOException
 * @throws NullPointerException
 */
public static ContactRecord[] search(Properties oProps, String sWorkArea, String values[],
        boolean obligatorio[]) throws ParseException, IOException, NullPointerException {

    if (null == oProps.getProperty("luceneindex"))
        throw new NullPointerException("ContactSearcher.search() luceindex parameter cannot be null");

    if (null == sWorkArea)
        throw new NullPointerException("ContactSearcher.search() workarea parameter cannot be null");

    if (DebugFile.trace) {
        DebugFile.writeln("Begin ContactSearcher.search(" + oProps.getProperty("luceneindex") + "," + sWorkArea
                + "," + String.valueOf(20) + ")");
        DebugFile.incIdent();
    }

    BooleanQuery oQry = new BooleanQuery();

    oQry.add(new TermQuery(new Term("workarea", sWorkArea)), BooleanClause.Occur.MUST);

    for (int i = 0; i < values.length; i++) {
        if (obligatorio[i]) {
            oQry.add(new TermQuery(new Term("value", values[i])), BooleanClause.Occur.MUST);
        } else {
            oQry.add(new TermQuery(new Term("value", values[i])), BooleanClause.Occur.SHOULD);
        }
    }

    String sSegments = Gadgets.chomp(oProps.getProperty("luceneindex"), File.separator) + "k_contacts"
            + File.separator + sWorkArea;
    if (DebugFile.trace)
        DebugFile.writeln("new IndexSearcher(" + sSegments + ")");

    File oDir = new File(sSegments);
    if (!oDir.exists()) {
        try {
            Indexer.rebuild(oProps, "k_contacts", sWorkArea);
        } catch (Exception e) {
            if (DebugFile.trace)
                DebugFile.writeln(e.getMessage());
        }
    }
    Directory oFsDir = Indexer.openDirectory(sSegments);
    IndexSearcher oSearch = new IndexSearcher(oFsDir);

    Document oDoc;

    ContactRecord aRetArr[] = null;

    TopDocs oTopSet = oSearch.search(oQry, null, 20);
    if (oTopSet.scoreDocs != null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        int iDocCount = oTopDoc.length;
        aRetArr = new ContactRecord[iDocCount];
        for (int d = 0; d < iDocCount; d++) {
            oDoc = oSearch.doc(oTopDoc[d].doc);
            // String[] aAbstract = Gadgets.split(oSearch.doc(oTopDoc[d].doc).get("abstract"), '');
            aRetArr[d] = new ContactRecord(oTopDoc[d].score, oDoc.get("author"), oDoc.get("workarea"),
                    oDoc.get("guid"), oDoc.get("value"));
        } // next
    } else {
        aRetArr = null;
    }

    oSearch.close();
    oFsDir.close();

    if (DebugFile.trace) {
        DebugFile.decIdent();
        if (null == aRetArr)
            DebugFile.writeln("End ContactSearcher.search() : no records found");
        else
            DebugFile.writeln("End ContactSearcher.search() : " + String.valueOf(aRetArr.length));
    }
    return aRetArr;
}

From source file:com.knowgate.lucene.NewsMessageSearcher.java

License:Open Source License

/**
 * Find out if a given NewsMessage is already indexed
 * @param sLuceneIndexPath String Base path for Lucene indexes excluding WorkArea and table name
 * @param sWorkArea String GUID of WorkArea to be searched (optional, may be null)
 * @param sNewsGroupCategoryName String GUID or Category Name of NewsGroup to which message belongs (optional, may be null)
 * @param sAuthor String/*from  w w  w .j a  v a  2s .  co m*/
 * @param sTitle String
 * @param sText String
 * @param iLimit int
 * @param oSortBy Comparator
 * @return NewsMessageRecord[] An Array of NewsMessageRecord objects or <b>null</b> if no messages where found matching the given criteria
 * @throws ParseException
 * @throws IOException
 * @throws NullPointerException
 */
public static boolean isIndexed(String sLuceneIndexPath, String sWorkArea, String sNewsGroupCategoryName,
        String sMsgId) throws ParseException, IOException, NullPointerException {

    boolean bIsIndexed = false;

    if (null == sLuceneIndexPath)
        throw new NullPointerException("NewsMessageSearcher.search() luceneindex parameter cannot be null");

    if (DebugFile.trace) {
        DebugFile.writeln("Begin NewsMessageSearcher.isIndexed(" + sLuceneIndexPath + "," + sWorkArea + ","
                + sNewsGroupCategoryName + "," + sMsgId + ")");
        DebugFile.incIdent();
    }

    BooleanQuery oQrx = new BooleanQuery();
    oQrx.add(new TermQuery(new Term("guid", sMsgId)), BooleanClause.Occur.MUST);

    if (null != sWorkArea)
        oQrx.add(new TermQuery(new Term("workarea", sWorkArea)), BooleanClause.Occur.MUST);

    if (null != sNewsGroupCategoryName)
        oQrx.add(new TermQuery(new Term("container", sNewsGroupCategoryName)), BooleanClause.Occur.MUST);

    String sSegments = Gadgets.chomp(sLuceneIndexPath, File.separator) + "k_newsmsgs" + File.separator
            + sWorkArea;
    if (DebugFile.trace)
        DebugFile.writeln("new IndexSearcher(" + sSegments + ")");
    Directory oDir = Indexer.openDirectory(sSegments);
    IndexSearcher oSearch = new IndexSearcher(oDir);

    if (DebugFile.trace)
        DebugFile.writeln("IndexSearcher.search(" + oQrx.toString() + ")");
    TopDocs oTopSet = oSearch.search(oQrx, null, 1);
    if (oTopSet.scoreDocs != null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        bIsIndexed = (oTopDoc.length > 0);
    }
    oSearch.close();
    oDir.close();

    if (DebugFile.trace) {
        DebugFile.decIdent();
        DebugFile.writeln("End NewsMessageSearcher.isIndexed() : " + String.valueOf(bIsIndexed));
    }
    return bIsIndexed;
}

From source file:com.knowgate.lucene.NewsMessageSearcher.java

License:Open Source License

/**
 * Compose a Lucene query based on given parameters
 * @param sLuceneIndexPath String Base path for Lucene indexes excluding WorkArea and table name
 * @param sWorkArea String GUID of WorkArea to be searched, cannot be null
 * @param sGroup sNewsGroupCategoryName String GUID or Category Name of NewsGroup to which message belongs (optional, may be null)
 * @param sAuthor String//from   www. j  av  a2 s .  c om
 * @param sTitle String
 * @param sText String
 * @param iLimit int
 * @param oSortBy Comparator
 * @return NewsMessageRecord[] An Array of NewsMessageRecord objects or <b>null</b> if no messages where found matching the given criteria
 * @throws ParseException
 * @throws IOException
 * @throws NullPointerException
 */
public static NewsMessageRecord[] search(String sLuceneIndexPath, String sWorkArea,
        String sNewsGroupCategoryName, String sAuthor, String sTitle, Date dtFromDate, Date dtToDate,
        String sText, int iLimit, Comparator oSortBy) throws ParseException, IOException, NullPointerException {

    if (null == sLuceneIndexPath)
        throw new NullPointerException("NewsMessageSearcher.search() luceneindex parameter cannot be null");

    if (null == sWorkArea)
        throw new NullPointerException("NewsMessageSearcher.search() workarea parameter cannot be null");

    if (DebugFile.trace) {
        DebugFile.writeln("Begin NewsMessageSearcher.search(" + sLuceneIndexPath + "," + sWorkArea + ","
                + sNewsGroupCategoryName + "," + sAuthor + "," + sTitle + "," + dtFromDate + "," + dtToDate
                + "," + sText + "," + String.valueOf(iLimit) + ")");
        DebugFile.incIdent();
    }

    NewsMessageRecord[] aRetArr;

    BooleanQuery oQrx = new BooleanQuery();

    oQrx.add(new TermQuery(new Term("workarea", sWorkArea)), BooleanClause.Occur.MUST);

    if (null != sNewsGroupCategoryName)
        oQrx.add(new TermQuery(new Term("container", sNewsGroupCategoryName)), BooleanClause.Occur.MUST);

    if (dtFromDate != null && dtToDate != null)
        oQrx.add(
                new TermRangeQuery("created", DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY),
                        DateTools.dateToString(dtToDate, DateTools.Resolution.DAY), true, true),
                BooleanClause.Occur.MUST);
    else if (dtFromDate != null)
        oQrx.add(new TermRangeQuery("created", DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY),
                null, true, false), BooleanClause.Occur.MUST);

    else if (dtToDate != null)
        oQrx.add(new TermRangeQuery("created", null, DateTools.dateToString(dtToDate, DateTools.Resolution.DAY),
                false, true), BooleanClause.Occur.MUST);

    BooleanQuery oQry = new BooleanQuery();

    if (null != sAuthor)
        oQry.add(new TermQuery(new Term("author", sAuthor)), BooleanClause.Occur.SHOULD);

    if (null != sTitle)
        oQry.add(new TermQuery(new Term("title", sTitle)), BooleanClause.Occur.SHOULD);

    if (null != sText)
        oQry.add(new TermQuery(new Term("text", escape(Gadgets.ASCIIEncode(sText).toLowerCase()))),
                BooleanClause.Occur.SHOULD);

    oQrx.add(oQry, BooleanClause.Occur.MUST);

    String sSegments = Gadgets.chomp(sLuceneIndexPath, File.separator) + "k_newsmsgs" + File.separator
            + sWorkArea;
    if (DebugFile.trace)
        DebugFile.writeln("new IndexSearcher(" + sSegments + ")");
    Directory oDir = Indexer.openDirectory(sSegments);
    IndexSearcher oSearch = new IndexSearcher(oDir);

    Document oDoc;

    if (DebugFile.trace)
        DebugFile.writeln("IndexSearcher.search(" + oQrx.toString() + ")");
    TopDocs oTopSet = oSearch.search(oQrx, null, iLimit > 0 ? iLimit : 2147483647);
    if (oTopSet.scoreDocs != null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        final int iDocCount = oTopDoc.length <= iLimit ? oTopDoc.length : iLimit;
        aRetArr = new NewsMessageRecord[iDocCount];
        for (int d = 0; d < iDocCount; d++) {
            oDoc = oSearch.doc(oTopDoc[d].doc);
            try {
                aRetArr[d] = new NewsMessageRecord(oTopDoc[d].score, oDoc.get("workarea"), oDoc.get("guid"),
                        oDoc.get("thread"), oDoc.get("container"), oDoc.get("title"), oDoc.get("author"),
                        DateTools.stringToDate(oDoc.get("created")), oDoc.get("abstract"));
            } catch (java.text.ParseException neverthrown) {
                throw new ParseException("NewsMessageSearcher.search() Error parsing date "
                        + oDoc.get("created") + " of document " + oDoc.get("guid"));
            }
        } // next
    } else {
        aRetArr = null;
    }

    oSearch.close();
    oDir.close();

    if (oSortBy != null) {
        Arrays.sort(aRetArr, oSortBy);
    }

    if (DebugFile.trace) {
        DebugFile.decIdent();
        if (null == aRetArr)
            DebugFile.writeln("End NewsMessageSearcher.search() : no records found");
        else
            DebugFile.writeln("End NewsMessageSearcher.search() : " + String.valueOf(aRetArr.length));
    }
    return aRetArr;
}