eXist-db ft:query returning zero result while running eXide or oxygen

412 Views Asked by At

I am running ft:query on a collection which is stored in eXist-db but it's returning zero results. If I use fn:contains function it works perfect but ft:query returns zero results. Below is my XML structure, index configuration file, and query:

test.xml

<article xmlns="http://www.rsc.org/schema/rscart38"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    type="ART" 
    xsi:schemaLocation="http://www.rsc.org/schema/rscart38 http://www.rsc.org/schema/rscart38/rscart38.xsd" dtd="RSCART3.8">
    <metainfo last-modified="2012-11-23T19:16:50.023Z">
        <subsyear>1997</subsyear>
        <collectiontype>rscart</collectiontype>
        <collectionname>journals</collectionname>
        <docid>A605867A</docid>
        <doctitle>NMR studies on hydrophobic interactions in solution Part
            2.—Temperature and urea effect on
            the self-association of ethanol in water</doctitle>
        <summary/>
</article>

collection.xconf

<collection xmlns="http://exist-db.org/collection-config/1.0">
    <index rsc="http://www.rsc.org/schema/rscart38"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        type="ART"
        xsi:schemaLocation="http://www.rsc.org/schema/rscart38 http://www.rsc.org/schema/rscart38/rscart38.xsd" 
        dtd="RSCART3.8">
        <fulltext default="all" attributes="false"/>
        <lucene>
            <analyzer id="nosw" class="org.apache.lucene.analysis.standard.StandardAnalyzer">
                <param name="stopwords" type="org.apache.lucene.analysis.util.CharArraySet"/>
            </analyzer>
            <text qname="//rsc:article" analyzer="nosw"/>
        </lucene>
        <create path="//rsc:doctitle" type="xs:string"/>
        <create path="//rsc:journal-full-title" type="xs:string"/>
        <create path="//rsc:journal-full-title" type="xs:string"/>
    </index>
</collection>

test.xq

declare namespace rsc="http://www.rsc.org/schema/rscart38";
let $coll := collection('/db/apps/test/RSC')
let $hits := $coll//rsc:doctitle[ft:query(., 'studies')] 
return 
    $hits
2

There are 2 best solutions below

12
On BEST ANSWER

Let's start from your query. The key part of your query is:

$coll//rsc:doctitle[ft:query(., 'studies')] 

This performs a full text query for the string studies on rsc:doctitle elements in the collection. For this ft:query() function to work, there must be an index configuration for the named elements. This brings us to your index configuration.

In your index configuration, you have a full text (Lucene) index:

<text qname="//rsc:article" analyzer="nosw"/>

A couple of issues:

  1. The @qname attribute should be a QName - simply, an element or attribute name. You've expressed this as a path. Remove the path //, leaving just rsc:article.

  2. Your code does a full text query on rsc:doctitle, not on rsc:article, so I would expect your code, as written, to return 0 results. Change the existing index to rsc:doctitle, or add a new index on rsc:doctitle so that you could query either one. Reindex the collection afterwards, and as Adam suggested, check the Monex app's Indexing pane to ensure that the database has applied your index configuration as expected.

Lastly, contains() does not require an index to be in place. It benefits from the presence of a range index (i.e., your <create> elements), but range indexes are quite different from full text indexes. To learn more about these, I'd suggest reading the eXist documentation on indexing, http://exist-db.org/exist/apps/doc/indexing.xml.

3
On

I am not certain if configuring a Standard Analyzer without stopwords in the way you have done is correct. Can you check with Monex that your index has your terms in it?

Note also, if you created the index config after loading the index, then you need to reindex the collection. When you reindex it is also worth monitoring $EXIST_HOME/webapp/WEB-INF/exist.log to ensure that the indexing is done as expected.