lucy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kasi Lakshman Karthi Anbumony <kasi.anbum...@gmail.com>
Subject Re: [lucy-user] ProxmityQuery in C
Date Thu, 16 Feb 2017 00:13:38 GMT
Hi Peter:

Thanks for your quick response. I am a beginner with Lucy framework and
getting to know the different classes and objects.

I have copy-pasted my source code, with the code marked in red is the block
I am working.

(1) Is this what you meant by analyze "terms"?

(2) Can I do something similar to what has been done for TermQuery in the
code block marked in blue below?

    String        *folder   = Str_newf("%s", path_to_index);
    printf("Index file used: %s\n", path_to_index);
    IndexSearcher *searcher = IxSearcher_new((Obj*)folder);
    Schema        *schema   = IxSearcher_Get_Schema(searcher);
    QueryParser   *qparser  = QParser_new(schema, NULL, NULL, NULL);
    //ProximityQuery *pquery  = ProximityQuery_new(NULL, "animal quarter",
20);

    String *query_str = Str_newf("%s", query_c);
    Query  *query     = QParser_Parse(qparser, query_str);
    //Query  *query       = QParser_Parse(pquery, query_str);

    String *content_str = Str_newf("content");
#ifdef ENABLE_HIGHLIGHTER
    Highlighter *highlighter
        = Highlighter_new((Searcher*)searcher, (Obj*)query, content_str,
200);
#endif

    if (category) {
        String *category_name = Str_newf("category");
        String *category_str  = Str_newf("%s", category);
        TermQuery *category_query
            = TermQuery_new(category_name, (Obj*)category_str);

        Vector *children = Vec_new(2);
        Vec_Push(children, (Obj*)query);
        Vec_Push(children, (Obj*)category_query);
        query = (Query*)ANDQuery_new(children);

        DECREF(children);
        DECREF(category_str);
        DECREF(category_name);
    }

    if( queryType[g_testProximity] )
    {
        Vector *terms = Vec_new(0);
        Vec_Push(terms, (Obj*)query_str);

String *field_name = Str_newf("content");
        ProximityQuery *pquery = ProximityQuery_new(field_name, terms, 100);

        Analyzer *analyzer = Schema_Fetch_Analyzer(schema, field_name);
        if (!analyzer)
        {
           Vec_Push(query, pquery);
        }

        DECREF(terms);
DECREF(field_name);
    }


    Hits *hits = IxSearcher_Hits(searcher, (Obj*)query, 0, 10, NULL);


Thanks
-Kasi


On Wed, Feb 15, 2017 at 5:55 PM, Peter Karman <peter@peknet.com> wrote:

> Kasi Lakshman Karthi Anbumony wrote on 2/15/17 4:22 PM:
>
>
>> I stumbled upon this perl thread:
>> http://lucene.472066.n3.nabble.com/lucy-user-Unable-to-
>> retrieve-records-using-Proximity-query-td3990375.html
>>
>> The above perl thread says that there is no analyzer for ProximityQuery.
>> Can I know what is the equivalent translation I need to apply for my C
>> code
>> so as to enable ProximtyQuery and get it working?
>>
>>
>
> You need to analyze "terms" before you pass it to ProximityQuery_new
>
> The relevant section of the QueryParser code is here and might point you
> in the right direction:
>
> https://github.com/apache/lucy/blob/master/core/Lucy/Search/
> QueryParser.c#L862
>
>
>
>
> --
> Peter Karman  .  https://peknet.com/  .  https://keybase.io/peterkarman
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message