1

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
Joe Wicentowski
  • 5,159
  • 16
  • 26

2 Answers2

1

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.

adamretter
  • 3,885
  • 2
  • 23
  • 43
  • As I understand from a post by Jens Østergaard Petersen on exist-open from April 2016 (http://markmail.org/message/jynggwbhrprek4m6), including an empty stopwords element prevents Lucene from applying its default set of stopwords (see the whole list of these at http://stackoverflow.com/questions/17527741/what-is-the-default-list-of-stopwords-used-in-lucenes-stopfilter). – Joe Wicentowski Jan 10 '17 at 14:37
  • Thanx for your reply Adam, whenever i change the conf file i reindex the collection but still i am getting the zero result, and where can i find the Monex – Dharmendra Kumar Singh Jan 11 '17 at 06:56
  • Monex is installable from the Package Manager in the Dashboard of eXist-db 3.0-RC1 and up – adamretter Jan 21 '17 at 00:12
1

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.

Joe Wicentowski
  • 5,159
  • 16
  • 26
  • Also, you haven't properly declared the `rsc` namespace: `` should be ``. The remaining attributes should be deleted; you should probably add `xmlns:xs="http://www.w3.org/2001/XMLSchema"` though. – Joe Wicentowski Jan 10 '17 at 14:41
  • whatever you have suggested i have done but i am not getting the result and whenever i change the conf file i reindex the collecton but still i am getting the zero result below is the code: – Dharmendra Kumar Singh Jan 11 '17 at 07:10
  • xquery: 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 – Dharmendra Kumar Singh Jan 11 '17 at 07:20
  • also i tried to search by removing '//' in the conf file but still it is not working , and where can i find the Monex – Dharmendra Kumar Singh Jan 11 '17 at 07:23
  • Did you reindex after making your change to collection.xconf? `xmldb:reindex('/db/apps/test/RSC')` then rerun your query, check monex indexes pane, etc. – Joe Wicentowski Jan 11 '17 at 11:44
  • As to finding monex, the answer depends on your version of eXist, so I asked that question above. And, for troubleshooting, what is the full path to your collection.xconf file? – Joe Wicentowski Jan 11 '17 at 11:50
  • My collection.xconf file path is "db/apps/test/collection.xconf" and xquery path is "db/apps/test/modules/search.xql" and i am running it int0 eXide xquery environment and oxygen editor both i have connected the oxygen with eXistDB – Dharmendra Kumar Singh Jan 13 '17 at 08:57
  • When you save the xconf file is eXide offering to copy it to the required location for xconf files - inside `/db/system/config/` - and reindex the collection? Again, though, please answer: which version of eXist? – Joe Wicentowski Jan 13 '17 at 13:04
  • when i save the conf file it just save into db/apps/test/collection.xconf" location it doesn't ask for the copy, and i am using the version 2.2.jar – Dharmendra Kumar Singh Jan 16 '17 at 12:30
  • Ok, then save this file into `/db/system/config/db/apps/test/collection.xconf`, and run `xmldb:reindex('/db/apps/test')`. Then your query should work. For monex, go to Dashboard > Package Manager, and look for "Monitoring and Profiling for eXist". Install, then visit `http://localhost:8080/exist/apps/monex`; then go to Indexes pane. – Joe Wicentowski Jan 16 '17 at 20:51
  • Great to hear! Best of luck! – Joe Wicentowski Jan 17 '17 at 12:22