Full Text Search API for App Engine (Java)

后端 未结 2 1184
一向
一向 2021-01-21 06:07

I have been trying to use the experimental Search API for the Google AppEngine. I am using SDK 1.6.6. So far, I could add entries to an index and search it in my development env

相关标签:
2条回答
  • 2021-01-21 06:28

    If you think sorting is your issue then you may want to look at presorting your documents in the index using Document rank. The rank field on documents is by default set to the number of seconds since Jan 1 2011. However, you can supply a integer rank value. For example, if you wanted to sort a product catalog on price (low to high, and high to low). The rank is used to presort the documents in the index.

    public Index getIndex(String indexName) {
        IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
        return SearchServiceFactory.getSearchService().getIndex(indexSpec);
    }
    
    Document doc = Document.newBuilder()
        .addField(Field.newBuilder().setName('name').setText("some text"))
        .setRank(functionToGetPrice())
        .build();
    
    getIndex("productHighToLow").put(doc);
    
    doc = Document.newBuilder()
        .addField(Field.newBuilder().setName('name').setText("some text"))
        .setRank(MAXINT-functionToGetPrice())
        .build();
    
    getIndex("productLowToHigh").put(doc);
    

    Then when you search your index, if the user has selected "price low to high" and queried for "LED TV", then you can simply issue a query like

    getIndex("productLowToHigh").search("LED TV");
    

    and it will be faster and semantically correct even for large (product catalog) indexes.

    0 讨论(0)
  • 2021-01-21 06:30

    Did you tried removing SortOptions ? I got same error when I set SortOptions. I think this is a bug.

    0 讨论(0)
提交回复
热议问题