Results 1 to 7 of 7

Thread: Derived Query with Like or without doesn't search via partial words.

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default Derived Query with Like or without doesn't search via partial words.

    So, I have two derived queries in my repo

    Page<Item> findByDescriptionLike(String description, Pageable page);
    Page<Item> findByDescription(String description, Pageable page);

    No matter which of these two that I use. If I pass "co" as the description I get no results. If I pass "coke" as the description I get 4 results back.

    "Coke 6-pack"
    "Coke 12-pack"
    "Diet Coke"
    "Coke Single"

    I might expect findByDescription to return 0 results with "co" as description, but then "coke" would also return 0 results.

    But I definitely expect findByDescriptionLike should return 4 results for "co" and for "coke"

    Basically, I am doing an autocomplete textfield in my UI where is sends a request to the server side REST service that returns a List of Item names.

    Also, I have tried doing what I did when I had a description with two words and a space where I / a quote in the description at the beginning and end. I even tried adding "*" to the front and back of the String but that didn't work.

    Thanks

    Mark

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    It would help if you mentioned which store you're talking about. Like is usually dependent on the store representation of the Like (e.g. using % in JPA). You might wanna try Contains/Containing as it automatically translates the given String (e.g. "foo") into the appropriate expression (e.g. "%foo%" for JPA).

  3. #3
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Thanks for the reply. As this is posted in the Data/NoSql forum, it isn't JPA.

    I am using SDN Neo4j.

    I'll try renaming the method to have the word contains.

    Mark

  4. #4
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    I just tried with Contains and Containing in the name of the derived query and I get an exception. Basically it looks like it is running some query, but it says the results are not of the same type as my domain object.

    Code:
    public interface ItemRepository extends GraphRepository<Item> {
    
        Page<Item> findByDescriptionLike(String description, Pageable page);
        Page<Item> findByDescriptionContaining(String description, Pageable page);
        Page<Item> findByDescription(String description, Pageable page);
        Page<Item> findByBarcode(String barcode, Pageable page);
    
        //ITEM_NEEDED_FOR_EVENT
        @Query("start event=node({0}) " +
                   "match event-[itemNeeded:" + Event.ITEMS_NEEDED_FOR_EVENT + "]->item " +
                   "return itemNeeded " +
                   "order by events.eventDate desc")
        Page<ItemNeededForEvent> findItemsNeededByEvent(Event event, Pageable page);
    
        @Query("start user=node({user}), event=node({eventId}) " +
                "match user-[host?:HOSTS]->event, " +
                "event-[:ITEMS_NEEDED]->neededItem-[:ITEM]->item, " +
                "event-[:ITEMS_SIGNED_UP_FOR]-> signedUpToBringToEvent-[userSignedUp?:USER]->user " +
                "return host!=null as isHost, ID(neededItem) as neededItemId, neededItem.quantity as quantity, item.name as itemName, " +
                "userSignedUp!=null as currentUserSignedUp, ID(signedUpToBringToEvent) as itemSignedUpId")
        Page<ItemsForEventsPage> findItemsByEvent(User user, Long eventId, Pageable page);
    
    }
    Thanks

    Mark

  5. #5
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    I don't think Spring Data Neo4j supports contains or startswith.

    Thanks

    Mark

  6. #6
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    It looks like there is already a Jira that covers this problem. Hopefully, it will be resolved soon so I can go live in a few weeks.

    Thanks

    Mark

  7. #7
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    My issue is resolved here, but still a like, contains or startsWith should do this automatically.

    But basically, I stuck with a derived query with property name in method name, no Like, Contains or StartsWith, I just pass in the String with a "*" concatenated at the end.

    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •